fix: string samples should also be json stringified. (#6412)
fixes #6120
This commit is contained in:
@@ -560,7 +560,9 @@ export const getSampleSchema = (schema, contentType="", config={}) => {
|
|||||||
|
|
||||||
const res = memoizedSampleFromSchema(schema, config)
|
const res = memoizedSampleFromSchema(schema, config)
|
||||||
|
|
||||||
return typeof res === "object" ? JSON.stringify(res, null, 2) : res
|
return typeof res === "object" || typeof res === "string"
|
||||||
|
? JSON.stringify(res, null, 2)
|
||||||
|
: res
|
||||||
}
|
}
|
||||||
|
|
||||||
export const parseSearch = () => {
|
export const parseSearch = () => {
|
||||||
|
|||||||
@@ -1494,7 +1494,7 @@ describe("utils", () => {
|
|||||||
Date = oriDate
|
Date = oriDate
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should not unnecessarily stringify non-object values", () => {
|
it("should stringify string values", () => {
|
||||||
// Given
|
// Given
|
||||||
const res = getSampleSchema({
|
const res = getSampleSchema({
|
||||||
type: "string",
|
type: "string",
|
||||||
@@ -1502,7 +1502,17 @@ describe("utils", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
expect(res).toEqual(new Date().toISOString())
|
expect(res).toEqual(JSON.stringify(new Date().toISOString()))
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should not unnecessarily stringify non-object values", () => {
|
||||||
|
// Given
|
||||||
|
const res = getSampleSchema({
|
||||||
|
type: "number"
|
||||||
|
})
|
||||||
|
|
||||||
|
// Then
|
||||||
|
expect(res).toEqual(0)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user