fix: sample generation for nested oject schemas (#4648)
This commit is contained in:
@@ -37,7 +37,7 @@ export function objectify (thing) {
|
|||||||
if(!isObject(thing))
|
if(!isObject(thing))
|
||||||
return {}
|
return {}
|
||||||
if(isImmutable(thing))
|
if(isImmutable(thing))
|
||||||
return thing.toObject()
|
return thing.toJS()
|
||||||
return thing
|
return thing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,35 @@
|
|||||||
|
import { fromJS } from "immutable"
|
||||||
import { createXMLExample, sampleFromSchema } from "corePlugins/samples/fn"
|
import { createXMLExample, sampleFromSchema } from "corePlugins/samples/fn"
|
||||||
import expect from "expect"
|
import expect from "expect"
|
||||||
|
|
||||||
describe("sampleFromSchema", function() {
|
describe("sampleFromSchema", function() {
|
||||||
|
it("handles Immutable.js objects for nested schemas", function () {
|
||||||
|
var definition = fromJS({
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"json": {
|
||||||
|
"type": "object",
|
||||||
|
"example": {
|
||||||
|
"a": "string"
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"a": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
var expected = {
|
||||||
|
json: {
|
||||||
|
a: "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(sampleFromSchema(definition, { includeReadOnly: false })).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
it("returns object with no readonly fields for parameter", function () {
|
it("returns object with no readonly fields for parameter", function () {
|
||||||
var definition = {
|
var definition = {
|
||||||
type: "object",
|
type: "object",
|
||||||
|
|||||||
Reference in New Issue
Block a user