Compare commits

...
Author SHA1 Message Date
Kyle Shockey 8875bd812b fix linter 2018-07-07 02:26:20 -05:00
Kyle Shockey 7fe9bcc195 fix: don't stringify non-object sample values 2018-07-07 02:12:47 -05:00
3 changed files with 31 additions and 2 deletions
+3 -1
View File
@@ -628,7 +628,9 @@ export const getSampleSchema = (schema, contentType="", config={}) => {
return memoizedCreateXMLExample(schema, config)
}
return JSON.stringify(memoizedSampleFromSchema(schema, config), null, 2)
const res = memoizedSampleFromSchema(schema, config)
return typeof res === "object" ? JSON.stringify(res, null, 2) : res
}
export const parseSearch = () => {
+1
View File
@@ -3,3 +3,4 @@ env:
rules:
"react/prop-types": 1 # bah humbug
"no-unused-vars": 1 # unused vars in tests can be useful for indicating a full signature
"no-global-assign": 1
+27 -1
View File
@@ -24,7 +24,8 @@ import {
getCommonExtensions,
sanitizeUrl,
extractFileNameFromContentDispositionHeader,
deeplyStripKey
deeplyStripKey,
getSampleSchema
} from "core/utils"
import win from "core/window"
@@ -1186,5 +1187,30 @@ describe("utils", function() {
expect(sanitizeUrl({})).toEqual("")
})
})
describe("getSampleSchema", function() {
const oriDate = Date
before(function() {
Date = function () {
this.toISOString = function () {
return "2018-07-07T07:07:05.189Z"
}
}
})
after(function() {
Date = oriDate
})
it("should not unnecessarily stringify non-object values", function() {
// Given
const res = getSampleSchema({
type: "string",
format: "date-time"
})
// Then
expect(res).toEqual(new Date().toISOString())
})
})
})