feat(samples): add support for const keyword (#8884)

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 11:09:10 +02:00
committed by GitHub
parent 3587696d73
commit bdad2fe83d
2 changed files with 15 additions and 10 deletions

View File

@@ -86,32 +86,33 @@ describe("sampleFromSchema", () => {
})
it("should handle type keyword defined as list of types", function () {
const definition = fromJS({
type: ["object", "string"],
})
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 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 definition = fromJS({ type: ["string", "number"] })
const expected = "string"
expect(sampleFromSchema(definition)).toEqual(expected)
})
it("should return const value", function () {
const definition = fromJS({ const: 3 })
const expected = 3
expect(sampleFromSchema(definition)).toStrictEqual(expected)
})
it("handles Immutable.js objects for nested schemas", function () {
const definition = fromJS({
type: "object",