Enhance swagger-ui access
See original GitHub issueDescribe 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:
- Configure springdoc as follows
apiDocs:
path: /api-docs/v3
groups:
enabled: true
group-configs:
- group: basic
paths-to-match: /v2/**,
...
-
Start the Spring Boot application
-
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>
-
Open
/api-docs/v3/swagger-config
-
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:
- Created 2 years ago
- Comments:16 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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 ofspringdoc.swagger-ui.path
@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.