Skip to content

Support relative server URL #342

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

Open
cbornet opened this issue Jun 18, 2018 · 4 comments · May be fixed by Stanislav1975/openapi-generator#20
Open

Support relative server URL #342

cbornet opened this issue Jun 18, 2018 · 4 comments · May be fixed by Stanislav1975/openapi-generator#20

Comments

@cbornet
Copy link
Member

cbornet commented Jun 18, 2018

Description

Generator doesn't support relative URL for OAIv3 servers.
Whereas the spec specifies

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.

openapi-generator version

3.0.1

OpenAPI declaration file content or url

OpenAPI petstore's server URL is relative and it's /v3

Steps to reproduce
@jmini
Copy link
Member

jmini commented Jun 19, 2018

See also discussion in #239


In my opinion this is the responsibility of the parser to convert the server value into an absolute URL, because when OpenAPI-Generator consumes the OpenAPI there is no indication where it was generated from.

This code snippets already show that the parser does not resolve the server value correctly:

String inputSpec = "http://localhost:8090/openapi.json";

OpenAPIParser openApiParser = new OpenAPIParser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setFlatten(true);

OpenAPI openAPI = openApiParser.readLocation(inputSpec, null, options).getOpenAPI();
String string = Yaml.mapper().writerWithDefaultPrettyPrinter().writeValueAsString(openAPI);

System.out.println(string);

The value stays unchanged. I have filed swagger-api/swagger-parser#742 for that.

@jmini
Copy link
Member

jmini commented Jul 31, 2018

The issue in Swagger-Parser was fixed, and with PR #696 OpenAPI-Generator was updated to use a version containing the fix.

This issue reported here, should no longer appear with the newest 3.2.0-SNAPSHOT version.
@cbornet, can you check it?

@jmini jmini added this to the 3.2.0 milestone Jul 31, 2018
@wing328 wing328 modified the milestones: 3.2.0, 3.2.1 Aug 6, 2018
@wing328 wing328 modified the milestones: 3.2.1, 3.2.2 Aug 14, 2018
@wing328 wing328 modified the milestones: 3.2.2, 3.2.3 Aug 22, 2018
@wing328 wing328 modified the milestones: 3.2.3, 3.3.0 Aug 30, 2018
@rtfeldman
Copy link

I'm not sure if I understand correctly, so I wanted to check:

Is the intended design that it is impossible to end up with a generated client which uses relative URLs?

For example, should the following HTTP request be impossible to generate?

GET "/about"

...and should it instead have to be an absolute URL?

@wing328 wing328 modified the milestones: 3.3.0, 3.3.1 Oct 1, 2018
@wing328 wing328 modified the milestones: 3.3.1, 3.3.2 Oct 15, 2018
@wing328 wing328 modified the milestones: 3.3.2, 3.3.3 Oct 31, 2018
@wing328 wing328 modified the milestones: 3.3.3, 3.3.4 Nov 14, 2018
@wing328 wing328 modified the milestones: 3.3.4, 4.0.0 Nov 30, 2018
@tarioch
Copy link
Contributor

tarioch commented May 10, 2019

I have the same use case as #1290 (api deployed with the project that consumes the api) and it looks weird to me to fix this on the individual generator basis, should this be something to be fixed generally (maybe simply allowing to override the base path?)

@wing328 wing328 modified the milestones: 4.0.0, 4.0.1 May 13, 2019
@wing328 wing328 modified the milestones: 4.0.1, 4.0.2 May 31, 2019
@wing328 wing328 modified the milestones: 4.0.2, 4.0.3 Jun 20, 2019
@wing328 wing328 modified the milestones: 4.0.3, 4.1.0 Jul 9, 2019
@wing328 wing328 modified the milestones: 4.1.0, 4.1.1 Aug 9, 2019
@wing328 wing328 modified the milestones: 4.1.1, 4.1.2 Aug 26, 2019
@wing328 wing328 modified the milestones: 4.1.2, 4.1.3 Sep 11, 2019
@wing328 wing328 modified the milestones: 4.1.3, 4.2.0 Oct 4, 2019
@wing328 wing328 removed this from the 4.2.0 milestone Oct 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants