fix(sample-gen): case yaml parsed example is number but string schema (#6872)

This commit is contained in:
Mahtis Michel
2021-01-28 18:04:15 +01:00
committed by GitHub
parent 265bdc07b7
commit 5b2ad68f50
2 changed files with 41 additions and 1 deletions

View File

@@ -1582,6 +1582,42 @@ describe("utils", () => {
expect(actual.test).toEqual(123)
})
it("should handle number example with string schema as string", () => {
// Given
const expected = 123
const res = getSampleSchema({
type: "string",
}, "text/json", {}, expected)
// Then
const actual = JSON.parse(res)
expect(actual).toEqual("123")
})
it("should handle number literal example with string schema as string", () => {
// Given
const expected = "123"
const res = getSampleSchema({
type: "string",
}, "text/json", {}, expected)
// Then
const actual = JSON.parse(res)
expect(actual).toEqual("123")
})
it("should handle number literal example with number schema as number", () => {
// Given
const expected = "123"
const res = getSampleSchema({
type: "number",
}, "text/json", {}, expected)
// Then
const actual = JSON.parse(res)
expect(actual).toEqual(123)
})
it("should return yaml example if yaml is contained in the content-type", () => {
const res = getSampleSchema({
type: "object",