fix: string samples should also be json stringified. (#6412)

fixes #6120
This commit is contained in:
Mahtis Michel
2020-09-21 21:16:26 +02:00
committed by GitHub
parent 52360a0612
commit 821ba887a6
2 changed files with 15 additions and 3 deletions

View File

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

View File

@@ -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)
}) })
}) })