最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

openapi - Setting SpringdocSwaggerUI servers using YAML file - Stack Overflow

programmeradmin4浏览0评论

I want to configure the Servers dropdown in SwaggerUI to use the server urls specified in the yaml config. To start with I'm using this yaml configuration:

springdoc:
  show-actuator: false
  packagesToScan: .example.project
  show-login-endpoint: false
  swagger-ui:
    path : /actuator/swagger-ui
  api-docs:
    path: /actuator/api-docs 

@OpenAPIDefinition in the main application class only has info configured:

@OpenAPIDefinition(info = @Info(title = "ServiceAPI", version = "1.0", description = "Documentation API v1.0"))

This results in the the default generated server url: generated server url

I know I can hardcode the servers in @OpenAPIDefinition (and that works), but this isn't useful for me. I need to be able to take the servers from the yaml config.

If I understood the documentation correctly I should by able to just add them like this:

springdoc:
  show-actuator: false
  packagesToScan: .example.project
  show-login-endpoint: false
  swagger-ui:
    path : /actuator/swagger-ui
  api-docs:
    path: /actuator/api-docs 
  servers:
    - url: 
      description: Production Server
    - url: 
      description: Staging Server

I also tried:

springdoc:
  show-actuator: false
  packagesToScan: .example.project
  show-login-endpoint: false
  open-api:
    servers:
      - url: 
        description: Production Server
      - url: 
        description: Staging Server
  swagger-ui:
    path : /actuator/swagger-ui
  api-docs:
    path: /actuator/api-docs

With both of these the servers setting is completely ignored and I get the single default generated server url anyway. How do I get Swagger to use the servers provided in the yaml?

I'm using springdoc-openapi 2.6.0.

发布评论

评论列表(0)

  1. 暂无评论