Skip to content

Commit acac3ee

Browse files
committed
Merge branch 'master' of github.com:swagger-api/swagger-ui
2 parents 78ed1e6 + 11d8a34 commit acac3ee

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"dependencies": {
4242
"base64-js": "^1.2.0",
4343
"brace": "0.7.0",
44+
"css.escape": "1.5.1",
4445
"deep-extend": "0.4.1",
4546
"expect": "1.20.2",
4647
"getbase": "^2.8.2",

src/core/components/operations.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react"
22
import PropTypes from "prop-types"
33
import { helpers } from "swagger-client"
4-
4+
import { createDeepLinkPath } from "core/utils"
55
const { opId } = helpers
66

77
export default class Operations extends React.Component {
@@ -69,7 +69,7 @@ export default class Operations extends React.Component {
6969
let tagExternalDocsDescription = tagObj.getIn(["tagDetails", "externalDocs", "description"])
7070
let tagExternalDocsUrl = tagObj.getIn(["tagDetails", "externalDocs", "url"])
7171

72-
let isShownKey = ["operations-tag", tag]
72+
let isShownKey = ["operations-tag", createDeepLinkPath(tag)]
7373
let showTag = layoutSelectors.isShown(isShownKey, docExpansion === "full" || docExpansion === "list")
7474

7575
return (
@@ -124,7 +124,7 @@ export default class Operations extends React.Component {
124124

125125
const operationId =
126126
op.getIn(["operation", "operationId"]) || op.getIn(["operation", "__originalOperationId"]) || opId(op.get("operation"), path, method) || op.get("id")
127-
const isShownKey = ["operations", tag, operationId]
127+
const isShownKey = ["operations", createDeepLinkPath(tag), createDeepLinkPath(operationId)]
128128

129129
const allowTryItOut = specSelectors.allowTryItOutFor(op.get("path"), op.get("method"))
130130
const response = specSelectors.responseFor(op.get("path"), op.get("method"))

src/core/plugins/deep-linking/layout-wrap-actions.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { setHash } from "./helpers"
2+
import { createDeepLinkPath } from "core/utils"
23

34
export const show = (ori, { getConfigs }) => (...args) => {
45
ori(...args)
@@ -19,12 +20,12 @@ export const show = (ori, { getConfigs }) => (...args) => {
1920

2021
if(type === "operations") {
2122
let [, tag, operationId] = thing
22-
setHash(`/${tag}/${operationId}`)
23+
setHash(`/${createDeepLinkPath(tag)}/${createDeepLinkPath(operationId)}`)
2324
}
2425

2526
if(type === "operations-tag") {
2627
let [, tag] = thing
27-
setHash(`/${tag}`)
28+
setHash(`/${createDeepLinkPath(tag)}`)
2829
}
2930
}
3031

src/core/plugins/deep-linking/spec-wrap-actions.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import scrollTo from "scroll-to-element"
2+
import { escapeDeepLinkPath } from "core/utils"
23

34
const SCROLL_OFFSET = -5
45
let hasHashBeenParsed = false
@@ -34,14 +35,14 @@ export const updateResolved = (ori, { layoutActions, getConfigs }) => (...args)
3435
layoutActions.show(["operations-tag", tag], true)
3536
layoutActions.show(["operations", tag, operationId], true)
3637

37-
scrollTo(`#operations-${tag}-${operationId}`, {
38+
scrollTo(`#operations-${escapeDeepLinkPath(tag)}-${escapeDeepLinkPath(operationId)}`, {
3839
offset: SCROLL_OFFSET
3940
})
4041
} else if(tag) {
4142
// Pre-expand and scroll to the tag
4243
layoutActions.show(["operations-tag", tag], true)
4344

44-
scrollTo(`#operations-tag-${tag}`, {
45+
scrollTo(`#operations-tag-${escapeDeepLinkPath(tag)}`, {
4546
offset: SCROLL_OFFSET
4647
})
4748
}

src/core/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import some from "lodash/some"
88
import eq from "lodash/eq"
99
import { memoizedSampleFromSchema, memoizedCreateXMLExample } from "core/plugins/samples/fn"
1010
import win from "./window"
11+
import cssEscape from "css.escape"
1112

1213
const DEFAULT_REPONSE_KEY = "default"
1314

@@ -650,3 +651,6 @@ export const shallowEqualKeys = (a,b, keys) => {
650651
return eq(a[key], b[key])
651652
})
652653
}
654+
655+
export const createDeepLinkPath = (str) => str ? str.replace(/\s/g, "_") : ""
656+
export const escapeDeepLinkPath = (str) => cssEscape( createDeepLinkPath(str) )

0 commit comments

Comments
 (0)