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

@@ -0,0 +1,15 @@
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
}