feat(examples): add support for examples keyword (#8908)
This change is specific to JSON Schema 2020-12 and OpenAPI 3.1.0. Refs #8577
This commit is contained in:
@@ -627,98 +627,6 @@ describe("sampleFromSchema", () => {
|
||||
)
|
||||
})
|
||||
|
||||
it("returns object without any $$ref fields at the root schema level", function () {
|
||||
const definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
message: {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
example: {
|
||||
value: {
|
||||
message: "Hello, World!",
|
||||
},
|
||||
$$ref: "https://example.com/#/components/examples/WelcomeExample",
|
||||
},
|
||||
$$ref: "https://example.com/#/components/schemas/Welcome",
|
||||
}
|
||||
|
||||
const expected = {
|
||||
value: {
|
||||
message: "Hello, World!",
|
||||
},
|
||||
}
|
||||
|
||||
expect(sampleFromSchema(definition, { includeWriteOnly: true })).toEqual(
|
||||
expected
|
||||
)
|
||||
})
|
||||
|
||||
it("returns object without any $$ref fields at nested schema levels", function () {
|
||||
const definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
message: {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
example: {
|
||||
a: {
|
||||
value: {
|
||||
message: "Hello, World!",
|
||||
},
|
||||
$$ref: "https://example.com/#/components/examples/WelcomeExample",
|
||||
},
|
||||
},
|
||||
$$ref: "https://example.com/#/components/schemas/Welcome",
|
||||
}
|
||||
|
||||
const expected = {
|
||||
a: {
|
||||
value: {
|
||||
message: "Hello, World!",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expect(sampleFromSchema(definition, { includeWriteOnly: true })).toEqual(
|
||||
expected
|
||||
)
|
||||
})
|
||||
|
||||
it("returns object with any $$ref fields that appear to be user-created", function () {
|
||||
const definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
message: {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
example: {
|
||||
$$ref: {
|
||||
value: {
|
||||
message: "Hello, World!",
|
||||
},
|
||||
$$ref: "https://example.com/#/components/examples/WelcomeExample",
|
||||
},
|
||||
},
|
||||
$$ref: "https://example.com/#/components/schemas/Welcome",
|
||||
}
|
||||
|
||||
const expected = {
|
||||
$$ref: {
|
||||
value: {
|
||||
message: "Hello, World!",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expect(sampleFromSchema(definition, { includeWriteOnly: true })).toEqual(
|
||||
expected
|
||||
)
|
||||
})
|
||||
|
||||
it("returns example value for date-time property", () => {
|
||||
const definition = {
|
||||
type: "string",
|
||||
@@ -1836,7 +1744,7 @@ describe("createXMLExample", function () {
|
||||
|
||||
it("returns example value when provided", function () {
|
||||
const expected =
|
||||
'<?xml version="1.0" encoding="UTF-8"?>\n<newtagname>two</newtagname>'
|
||||
'<?xml version="1.0" encoding="UTF-8"?>\n<newtagname>one</newtagname>'
|
||||
const definition = {
|
||||
type: "string",
|
||||
default: "one",
|
||||
@@ -1850,6 +1758,23 @@ describe("createXMLExample", function () {
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns item from examples value when provided", function () {
|
||||
const expected =
|
||||
'<?xml version="1.0" encoding="UTF-8"?>\n<newtagname>three</newtagname>'
|
||||
const definition = {
|
||||
type: "string",
|
||||
default: "one",
|
||||
example: "two",
|
||||
examples: ["three", "four"],
|
||||
enum: ["two", "one"],
|
||||
xml: {
|
||||
name: "newtagname",
|
||||
},
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("sets first enum if provided", function () {
|
||||
const expected =
|
||||
'<?xml version="1.0" encoding="UTF-8"?>\n<newtagname>one</newtagname>'
|
||||
|
||||
Reference in New Issue
Block a user