From 2d30e7b64217b8728492356405501bc68cc9dfeb Mon Sep 17 00:00:00 2001 From: mathis-m Date: Fri, 5 Feb 2021 05:40:53 +0100 Subject: [PATCH 1/2] fix(sample-gen): enum without type Signed-off-by: mathis-m --- src/core/plugins/samples/fn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/plugins/samples/fn.js b/src/core/plugins/samples/fn.js index d71f1a6a89b..2077c65b2fc 100644 --- a/src/core/plugins/samples/fn.js +++ b/src/core/plugins/samples/fn.js @@ -133,7 +133,7 @@ export const sampleFromSchemaGeneric = (schema, config={}, exampleOverride = und type = "object" } else if(items) { type = "array" - } else if(!usePlainValue){ + } else if(!usePlainValue && !schema.enum){ return } } From e74ef37c22dcd37ab0bdff5ec7a4174a0ca8316b Mon Sep 17 00:00:00 2001 From: mathis-m Date: Fri, 5 Feb 2021 05:44:11 +0100 Subject: [PATCH 2/2] test(sample-gen): handle enum without type check Signed-off-by: mathis-m --- test/unit/core/plugins/samples/fn.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/unit/core/plugins/samples/fn.js b/test/unit/core/plugins/samples/fn.js index 90c1de224c8..cbda7eec633 100644 --- a/test/unit/core/plugins/samples/fn.js +++ b/test/unit/core/plugins/samples/fn.js @@ -29,6 +29,15 @@ describe("sampleFromSchema", () => { expect(sampleFromSchema(definition, { includeReadOnly: false })).toEqual(expected) }) + it("should return first enum value if only enum is provided", function () { + let definition = fromJS({ + enum: ["probe"] + }) + + let expected = "probe" + expect(sampleFromSchema(definition, { includeReadOnly: false })).toEqual(expected) + }) + it("combine first oneOf or anyOf with schema's definitions", function () { let definition = { type: "object",