Filter $$ref from examples (#4392)

* fix(dev-server): don't open localhost in a browser
* tests: refactor model-example enzyme tests to be more isolated
* tests: add failing sampleFromSchema tests for $$ref keys
* tests: add additional test for user-created $$ref values
* fix: create deeplyStripKey; use it to filter $$refs out of examples
* tests: add cases for deeplyStripKey
This commit is contained in:
kyle
2018-03-30 18:02:32 -07:00
committed by GitHub
parent 762a32b59b
commit fd8274b353
5 changed files with 214 additions and 46 deletions

View File

@@ -1,4 +1,4 @@
import { objectify, isFunc, normalizeArray } from "core/utils"
import { objectify, isFunc, normalizeArray, deeplyStripKey } from "core/utils"
import XML from "xml"
import memoizee from "memoizee"
@@ -29,13 +29,14 @@ export const sampleFromSchema = (schema, config={}) => {
let { type, example, properties, additionalProperties, items } = objectify(schema)
let { includeReadOnly, includeWriteOnly } = config
if(example && example.$$ref) {
delete example.$$ref
if(example !== undefined) {
return deeplyStripKey(example, "$$ref", (val) => {
// do a couple of quick sanity tests to ensure the value
// looks like a $$ref that swagger-client generates.
return typeof val === "string" && val.indexOf("#") > -1
})
}
if(example !== undefined)
return example
if(!type) {
if(properties) {
type = "object"