fix: expand tags and operations predictably in multiple SwaggerUI instances (#9050)
Refs #6996 Co-authored-by: Vladimír Gorej <vladimir.gorej@smartbear.com>
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
import YAML, { JSON_SCHEMA } from "js-yaml"
|
import YAML, { JSON_SCHEMA } from "js-yaml"
|
||||||
import { Map } from "immutable"
|
import { Map as ImmutableMap } from "immutable"
|
||||||
import parseUrl from "url-parse"
|
import parseUrl from "url-parse"
|
||||||
import { serializeError } from "serialize-error"
|
import { serializeError } from "serialize-error"
|
||||||
import isString from "lodash/isString"
|
import isString from "lodash/isString"
|
||||||
import debounce from "lodash/debounce"
|
import debounce from "lodash/debounce"
|
||||||
import set from "lodash/set"
|
import set from "lodash/set"
|
||||||
import assocPath from "lodash/fp/assocPath"
|
import assocPath from "lodash/fp/assocPath"
|
||||||
|
import constant from "lodash/constant"
|
||||||
|
|
||||||
import { paramToValue, isEmptyValue } from "core/utils"
|
import { paramToValue, isEmptyValue } from "core/utils"
|
||||||
|
|
||||||
@@ -140,13 +141,24 @@ export const resolveSpec = (json, url) => ({specActions, specSelectors, errActio
|
|||||||
|
|
||||||
let requestBatch = []
|
let requestBatch = []
|
||||||
|
|
||||||
const debResolveSubtrees = debounce(async () => {
|
const debResolveSubtrees = debounce(() => {
|
||||||
const system = requestBatch.system // Just a reference to the "latest" system
|
const systemPartitionedBatches = requestBatch.reduce((acc, { path, system }) => {
|
||||||
|
if (!acc.has(system)) acc.set(system, [])
|
||||||
|
acc.get(system).push(path)
|
||||||
|
return acc
|
||||||
|
}, new Map())
|
||||||
|
|
||||||
|
requestBatch = [] // clear stack
|
||||||
|
|
||||||
|
systemPartitionedBatches.forEach(async (systemRequestBatch, system) => {
|
||||||
if(!system) {
|
if(!system) {
|
||||||
console.error("debResolveSubtrees: don't have a system to operate on, aborting.")
|
console.error("debResolveSubtrees: don't have a system to operate on, aborting.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if(!system.fn.resolveSubtree) {
|
||||||
|
console.error("Error: Swagger-Client did not provide a `resolveSubtree` method, doing nothing.")
|
||||||
|
return
|
||||||
|
}
|
||||||
const {
|
const {
|
||||||
errActions,
|
errActions,
|
||||||
errSelectors,
|
errSelectors,
|
||||||
@@ -158,16 +170,8 @@ const debResolveSubtrees = debounce(async () => {
|
|||||||
specSelectors,
|
specSelectors,
|
||||||
specActions,
|
specActions,
|
||||||
} = system
|
} = system
|
||||||
|
const getLineNumberForPath = AST.getLineNumberForPath ?? constant(undefined)
|
||||||
if(!resolveSubtree) {
|
|
||||||
console.error("Error: Swagger-Client did not provide a `resolveSubtree` method, doing nothing.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let getLineNumberForPath = AST.getLineNumberForPath ? AST.getLineNumberForPath : () => undefined
|
|
||||||
|
|
||||||
const specStr = specSelectors.specStr()
|
const specStr = specSelectors.specStr()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
modelPropertyMacro,
|
modelPropertyMacro,
|
||||||
parameterMacro,
|
parameterMacro,
|
||||||
@@ -176,7 +180,7 @@ const debResolveSubtrees = debounce(async () => {
|
|||||||
} = system.getConfigs()
|
} = system.getConfigs()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var batchResult = await requestBatch.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: specSelectors.url(),
|
||||||
@@ -239,32 +243,28 @@ const debResolveSubtrees = debounce(async () => {
|
|||||||
specWithCurrentSubtrees
|
specWithCurrentSubtrees
|
||||||
}
|
}
|
||||||
}, Promise.resolve({
|
}, Promise.resolve({
|
||||||
resultMap: (specSelectors.specResolvedSubtree([]) || Map()).toJS(),
|
resultMap: (specSelectors.specResolvedSubtree([]) || ImmutableMap()).toJS(),
|
||||||
specWithCurrentSubtrees: specSelectors.specJS()
|
specWithCurrentSubtrees: specSelectors.specJS()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
delete requestBatch.system
|
specActions.updateResolvedSubtree([], batchResult.resultMap)
|
||||||
requestBatch = [] // Clear stack
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
specActions.updateResolvedSubtree([], batchResult.resultMap)
|
|
||||||
}, 35)
|
}, 35)
|
||||||
|
|
||||||
export const requestResolvedSubtree = path => system => {
|
export const requestResolvedSubtree = path => system => {
|
||||||
// poor-man's array comparison
|
const isPathAlreadyBatched = requestBatch.find(({ path: batchedPath, system: batchedSystem }) => {
|
||||||
// if this ever inadequate, this should be rewritten to use Im.List
|
return batchedSystem === system && batchedPath.toString() === path.toString()
|
||||||
const isPathAlreadyBatched = requestBatch
|
})
|
||||||
.map(arr => arr.join("@@"))
|
|
||||||
.indexOf(path.join("@@")) > -1
|
|
||||||
|
|
||||||
if(isPathAlreadyBatched) {
|
if(isPathAlreadyBatched) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
requestBatch.push(path)
|
requestBatch.push({ path, system })
|
||||||
requestBatch.system = system
|
|
||||||
debResolveSubtrees()
|
debResolveSubtrees()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,7 +294,7 @@ export const invalidateResolvedSubtreeCache = () => {
|
|||||||
type: UPDATE_RESOLVED_SUBTREE,
|
type: UPDATE_RESOLVED_SUBTREE,
|
||||||
payload: {
|
payload: {
|
||||||
path: [],
|
path: [],
|
||||||
value: Map()
|
value: ImmutableMap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -432,7 +432,7 @@ export const executeRequest = (req) =>
|
|||||||
req.requestBody = requestBody
|
req.requestBody = requestBody
|
||||||
.map(
|
.map(
|
||||||
(val) => {
|
(val) => {
|
||||||
if (Map.isMap(val)) {
|
if (ImmutableMap.isMap(val)) {
|
||||||
return val.get("value")
|
return val.get("value")
|
||||||
}
|
}
|
||||||
return val
|
return val
|
||||||
|
|||||||
Reference in New Issue
Block a user