Переглянути джерело

fix(sample-gen): respect null values in examples (via #4679)

* improvement: re-enable and improve Models jump-to-path

* fix(sample-gen): respect null values in examples
bubble
kyle 6 роки тому
committed by GitHub
джерело
коміт
9d02a7d8ad
Не вдалося знайти GPG ключ що відповідає даному підпису Ідентифікатор GPG ключа: 4AEE18F83AFDEB23
3 змінених файлів з 42 додано та 1 видалено
  1. +1
    -0
      src/core/plugins/samples/fn.js
  2. +1
    -1
      src/core/utils.js
  3. +40
    -0
      test/core/plugins/samples/fn.js

+ 1
- 0
src/core/plugins/samples/fn.js Переглянути файл

@@ -29,6 +29,7 @@ export const sampleFromSchema = (schema, config={}) => {
let { type, example, properties, additionalProperties, items } = objectify(schema)
let { includeReadOnly, includeWriteOnly } = config


if(example !== undefined) {
return deeplyStripKey(example, "$$ref", (val) => {
// do a couple of quick sanity tests to ensure the value


+ 1
- 1
src/core/utils.js Переглянути файл

@@ -742,7 +742,7 @@ export const getCommonExtensions = (defObj) => defObj.filter((v, k) => /^pattern
// `predicate` can be used to discriminate the stripping further,
// by preserving the key's place in the object based on its value.
export function deeplyStripKey(input, keyToStrip, predicate = () => true) {
if(typeof input !== "object" || Array.isArray(input) || !keyToStrip) {
if(typeof input !== "object" || Array.isArray(input) || input === null || !keyToStrip) {
return input
}



+ 40
- 0
test/core/plugins/samples/fn.js Переглянути файл

@@ -379,6 +379,46 @@ describe("sampleFromSchema", function() {

expect(sampleFromSchema(definition)).toEqual(expected)
})

it("returns null for a null example", function() {
var definition = {
"type": "object",
"properties": {
"foo": {
"type": "string",
"nullable": true,
"example": null
}
}
}

var expected = {
foo: null
}

expect(sampleFromSchema(definition)).toEqual(expected)
})

it("returns null for a null object-level example", function() {
var definition = {
"type": "object",
"properties": {
"foo": {
"type": "string",
"nullable": true
}
},
"example": {
"foo": null
}
}

var expected = {
foo: null
}

expect(sampleFromSchema(definition)).toEqual(expected)
})
})
})



Завантаження…
Відмінити
Зберегти