-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Fix OAS3 relative urls #5341
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
Merged
tim-lai
merged 38 commits into
swagger-api:master
from
geraldglynn:fix/oas3-relative-urls
Aug 4, 2020
Merged
Fix OAS3 relative urls #5341
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
7d39036
Added tooling for appending OAS3 relative URLs to selected Server
95bf267
Merge branch 'master' into fix/oas3-relative-urls
619cbfe
Modified buildUrl util to append realtive URLs beginning with '/' to …
ebef288
Merge branch 'master' into fix/oas3-relative-urls
geraldglynn 4fe710a
Merge branch 'master' into fix/oas3-relative-urls
geraldglynn 9d43142
Removed erroroneous exclamations marks!
geraldglynn 79d61e4
Updated varibale to `termsOfServiceUrl`
geraldglynn e218574
Changed how externalDocs url & description are retrieved and named
geraldglynn 1c5b39b
Changed naming of `tagExternalDocsUrl`
geraldglynn 2518603
Merge branch 'master' into fix/oas3-relative-urls
geraldglynn b44ac98
Added unit test for util `isAbsoluteUrl()`
geraldglynn 2852fb1
Added unit tests for util `buildUrl()`
geraldglynn 74c252e
Cleaned up utils `buildUrl()` to use URL class for constructing URL
geraldglynn d0887a9
Improved unit test for utils `buildUrl()`
geraldglynn 2228717
Removed unused `fromJS` and cleaned up whitespace
geraldglynn 111af62
Merge branch 'master' into fix/oas3-relative-urls
geraldglynn a170d64
Added support for server relative urls in utils `buildUrl()`
geraldglynn e526ef4
Cleaned up `buildUrl` unit tests and added `location.href` to window.…
geraldglynn 9fd7f39
Replaced `app.swaggerhub.com` with `example.com`
geraldglynn 2e62a08
Merge branch 'master' into fix/oas3-relative-urls
geraldglynn e9c91f4
Fixed whitespacing in mocha test `utils.js`
geraldglynn 2d427e0
Added guard to `externalDocs` in <Info />
geraldglynn c7390ed
Commented out `location.href` in window.js; it was breaking another test
geraldglynn b47d397
Added extra check to utils `buildUrl()`
geraldglynn a1edf30
Added `selectedServer` to test mock props
geraldglynn 8ac390b
Skipped test "build url from server with relative url"
geraldglynn 4e69e75
Removed "location" from window.js `props`
geraldglynn 40493da
Added specUrl to buildUrl to support relative server url or no server…
geraldglynn 80b8438
Added unit tests for `buildBaseUrl()` and improved unit tests `isAbso…
geraldglynn 53cad46
Added utils `addProtocol()`
geraldglynn 795355e
Removed `console.log()` from utils
geraldglynn 0632862
Add PropTypes `url`
geraldglynn 867b0aa
Added `specSelector.url()` to mock props for unit test
geraldglynn 86e9af7
Merge branch 'master' into fix/oas3-relative-urls
tim-lai 3c6cf6e
Merge branch 'master' into fix/oas3-relative-urls
geraldglynn 9206b7e
Merge branch 'fix/oas3-relative-urls' of https://github.com/geraldgly…
geraldglynn cba7b4f
Moved new url util functions to `utils/url`
geraldglynn 89b8d1a
style: Update test/mocha/core/utils.js
tim-lai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| export function isAbsoluteUrl(url) { | ||
| return url.match(/^(?:[a-z]+:)?\/\//i) // Matches http://, HTTP://, https://, ftp://, //example.com, | ||
| } | ||
|
|
||
| export function addProtocol(url) { | ||
| if(!url.match(/^\/\//i)) return url // Checks if protocol is missing e.g. //example.com | ||
| return `${window.location.protocol}${url}` | ||
| } | ||
|
|
||
| export function buildBaseUrl(selectedServer, specUrl) { | ||
| if(!selectedServer) return specUrl | ||
| if(isAbsoluteUrl(selectedServer)) return addProtocol(selectedServer) | ||
|
|
||
| return new URL(selectedServer, specUrl).href | ||
| } | ||
|
|
||
| export function buildUrl(url, specUrl, { selectedServer="" } = {}) { | ||
| if(!url) return | ||
| if(isAbsoluteUrl(url)) return url | ||
|
|
||
| const baseUrl = buildBaseUrl(selectedServer, specUrl) | ||
| return new URL(url, baseUrl).href | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
This was a breaking change for us. Our OAS2 documents have inline
termsOfServicerather than a URL e.g.Contrary to OAS 3 with OAS2 it is not required for the
termsOfServiceto be a URL (as per https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#fixed-fields-1). Hence, before building this URL thetermsOfServicevalue should first be verified to be a URL.