Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added tooling for appending OAS3 relative URLs to selected Server Info * Terms of service URL * Contact URL * License URL * External Docs URL Tag * Tag External Docs URL Operation * Operation External Docs ** Operation Tag Co-authored-by: Tim Lai <timothy.lai@gmail.com>
- Loading branch information
1 parent
225a915
commit d9f5691
Showing
11 changed files
with
174 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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.