Skip to content
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

Fix for parsing relative server URLs #62

Closed
wants to merge 1 commit into from
Closed

Conversation

tamlyn
Copy link
Contributor

@tamlyn tamlyn commented Sep 7, 2020

If the server URL is relative like /some-path then the URL constructor throws an error because it doesn't know how to resolve it. Passing a dummy base URL to the constructor avoids the problem.

@@ -83,7 +83,7 @@ paths:
$ref: "#/components/schemas/Error"
servers:
- url: http://petstore.swagger.io
- url: http://petstore.swagger.io/staging/
- url: /staging/
components:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better to add additional entry and not replace existing one .

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd also like to see a test that checks that all urls are parsed correctly

@@ -37,7 +37,8 @@ function buildValidations(referenced, dereferenced, receivedOptions) {
const schemas = {};

const basePaths = dereferenced.servers && dereferenced.servers.length
? dereferenced.servers.map(({ url }) => new URL(url).pathname)
// dummy base path is required by URL constructor when server url is not absolute
? dereferenced.servers.map(({ url }) => new URL(url, 'http://example.com').pathname)
Copy link
Collaborator

@kibertoad kibertoad Sep 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would matching work correctly with this hardcoded value? Definitely needs a new e2e test for this case of matching.

@kobik
Copy link
Collaborator

kobik commented Oct 5, 2020

Hi @tamlyn , thanks for you PR.

Would you mind address the comments?

While we're at it, we can also fix #59 by bumping swagger-parser version.

@tamlyn
Copy link
Contributor Author

tamlyn commented Oct 8, 2020

Sorry, we're no longer using this package so it's unlikely I'll have time to do the update. Happy for someone else to take it over of course. Thanks.

@kobik
Copy link
Collaborator

kobik commented Nov 26, 2020

Hi @tamlyn , are we continuing with this PR?

@kobik kobik closed this Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants