From f53f92351ec9f493b04125da29dcaab950932ddf Mon Sep 17 00:00:00 2001 From: kyle Date: Thu, 14 Jun 2018 16:56:03 -0700 Subject: [PATCH] fix: sample generation for nested oject schemas (#4648) --- src/core/utils.js | 2 +- test/core/plugins/samples/fn.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/core/utils.js b/src/core/utils.js index 795e3ae9..3f77a1bf 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -37,7 +37,7 @@ export function objectify (thing) { if(!isObject(thing)) return {} if(isImmutable(thing)) - return thing.toObject() + return thing.toJS() return thing } diff --git a/test/core/plugins/samples/fn.js b/test/core/plugins/samples/fn.js index 65fdd141..a3266177 100644 --- a/test/core/plugins/samples/fn.js +++ b/test/core/plugins/samples/fn.js @@ -1,7 +1,35 @@ +import { fromJS } from "immutable" import { createXMLExample, sampleFromSchema } from "corePlugins/samples/fn" import expect from "expect" 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 () { var definition = { type: "object",