diff --git a/src/core/plugins/json-schema-2020-12/samples-extensions/fn/main.js b/src/core/plugins/json-schema-2020-12/samples-extensions/fn/main.js
index 983d6253434..ee57f223ebd 100644
--- a/src/core/plugins/json-schema-2020-12/samples-extensions/fn/main.js
+++ b/src/core/plugins/json-schema-2020-12/samples-extensions/fn/main.js
@@ -420,7 +420,7 @@ export const sampleFromSchemaGeneric = (
return res
}
- if (isBooleanJSONSchema(additionalProperties)) {
+ if (isBooleanJSONSchema(additionalProperties) && additionalProperties) {
if (respectXML) {
res[displayName].push({ additionalProp: "Anything can be here" })
} else {
diff --git a/test/unit/core/plugins/json-schema-2020-12/samples-extensions/fn.js b/test/unit/core/plugins/json-schema-2020-12/samples-extensions/fn.js
index 181173efe0f..936e3f9d0c4 100644
--- a/test/unit/core/plugins/json-schema-2020-12/samples-extensions/fn.js
+++ b/test/unit/core/plugins/json-schema-2020-12/samples-extensions/fn.js
@@ -1189,6 +1189,67 @@ describe("sampleFromSchema", () => {
expect(sampleFromSchema(definition)).toEqual(expected)
})
+
+ it("should handle additionalProperties", () => {
+ const definition = {
+ type: "object",
+ additionalProperties: {
+ type: "string",
+ },
+ properties: {
+ foo: {
+ type: "string",
+ },
+ },
+ }
+
+ const expected = {
+ foo: "string",
+ additionalProp1: "string",
+ additionalProp2: "string",
+ additionalProp3: "string",
+ }
+
+ expect(sampleFromSchema(definition)).toEqual(expected)
+ })
+
+ it("should handle additionalProperties=true", () => {
+ const definition = {
+ type: "object",
+ additionalProperties: true,
+ properties: {
+ foo: {
+ type: "string",
+ },
+ },
+ }
+
+ const expected = {
+ foo: "string",
+ additionalProp1: {},
+ }
+
+ expect(sampleFromSchema(definition)).toEqual(expected)
+ })
+
+ it("should handle additionalProperties=false", () => {
+ const definition = {
+ type: "object",
+ additionalProperties: false,
+ properties: {
+ foo: {
+ type: "string",
+ },
+ },
+ }
+
+ const expected = {
+ foo: "string",
+ }
+
+ expect(sampleFromSchema(definition)).toEqual(expected)
+ })
+
it("should ignore minProperties if cannot extend object", () => {
const definition = {
type: "object",
@@ -2618,6 +2679,25 @@ describe("createXMLExample", function () {
expect(sut(definition)).toEqual(expected)
})
+ it("returns object with additional props =false", function () {
+ let expected =
+ '\n\n\tstring\n'
+ let definition = {
+ type: "object",
+ properties: {
+ dog: {
+ type: "string",
+ },
+ },
+ additionalProperties: false,
+ xml: {
+ name: "animals",
+ },
+ }
+
+ expect(sut(definition)).toEqual(expected)
+ })
+
it("returns object with 2 properties with no type passed but properties", function () {
const expected =
'\n\n\tstring\n\t0\n'
diff --git a/test/unit/core/plugins/samples/fn/index.js b/test/unit/core/plugins/samples/fn/index.js
index 11815f95fd8..d4de01d5542 100644
--- a/test/unit/core/plugins/samples/fn/index.js
+++ b/test/unit/core/plugins/samples/fn/index.js
@@ -914,6 +914,68 @@ describe("sampleFromSchema", () => {
expect(sampleFromSchema(definition)).toEqual(expected)
})
+
+
+ it("should handle additionalProperties", () => {
+ const definition = {
+ type: "object",
+ additionalProperties: {
+ type: "string",
+ },
+ properties: {
+ foo: {
+ type: "string",
+ },
+ },
+ }
+
+ const expected = {
+ foo: "string",
+ additionalProp1: "string",
+ additionalProp2: "string",
+ additionalProp3: "string",
+ }
+
+ expect(sampleFromSchema(definition)).toEqual(expected)
+ })
+
+ it("should handle additionalProperties=true", () => {
+ const definition = {
+ type: "object",
+ additionalProperties: true,
+ properties: {
+ foo: {
+ type: "string",
+ },
+ },
+ }
+
+ const expected = {
+ foo: "string",
+ additionalProp1: {},
+ }
+
+ expect(sampleFromSchema(definition)).toEqual(expected)
+ })
+
+ it("should handle additionalProperties=false", () => {
+ const definition = {
+ type: "object",
+ additionalProperties: false,
+ properties: {
+ foo: {
+ type: "string",
+ },
+ },
+ }
+
+ const expected = {
+ foo: "string",
+ }
+
+ expect(sampleFromSchema(definition)).toEqual(expected)
+ })
+
it("should ignore minProperties if cannot extend object", () => {
const definition = {
type: "object",
@@ -2149,6 +2211,24 @@ describe("createXMLExample", function () {
expect(sut(definition)).toEqual(expected)
})
+ it("returns object with additional props =false", function () {
+ let expected = "\n\n\tstring\n"
+ let definition = {
+ type: "object",
+ properties: {
+ dog: {
+ type: "string"
+ }
+ },
+ additionalProperties: false,
+ xml: {
+ name: "animals"
+ }
+ }
+
+ expect(sut(definition)).toEqual(expected)
+ })
+
it("returns object with 2 properties with no type passed but properties", function () {
let expected = "\n\n\tstring\n\t0\n"
let definition = {