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:
15
src/core/utils/jsonParse.js
Normal file
15
src/core/utils/jsonParse.js
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user