#3256 - Remove unnecessary JSON.stringify call on example values that are already strings

This commit is contained in:
Owen Conti
2017-06-25 16:39:54 -06:00
parent 165c1d7fcb
commit de3046e29d

View File

@@ -5,14 +5,16 @@ import { getSampleSchema } from "core/utils"
const getExampleComponent = ( sampleResponse, examples, HighlightCode ) => { const getExampleComponent = ( sampleResponse, examples, HighlightCode ) => {
if ( examples && examples.size ) { if ( examples && examples.size ) {
return examples.entrySeq().map( ([ key, example ]) => { return examples.entrySeq().map( ([ key, example ]) => {
let exampleValue let exampleValue = example
if ( example.toJS ) {
try { try {
exampleValue = example && example.toJS ? example.toJS() : example exampleValue = JSON.stringify(example.toJS(), null, 2)
exampleValue = JSON.stringify(exampleValue, null, 2)
} }
catch(e) { catch(e) {
exampleValue = String(example) exampleValue = String(example)
} }
}
return (<div key={ key }> return (<div key={ key }>
<h5>{ key }</h5> <h5>{ key }</h5>
<HighlightCode className="example" value={ exampleValue } /> <HighlightCode className="example" value={ exampleValue } />