【问题标题】:Change Swagger UI `server` dynamically at run time based on the url it is running on根据运行的 url 在运行时动态更改 Swagger UI `server`
【发布时间】:2022-10-26 00:21:35
【问题描述】:

我正在使用swagger 接口来测试我的 API 端点。我有这个在两个不同的服务器上运行

  1. 生产服务器https://example.co.app
  2. 暂存服务器https://example-staging.co.app

    我设法在options 文件中的options 中创建了一个下拉列表来选择您要使用的服务器:

    servers: [
    {
          url: 'https://example.co.app',
          description: 'prod server'
        },
        {
          url: 'https://example-staging.co.app',
          description: 'staging server'
        }
    ]
    

    这可行,但默认情况下将始终使用prod server,因为它是列表中的第一个。

    我想根据它实际运行的服务器在运行时使默认动态。

    这可能与大摇大摆的配置吗?

【问题讨论】:

  • 相对 URL 是否适用于您的场景 - url: '/'?还是您仍然需要手动选择服务器的能力(例如,在 Staging 上打开 Swagger UI,然后选择 Prod 服务器)?
  • @Helen 不,不需要手动选择。 / 会自动分配访问的 URL 吗?

标签: node.js swagger swagger-ui openapi


【解决方案1】:

Estimado colega, me encantaría poder ayudarte pero aun estoy empezando a usar swagger, quisiera saber como hiciste para poder montar swagger en un server, es decir tengo varias apis, como crear una vista cliente donde el usuario pueda probar su api, de momento solo me销售 con una sol api。 agradezco tu ayuda.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-04
    • 2022-08-02
    • 2018-03-04
    • 1970-01-01
    • 2023-03-20
    • 2011-01-26
    • 1970-01-01
    • 2020-03-05
    相关资源
    最近更新 更多