fix: sample schema should stringify string values for content-type: text/json (#6431)
* reverts #6412 which stringified string value if content-type: text/plain * enable stringify string values matching `/json/` and allowList of `shouldStringifyTypes` ("string")
This commit is contained in:
@@ -1494,7 +1494,18 @@ describe("utils", () => {
|
||||
Date = oriDate
|
||||
})
|
||||
|
||||
it("should stringify string values", () => {
|
||||
it("should stringify string values if json content-type", () => {
|
||||
// Given
|
||||
const res = getSampleSchema({
|
||||
type: "string",
|
||||
format: "date-time"
|
||||
}, "text/json")
|
||||
|
||||
// Then
|
||||
expect(res).toEqual(JSON.stringify(new Date().toISOString()))
|
||||
})
|
||||
|
||||
it("should not unnecessarily stringify string values for other content-types", () => {
|
||||
// Given
|
||||
const res = getSampleSchema({
|
||||
type: "string",
|
||||
@@ -1502,7 +1513,7 @@ describe("utils", () => {
|
||||
})
|
||||
|
||||
// Then
|
||||
expect(res).toEqual(JSON.stringify(new Date().toISOString()))
|
||||
expect(res).toEqual(new Date().toISOString())
|
||||
})
|
||||
|
||||
it("should not unnecessarily stringify non-object values", () => {
|
||||
@@ -1514,6 +1525,16 @@ describe("utils", () => {
|
||||
// Then
|
||||
expect(res).toEqual(0)
|
||||
})
|
||||
|
||||
it("should not unnecessarily stringify non-object values if content-type is json", () => {
|
||||
// Given
|
||||
const res = getSampleSchema({
|
||||
type: "number"
|
||||
}, "application/json")
|
||||
|
||||
// Then
|
||||
expect(res).toEqual(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("paramToIdentifier", () => {
|
||||
|
||||
Reference in New Issue
Block a user