feat(samples): add support for type keyword defined as list of types (#8883)

This change is specific to JSON Schema 2020-12
and OpenAPI 3.1.0.

Refs #8577
This commit is contained in:
Vladimír Gorej
2023-06-06 10:54:08 +02:00
committed by GitHub
parent 28b12338f8
commit 3587696d73
2 changed files with 107 additions and 77 deletions

View File

@@ -82,6 +82,34 @@ describe("sampleFromSchema", () => {
2 ** 53 - 1
)
expect(sample({ type: "boolean" })).toStrictEqual(true)
expect(sample({ type: "null" })).toStrictEqual(null)
})
it("should handle type keyword defined as list of types", function () {
const definition = fromJS({
type: ["object", "string"],
})
const expected = {}
expect(sampleFromSchema(definition)).toEqual(expected)
})
it("should prioritize array when array and object defined as list of types", function () {
const definition = fromJS({
type: ["object", "array"],
})
const expected = []
expect(sampleFromSchema(definition)).toEqual(expected)
})
it("should handle primitive types defined as list of types", function () {
const definition = fromJS({
type: ["string", "number"],
})
const expected = "string"
expect(sampleFromSchema(definition)).toEqual(expected)
})
it("handles Immutable.js objects for nested schemas", function () {
@@ -353,9 +381,9 @@ describe("sampleFromSchema", () => {
value: {
message: "Hello, World!",
},
$$ref: "#/components/examples/WelcomeExample",
$$ref: "https://example.com/#/components/examples/WelcomeExample",
},
$$ref: "#/components/schemas/Welcome",
$$ref: "https://example.com/#/components/schemas/Welcome",
}
const expected = {
@@ -382,10 +410,10 @@ describe("sampleFromSchema", () => {
value: {
message: "Hello, World!",
},
$$ref: "#/components/examples/WelcomeExample",
$$ref: "https://example.com/#/components/examples/WelcomeExample",
},
},
$$ref: "#/components/schemas/Welcome",
$$ref: "https://example.com/#/components/schemas/Welcome",
}
const expected = {
@@ -414,10 +442,10 @@ describe("sampleFromSchema", () => {
value: {
message: "Hello, World!",
},
$$ref: "#/components/examples/WelcomeExample",
$$ref: "https://example.com/#/components/examples/WelcomeExample",
},
},
$$ref: "#/components/schemas/Welcome",
$$ref: "https://example.com/#/components/schemas/Welcome",
}
const expected = {