Files
swagger-ui/src/core/utils/jsonParse.js
Tim Lai 92f1507408 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
2021-04-20 11:39:05 -07:00

16 lines
415 B
JavaScript

export function canJsonParse(str) {
try {
let testValueForJson = JSON.parse(str)
return testValueForJson ? true : false
} catch (e) {
// exception: string is not valid json
return null
}
}
export function getKnownSyntaxHighlighterLanguage(val) {
// to start, only check for json. can expand as needed in future
const isValidJson = canJsonParse(val)
return isValidJson ? "json" : null
}