openapi.json fails to take into account servlet context path, produces bad spec file
See original GitHub issuei have a jax-rs application, packaged in a war, deployed on tomcat with a non-empty context path (so at http://host:port/war-name). the ApplicationPath is /api
the openapi.json generated currently looks like this:
{
"openapi": "3.0.1",
"paths": {
"/api/someResourcePath": {
"get": { }
}
}
}
this produces a non-working descriptor as it fails to take into account the context path my war is deployed at. it should probably look like:
{
"openapi": "3.0.1",
"servers":[
{"url": "/war-name"}
],
"paths": {
"/api/someResourcePath": { }
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Springboot swagger url shows WhiteLabel Error page
I found what the issue was, in one of the config files i somehow had @EnableMvc annotation due to which the dispatcherservlet was...
Read more >Documentation - A lightweight Java and Kotlin web framework
You use a method like ctx.result(result) , ctx.json(obj) , or ctx.future(future) to set the response which will be returned to the user.
Read more >Using Eclipse MicroProfile with JBoss EAP XP 2.0.0
To use OpenAPI with multiple deployments registered with different context paths on the same virtual host, each deployment must use a distinct endpoint...
Read more >HTTP status and error codes for JSON | Cloud Storage
Error Response Format. Cloud Storage uses the standard HTTP error reporting format for the JSON API. Successful requests return HTTP status codes in...
Read more >Kickstart your first Quarkus application | by Hantsy - Medium
To fix the issue, we should add JSON support for the representation marshalling and unmarshalling. The quarkus-maven-plugin provides several goals for managing ...
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

PS if you add the server option in your basic openapi.yaml, it “works” - but I would like to change the contextPath based on my deployment name.
Prepends
/myAppNameto the generated URLsGenerally, as mentioned in https://github.com/swagger-api/swagger-core/issues/3523#issuecomment-650571106 with reference to a similar scenario, Web app “home directory” or “base path” or “application path” can be defined in many different ways in many different environments.
The “default” way in case an
@ApplicationPathis present, is to prepend it to paths. In your case or in other scenarios this might be not desired, the two easiest ways to customize this behaviour is either extending Reader or using a filterYou would for example override
resolveApplicationPath()returning an empty string, or adding a filter and updating all keys of openAPI.getPaths().Related tickets for reference:
Closing ticket, please reopen if you’re still experiencing issues