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.

openapi.json fails to take into account servlet context path, produces bad spec file

See original GitHub issue

i 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:open
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cljkcommented, May 2, 2019

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.

openAPI:
  info:
    version: '1.0'
    title: [...]
[...]
  servers:
    - url: /myAppName

Prepends /myAppName to the generated URLs

0reactions
frantumacommented, Apr 16, 2021

Generally, 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 @ApplicationPath is 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 filter

You 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

Read more comments on GitHub >

github_iconTop 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 >

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