Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting ‘swagger-ui.path’ and ‘swagger-ui.config-url ‘will cause browser to display an incorrect page (Swagger Petstore) #1417

Closed
zxuanhong opened this issue Jan 2, 2022 · 2 comments
Labels
invalid This doesn't seem right

Comments

@zxuanhong
Copy link

zxuanhong commented Jan 2, 2022

Describe the bug

  1. Setting ‘swagger-ui.path’ and ‘swagger-ui.config-url‘ will cause browser to display an incorrect page (swagger Petstore)
  2. Configuring only one of them will not cause exceptions

To Reproduce
Steps to reproduce the behavior:

  1. https://github.com/springdoc/springdoc-openapi-demos/tree/master/springdoc-openapi-book-service project setting ‘swagger-ui.path’ and ‘swagger-ui.config-url‘
  2. application.yml
springdoc:
  version: '@springdoc.version@'
  swagger-ui:
    use-root-path: false
    path: /api/gateway/swagger-ui.html
    config-url: /v3/api-docs/swagger-config
    enabled: true
  1. Access doc via address http://localhost:8080/api/gateway/swagger-ui.html
  2. Error page displayed
    image
  3. Eventually eliminate the drop-down will open the page request https://petstore.swagger.io/v2/swagger.json directly, not request /v3/api-docs/swagger-config
  4. I never defined the https://petstore.swagger.io/v2/swagger.json address

Help
I want to customize the UI address, as well as the config-URL address, can give a valid configuration

@zxuanhong zxuanhong changed the title Setting ‘swagger-ui.path’ and ‘swagger-ui.config-url ‘will cause browser to display an incorrect page (swagger Petstore) Setting ‘swagger-ui.path’ and ‘swagger-ui.config-url ‘will cause browser to display an incorrect page (Swagger Petstore) Jan 2, 2022
@bnasslahsen
Copy link
Contributor

bnasslahsen commented Jan 2, 2022

@Zxiaozhou,

  1. First: springdoc.swagger-ui.enabled=true is useless. (It's by default true as explained in the documentation)
    Same for remark applies to springdoc.use-root-pathproperty.

  2. Then see Setting springdoc.api-docs.path prevents auto loading of api #1279, configUrl does not include the api gateway route #1144, expose external REST API. Failed to load remote configuration #686 for how people managed to use configUrl.

  3. You will understand when you decide to set springdoc.swagger-ui.configUrl manually, then you have to provide the configuration resources in the right path: This is missing from the sample you provided

So make sure your swagger-config.json is located to in static folder - standard spring configuration src/main/resrouces/static - or valid location remote location with CORS enabled.

springdoc.swagger-ui.configUrl=/myapi/swagger-config.json

@bnasslahsen bnasslahsen added the invalid This doesn't seem right label Jan 9, 2022
@jarek-jpa
Copy link

it might be important to clearly mention that the content of the swagger-config.json is not the same as the content served from the api-docs endpoint (so setting ?configUrl=/v3/api-docs does not work)
to set the default api-docs url for swagger-ui (as set in the "Explore" input-box) one must create a swagger-config.json in the correct location with content like:

{
  "url": "/v3/api-docs"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants