Skip to content

Enhance swagger-ui access #1384

Closed
Closed
@waschmittel

Description

@waschmittel

Describe the bug

  • Swagger UI cannot load the API description after start. It only works after explicitly requesting ${apiDocs.path}/swagger-config

To Reproduce
Steps to reproduce the behavior:

  1. Configure springdoc as follows
  apiDocs:
    path: /api-docs/v3
    groups:
      enabled: true
  group-configs:
    - group: basic
      paths-to-match: /v2/**,
    ...
  1. Start the Spring Boot application

  2. Open swagger-ui/index.html?configUrl=/api-docs/v3/swagger-config

Swagger UI cannot find the API definition. The source of index.html contains:

...
<script>
    window.onload = function() {
      // Begin Swagger UI call region
      const ui = SwaggerUIBundle({
        url: "",
        dom_id: '#swagger-ui',
        deepLinking: true,
        presets: [
          SwaggerUIBundle.presets.apis,
          SwaggerUIStandalonePreset
        ],
        plugins: [
          SwaggerUIBundle.plugins.DownloadUrl
        ],
        layout: "StandaloneLayout"
      });
      // End Swagger UI call region

      window.ui = ui;
    };
  </script>
  1. Open /api-docs/v3/swagger-config

  2. Open swagger-ui/index.html?configUrl=/api-docs/v3/swagger-config again

Swagger UI can now find the API definition. The source of index.html contains:

    <script>
    window.onload = function() {
      // Begin Swagger UI call region
      const ui = SwaggerUIBundle({
        url: "",
        dom_id: '#swagger-ui',
        deepLinking: true,
        presets: [
          SwaggerUIBundle.presets.apis,
          SwaggerUIStandalonePreset
        ],
        plugins: [
          SwaggerUIBundle.plugins.DownloadUrl
        ],
        layout: "StandaloneLayout" ,

  "oauth2RedirectUrl" : "http://localhost:8080/swagger-ui/oauth2-redirect.html",
  "urls" : [ {
    "url" : "<redacted>",
    "name" : "<redacted>"
  } ]

      });
      // End Swagger UI call region

      window.ui = ui;
    };
  </script>
  • What version of spring-boot you are using? --> 2.6.1
  • What modules and versions of springdoc-openapi are you using? --> 1.6.0
  • What is the actual and the expected result using OpenAPI Description (yml or json)? --> Swagger UI should always work
  • Provide with a sample code (HelloController) or Test that reproduces the problem --> not related to a particular controller

Expected behavior

Swagger UI should always work

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions