fix(resolve): make retrievalURI absolute before resolution (#9214)

Refs #9208
This commit is contained in:
Vladimír Gorej
2023-09-14 13:33:31 +02:00
committed by GitHub
parent 542f490ec5
commit 9ca41e0b40
3 changed files with 3 additions and 19 deletions

View File

@@ -4,7 +4,6 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="img-src 'self'" />
<title>Swagger UI</title> <title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="style.css"> <link rel="stylesheet" type="text/css" href="style.css">
<style> <style>

View File

@@ -154,9 +154,7 @@ export default function SwaggerUI(opts) {
spec: { spec: {
spec: "", spec: "",
// support Relative References // support Relative References
url: constructorConfig.url url: constructorConfig.url,
? new URL(constructorConfig.url, document.baseURI).toString()
: constructorConfig.url,
}, },
requestSnippets: constructorConfig.requestSnippets requestSnippets: constructorConfig.requestSnippets
}, constructorConfig.initialState) }, constructorConfig.initialState)
@@ -193,19 +191,6 @@ export default function SwaggerUI(opts) {
let localConfig = system.specSelectors.getLocalConfig ? system.specSelectors.getLocalConfig() : {} let localConfig = system.specSelectors.getLocalConfig ? system.specSelectors.getLocalConfig() : {}
let mergedConfig = deepExtend({}, localConfig, constructorConfig, fetchedConfig || {}, queryConfig) 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 // deep extend mangles domNode, we need to set it manually
if(domNode) { if(domNode) {
mergedConfig.domNode = domNode mergedConfig.domNode = domNode

View File

@@ -111,7 +111,7 @@ export const resolveSpec = (json, url) => ({specActions, specSelectors, errActio
return resolve({ return resolve({
fetch, fetch,
spec: json, spec: json,
baseDoc: url, baseDoc: String(new URL(url, document.baseURI)),
modelPropertyMacro, modelPropertyMacro,
parameterMacro, parameterMacro,
requestInterceptor, requestInterceptor,
@@ -183,7 +183,7 @@ const debResolveSubtrees = debounce(() => {
const batchResult = await systemRequestBatch.reduce(async (prev, path) => { const batchResult = await systemRequestBatch.reduce(async (prev, path) => {
let { resultMap, specWithCurrentSubtrees } = await prev let { resultMap, specWithCurrentSubtrees } = await prev
const { errors, spec } = await resolveSubtree(specWithCurrentSubtrees, path, { const { errors, spec } = await resolveSubtree(specWithCurrentSubtrees, path, {
baseDoc: specSelectors.url(), baseDoc: String(new URL(specSelectors.url(), document.baseURI)),
modelPropertyMacro, modelPropertyMacro,
parameterMacro, parameterMacro,
requestInterceptor, requestInterceptor,