fix: path item $ref rendering (#4381)

* WIP: trigger resolution of Path Item $ref on spec load

* fix(dev-server): don't open localhost in a browser

* preserve key order when merging specJson with specResolvedSubtrees

* remove stray `debugger`
This commit is contained in:
kyle
2018-03-27 17:04:31 -07:00
committed by GitHub
parent 71d39af443
commit 8189fd2473
6 changed files with 1148 additions and 7 deletions

View File

@@ -105,7 +105,8 @@ export default class OperationContainer extends PureComponent {
toggleShown =() => {
let { layoutActions, tag, operationId, isShown } = this.props
if(!isShown) {
const resolvedSubtree = this.getResolvedSubtree()
if(!isShown && resolvedSubtree === undefined) {
// transitioning from collapsed to expanded
this.requestResolvedSubtree()
}

View File

@@ -54,7 +54,7 @@ const mergerFn = (oldVal, newVal) => {
return newVal
}
return Map().mergeWith(
return OrderedMap().mergeWith(
mergerFn,
oldVal,
newVal
@@ -66,7 +66,7 @@ const mergerFn = (oldVal, newVal) => {
export const specJsonWithResolvedSubtrees = createSelector(
state,
spec => Map().mergeWith(
spec => OrderedMap().mergeWith(
mergerFn,
spec.get("json"),
spec.get("resolvedSubtrees")
@@ -109,7 +109,7 @@ export const semver = createSelector(
)
export const paths = createSelector(
spec,
specJsonWithResolvedSubtrees,
spec => spec.get("paths")
)

View File

@@ -1,3 +1,5 @@
import get from "lodash/get"
export const updateSpec = (ori, {specActions}) => (...args) => {
ori(...args)
specActions.parseToJson(...args)
@@ -5,7 +7,21 @@ export const updateSpec = (ori, {specActions}) => (...args) => {
export const updateJsonSpec = (ori, {specActions}) => (...args) => {
ori(...args)
specActions.invalidateResolvedSubtreeCache()
// Trigger resolution of any path-level $refs.
const [json] = args
const pathItems = get(json, ["paths"])
const pathItemKeys = Object.keys(pathItems)
pathItemKeys.forEach(k => {
const val = get(pathItems, [k])
if(val.$ref) {
specActions.requestResolvedSubtree(["paths", k])
}
})
}
// Log the request ( just for debugging, shouldn't affect prod )