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:
Mahtis Michel
2020-09-29 22:40:47 +02:00
committed by GitHub
parent 688ac909ea
commit ad630cc3e0
2 changed files with 65 additions and 20 deletions

View File

@@ -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", () => {