question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enhance swagger-ui access

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
bnasslahsencommented, Dec 14, 2021

@waschmittel,

You are using the wrong url to request the swagger-ui. Since v1.6.0, query params are disabled by default. You can read the CHANGELOG for more details. If you want the legacy mode, you can still enable it using springdoc.swagger-ui.queryConfigEnabled=true

Use the default url as described in the documentation: http://serverName:applicationPort/swagger-ui.html or instead of swagger-ui.html the value of springdoc.swagger-ui.path

1reaction
not3baddadcommented, Feb 9, 2022

@abrudin @bnasslahsen Just wanted to thank you both for this enhancement. I’m pretty new to Java and was facing the same scenario and had no idea what was causing it or how it might have been resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger UI tutorial | Documenting APIs - Idratherbewriting.com
Swagger UI provides a display framework that reads an OpenAPI specification document and generates an interactive documentation website.
Read more >
Configuring and Using Swagger UI in ASP.NET Core Web API
We are going to learn how to integrate the Swagger UI/OpenAPI in an ASP.NET Core Web API, extend the documentation, and customize UI....
Read more >
Chapter 5. Upgrade Swagger UI 2.1.3 TO 2.2.10
Chapter 5. Upgrade Swagger UI 2.1.3 TO 2.2.10 · Log in to your 3scale AMP admin portal · Navigate to the Developer Portal...
Read more >
OAuth 2.0 configuration - Swagger Documentation
Proof Key for Code Exchange brings enhanced security for OAuth public clients. The default is false ... const ui = SwaggerUI({.
Read more >
Enable Swagger UI for management REST API access
Direct access to management APIs through Swagger UI is considered a security risk. Explicit authorization is required. Limit access to the administrator roles ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found