fix(syntaxHighlighter): request and response examples for json cases (#7199)

* OAS 2 request and response examples for json cases
* OAS 3 request and response examples for json cases
* OAS2 and OAS3 tests
* jsonParse utils for syntax highlighting
This commit is contained in:
Tim Lai
2021-04-20 11:39:05 -07:00
committed by GitHub
parent f408e7d0c8
commit 92f1507408
8 changed files with 276 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ import PropTypes from "prop-types"
import ImPropTypes from "react-immutable-proptypes"
import { Map, OrderedMap, List } from "immutable"
import { getCommonExtensions, getSampleSchema, stringify, isEmptyValue } from "core/utils"
import { getKnownSyntaxHighlighterLanguage } from "core/utils/jsonParse"
export const getDefaultRequestBodyValue = (requestBody, mediaType, activeExamplesKey) => {
const mediaTypeValue = requestBody.getIn(["content", mediaType])
@@ -235,6 +236,11 @@ const RequestBody = ({
contentType,
activeExamplesKey,
)
let language = null
let testValueForJson = getKnownSyntaxHighlighterLanguage(sampleRequestBody)
if (testValueForJson) {
language = "json"
}
return <div>
{ requestBodyDescription &&
@@ -279,6 +285,7 @@ const RequestBody = ({
<HighlightCode
className="body-param__example"
getConfigs={getConfigs}
language={language}
value={stringify(requestBodyValue) || sampleRequestBody}
/>
}