-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Codegen] Spec not adhered to wrt. relative Server URLs #7960
Comments
At first glance it seems like this line could be altered to: return new URL(config.getInputSpec())
.toURI()
.resolve(url)
.toURL(); if |
I'm running into this issue as well with the latest 3.0.0 snapshot. If I switch back to the latest 2.4.0 snapshot, the problem goes away. |
This issue still appears to be present in 3.0.0. |
I'm running into the same error. Swagger API on the server is version 2.3.0 and the relative URl on the swagger.json is I worked around it by hard coding the entire server URL into line 32 of |
I noticed that when |
this issue has been fixed with PR #9047, so going to close this issue but please let me know if you find something wrong and i'll work on it. |
R u guys planning to merge this fix to the 2.x master branch any time soon? Thx for the great work! |
Description
The spec for a Server Object states that the URL is "A URL to the target host. This URL supports Server Variables and MAY be relative, to indicate that the host location is relative to the location where the OpenAPI document is being served" (emphasis mine).
The generator does not support relative URLs:
Swagger-codegen version
3.0.0-SNAPSHOT (swagger-codegen-cli-3.0.0-20180328.231509-53.jar)
Swagger declaration file content or url
Command line used for generation
$ java -jar ~/swagger-codegen-cli-3.0.0-20180328.231509-53.jar generate -i http://localhost:48781/v1/openapi.json -l java -o /tmp/test/
Steps to reproduce
Specify a relative URL for a server object definition and provide the codegen tool with a URL to the OpenAPI JSON file, e.g.
http://foo.com/openapi.json
specifyingand expecting the URL to be expanded to
http://foo.com/api
.Related issues/PRs
Did not find related issues.
Suggest a fix/enhancement
My reading of the spec is that since a relative URL is a valid value for the
url
field, it should be used, along with the input file provided to the codegen (i.e. via the-i
switch) to derive a new URL.This will allow OpenAPI files to be served from behind proxies/load balancers where the actual server cannot know its public address with certainty (
X-Forwarded-Host
can be wrong).The text was updated successfully, but these errors were encountered: