feat(samples): add support for contentSchema keyword (#8907)

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-09 21:35:44 +02:00
committed by GitHub
parent d72b72c5c6
commit 6c622a87e7
9 changed files with 174 additions and 35 deletions

View File

@@ -2,7 +2,6 @@
* @prettier
*
*/
import { Buffer } from "node:buffer"
import { fromJS } from "immutable"
import {
createXMLExample,
@@ -291,6 +290,58 @@ describe("sampleFromSchema", () => {
expect(sampleFromSchema(definition)).toMatch(base64Regex)
})
it("should handle contentSchema defined as type=object", function () {
const definition = fromJS({
type: "string",
contentMediaType: "application/json",
contentSchema: {
type: "object",
properties: {
a: { const: "b" },
},
},
})
expect(sampleFromSchema(definition)).toStrictEqual('{"a":"b"}')
})
it("should handle contentSchema defined as type=string", function () {
const definition = fromJS({
type: "string",
contentMediaType: "text/plain",
contentSchema: {
type: "string",
},
})
expect(sampleFromSchema(definition)).toStrictEqual("string")
})
it("should handle contentSchema defined as type=number", function () {
const definition = fromJS({
type: "string",
contentMediaType: "text/plain",
contentSchema: {
type: "number",
},
})
expect(sampleFromSchema(definition)).toStrictEqual("0")
})
it("should handle contentSchema defined as type=number + contentEncoding", function () {
const definition = fromJS({
type: "string",
contentEncoding: "base16",
contentMediaType: "text/plain",
contentSchema: {
type: "number",
},
})
expect(sampleFromSchema(definition)).toStrictEqual("30")
})
it("should handle type keyword defined as list of types", function () {
const definition = fromJS({ type: ["object", "string"] })
const expected = {}