Skip to content

Commit

Permalink
fix(sample-gen): should return json literal example (#6827)
Browse files Browse the repository at this point in the history
* fix(sample-gen): should return json literal example

* test(sample-gen): should return json literal example
  • Loading branch information
mathis-m committed Jan 14, 2021
1 parent 7087210 commit a2f7917
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 210 deletions.
12 changes: 11 additions & 1 deletion src/core/plugins/samples/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,17 @@ export const sampleFromSchemaGeneric = (schema, config={}, exampleOverride = und

// if json just return
if(!respectXML) {
return sample
// return if sample does not need any parsing
if(typeof sample !== "string") {
return sample
}
// check if sample is parsable or just a plain string
try {
return JSON.parse(sample)
} catch(e) {
// sample is just plain string return it
return sample
}
}

// recover missing type
Expand Down
Loading

0 comments on commit a2f7917

Please sign in to comment.