Skip to content

Commit fa312cb

Browse files
authored
Merge branch 'master' into bug/oas3-accept-controls
2 parents 277cc81 + 11d8a34 commit fa312cb

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
@@ -42,6 +42,7 @@
4242
"base64-js": "^1.2.0",
4343
"brace": "0.7.0",
4444
"classnames": "^2.2.5",
45+
"css.escape": "1.5.1",
4546
"deep-extend": "0.4.1",
4647
"expect": "1.20.2",
4748
"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 {
@@ -71,7 +71,7 @@ export default class Operations extends React.Component {
7171
let tagExternalDocsDescription = tagObj.getIn(["tagDetails", "externalDocs", "description"])
7272
let tagExternalDocsUrl = tagObj.getIn(["tagDetails", "externalDocs", "url"])
7373

74-
let isShownKey = ["operations-tag", tag]
74+
let isShownKey = ["operations-tag", createDeepLinkPath(tag)]
7575
let showTag = layoutSelectors.isShown(isShownKey, docExpansion === "full" || docExpansion === "list")
7676

7777
return (
@@ -126,7 +126,7 @@ export default class Operations extends React.Component {
126126

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

131131
const allowTryItOut = specSelectors.allowTryItOutFor(op.get("path"), op.get("method"))
132132
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

@@ -673,3 +674,6 @@ export function getAcceptControllingResponse(responses) {
673674

674675
return suitable2xxResponse || suitableDefaultResponse
675676
}
677+
678+
export const createDeepLinkPath = (str) => str ? str.replace(/\s/g, "_") : ""
679+
export const escapeDeepLinkPath = (str) => cssEscape( createDeepLinkPath(str) )

0 commit comments

Comments
 (0)