improvement: omit deprecated fields in examples (via #4758)

This commit is contained in:
Tim Macfarlane
2018-08-20 22:11:50 +01:00
committed by kyle
parent 98fdb3e43c
commit 9a9cfdf101
2 changed files with 27 additions and 0 deletions

View File

@@ -52,6 +52,9 @@ export const sampleFromSchema = (schema, config={}) => {
let props = objectify(properties)
let obj = {}
for (var name in props) {
if ( props[name] && props[name].deprecated ) {
continue
}
if ( props[name] && props[name].readOnly && !includeReadOnly ) {
continue
}

View File

@@ -79,6 +79,30 @@ describe("sampleFromSchema", function() {
expect(sampleFromSchema(definition, { includeReadOnly: true })).toEqual(expected)
})
it("returns object without deprecated fields for parameter", function () {
var definition = {
type: "object",
properties: {
id: {
type: "integer"
},
deprecatedProperty: {
deprecated: true,
type: "string"
}
},
xml: {
name: "animals"
}
}
var expected = {
id: 0
}
expect(sampleFromSchema(definition)).toEqual(expected)
})
it("returns object without writeonly fields for parameter", function () {
var definition = {
type: "object",