Skip to content

Commit

Permalink
fix(resolve): make retrievalURI absolute before resolution (#9214)
Browse files Browse the repository at this point in the history
Refs #9208
  • Loading branch information
char0n committed Sep 14, 2023
1 parent 542f490 commit 9ca41e0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 19 deletions.
1 change: 0 additions & 1 deletion dev-helpers/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="img-src 'self'" />
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="style.css">
<style>
Expand Down
17 changes: 1 addition & 16 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ export default function SwaggerUI(opts) {
spec: {
spec: "",
// support Relative References
url: constructorConfig.url
? new URL(constructorConfig.url, document.baseURI).toString()
: constructorConfig.url,
url: constructorConfig.url,
},
requestSnippets: constructorConfig.requestSnippets
}, constructorConfig.initialState)
Expand Down Expand Up @@ -193,19 +191,6 @@ export default function SwaggerUI(opts) {
let localConfig = system.specSelectors.getLocalConfig ? system.specSelectors.getLocalConfig() : {}
let mergedConfig = deepExtend({}, localConfig, constructorConfig, fetchedConfig || {}, queryConfig)

// support Relative References in `url` config option
if (mergedConfig.url) {
mergedConfig.url = new URL(mergedConfig.url, document.baseURI).toString()
}

// support Relative References in `urls` config option
if (Array.isArray(mergedConfig.urls)) {
mergedConfig.urls = mergedConfig.urls.map(({ url , ...rest}) => ({
url: new URL(url, document.baseURI).toString(),
...rest,
}))
}

// deep extend mangles domNode, we need to set it manually
if(domNode) {
mergedConfig.domNode = domNode
Expand Down
4 changes: 2 additions & 2 deletions src/core/plugins/spec/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const resolveSpec = (json, url) => ({specActions, specSelectors, errActio
return resolve({
fetch,
spec: json,
baseDoc: url,
baseDoc: String(new URL(url, document.baseURI)),
modelPropertyMacro,
parameterMacro,
requestInterceptor,
Expand Down Expand Up @@ -183,7 +183,7 @@ const debResolveSubtrees = debounce(() => {
const batchResult = await systemRequestBatch.reduce(async (prev, path) => {
let { resultMap, specWithCurrentSubtrees } = await prev
const { errors, spec } = await resolveSubtree(specWithCurrentSubtrees, path, {
baseDoc: specSelectors.url(),
baseDoc: String(new URL(specSelectors.url(), document.baseURI)),
modelPropertyMacro,
parameterMacro,
requestInterceptor,
Expand Down

0 comments on commit 9ca41e0

Please sign in to comment.