首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在<redoc>中添加选项?

如何在<redoc>中添加选项?
EN

Stack Overflow用户
提问于 2018-10-11 15:31:00
回答 3查看 7.3K关注 0票数 3

我想在我的ReDoc中添加一些额外的选项。对于当前的实现,我使用从Swagger生成的json文件,并将其添加到html页面中。例如,如何做到这一点:

代码语言:javascript
复制
  <body>
    <redoc spec-url='http://petstore.swagger.io/v2/swagger.json'></redoc>
    <script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
  </body>

我使用它作为参考文档:https://github.com/Rebilly/ReDoc

如何在标记中添加选项对象而不使用ReDoc对象?我如何使用供应商扩展,例如x-徽标?在文档中,这是通过json文件设置的,但我的json文件是从Swagger自动生成的。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-10-19 10:17:15

您只需将选项放在spec-url之后的redoc标记中,如下所示:

代码语言:javascript
复制
<body>
    <redoc spec-url='http://petstore.swagger.io/v2/swagger.json' YOUR_OPTIONS_HERE></redoc>
    <script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
</body>

在ReDoc存储库上的这个示例中,您可以验证它(此时第22行):

https://github.com/Rebilly/ReDoc/blob/master/config/docker/index.tpl.html#L22

重要信息:

请记住,如果您的选项是:

hideDownloadButton noAutoAuth disableSearch

YOUR_OPTIONS_HERE

应该是(在烤肉串之后):

hide-download-button no-auto-auth disable-search

拥有这些选择的你的身体会变成这样:

代码语言:javascript
复制
<body>
    <redoc spec-url='http://petstore.swagger.io/v2/swagger.json' hide-download-button no-auto-auth disable-search></redoc>
    <script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
</body>

希望它对你有用。

票数 7
EN

Stack Overflow用户

发布于 2018-10-12 07:54:54

ReDoc通过Redoc.init进行了高级初始化,因此您可以手动下载规范并添加一些后处理(例如添加一个x-logo)。

您可以将ReDoc选项作为第二个参数传递给Redoc.init

代码语言:javascript
复制
<body>
  <div id="redoc"></div>
  <script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
  <script>
    fetch('http://petstore.swagger.io/v2/swagger.json')
      .then(res => res.json())
      .then(spec => {
        spec.info['x-logo'] = { url: "link/to/image.png" };
        Redoc.init(spec, {
        // options go here (e.g. pathInMiddlePanel)
        }, document.getElementById('redoc'));
      });
</body>

注意:--这要求取API在浏览器中可用,因此在IE11中不能工作。

票数 1
EN

Stack Overflow用户

发布于 2020-02-06 10:08:44

您可以将您的选项放在spec-url旁边。确保您正在使用的Redoc版本,有您想要使用的选项,您可以通过转到特定的版本来检查它。github.com/Redocly/redoc/tree/vx.x.x。顺便提一句,延迟呈现功能可以在v1.22.3之前使用。

https://github.com/Redocly/redoc#redoc-options-object

You can use all of the following options with standalone version on tag by kebab-casing them, e.g. scrollYOffset becomes scroll-y-offset and expandResponses becomes expand-responses.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52763862

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档