-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conversation
@@ -83,7 +83,7 @@ paths: | |||
$ref: "#/components/schemas/Error" | |||
servers: | |||
- url: http://petstore.swagger.io | |||
- url: http://petstore.swagger.io/staging/ | |||
- url: /staging/ | |||
components: |
There was a problem hiding this comment.
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 .
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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. |
Hi @tamlyn , are we continuing with this PR? |
If the server URL is relative like
/some-path
then theURL
constructor throws an error because it doesn't know how to resolve it. Passing a dummy base URL to the constructor avoids the problem.