fix(json-schema-2020-12-samples): fix examples for nullable primitive types defined as list of types (#10390)

This commit is contained in:
ctyar
2025-04-03 07:12:42 +01:00
committed by GitHub
parent ac4b549bfd
commit d375f50914
2 changed files with 18 additions and 1 deletions

View File

@@ -373,6 +373,20 @@ describe("sampleFromSchema", () => {
expect(sampleFromSchema(definition)).toEqual(expected)
})
it("should handle nullable primitive types defined as list of types", function () {
const sample = (schema) => sampleFromSchema(fromJS(schema))
expect(sample({ type: ["string", "null"] })).toStrictEqual("string")
expect(sample({ type: ["null", "string"] })).toStrictEqual("string")
expect(sample({ type: ["number", "null"] })).toStrictEqual(0)
expect(sample({ type: ["null", "number"] })).toStrictEqual(0)
expect(sample({ type: ["integer", "null"] })).toStrictEqual(0)
expect(sample({ type: ["null", "integer"] })).toStrictEqual(0)
expect(sample({ type: ["boolean", "null"] })).toStrictEqual(true)
expect(sample({ type: ["null", "boolean"] })).toStrictEqual(true)
expect(sample({ type: ["null"] })).toStrictEqual(null)
})
it("should return const value", function () {
const definition = fromJS({ const: 3 })
const expected = 3