Add writeOnly logic
This commit is contained in:
@@ -96,7 +96,7 @@ export const inferSchema = (thing) => {
|
||||
export const sampleXmlFromSchema = (schema, config={}) => {
|
||||
let objectifySchema = objectify(schema)
|
||||
let { type, properties, additionalProperties, items, example } = objectifySchema
|
||||
let { includeReadOnly } = config
|
||||
let { includeReadOnly, includeWriteOnly } = config
|
||||
let defaultValue = objectifySchema.default
|
||||
let res = {}
|
||||
let _attr = {}
|
||||
@@ -177,27 +177,32 @@ export const sampleXmlFromSchema = (schema, config={}) => {
|
||||
example = example || {}
|
||||
|
||||
for (let propName in props) {
|
||||
if ( !props[propName].readOnly || includeReadOnly ) {
|
||||
props[propName].xml = props[propName].xml || {}
|
||||
if ( props[propName].readOnly && !includeReadOnly ) {
|
||||
continue
|
||||
}
|
||||
if ( props[propName].writeOnly && !includeWriteOnly ) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (props[propName].xml.attribute) {
|
||||
let enumAttrVal = Array.isArray(props[propName].enum) && props[propName].enum[0]
|
||||
let attrExample = props[propName].example
|
||||
let attrDefault = props[propName].default
|
||||
_attr[props[propName].xml.name || propName] = attrExample!== undefined && attrExample
|
||||
|| example[propName] !== undefined && example[propName] || attrDefault !== undefined && attrDefault
|
||||
|| enumAttrVal || primitive(props[propName])
|
||||
props[propName].xml = props[propName].xml || {}
|
||||
|
||||
if (props[propName].xml.attribute) {
|
||||
let enumAttrVal = Array.isArray(props[propName].enum) && props[propName].enum[0]
|
||||
let attrExample = props[propName].example
|
||||
let attrDefault = props[propName].default
|
||||
_attr[props[propName].xml.name || propName] = attrExample!== undefined && attrExample
|
||||
|| example[propName] !== undefined && example[propName] || attrDefault !== undefined && attrDefault
|
||||
|| enumAttrVal || primitive(props[propName])
|
||||
} else {
|
||||
props[propName].xml.name = props[propName].xml.name || propName
|
||||
props[propName].example = props[propName].example !== undefined ? props[propName].example : example[propName]
|
||||
let t = sampleXmlFromSchema(props[propName])
|
||||
if (Array.isArray(t)) {
|
||||
res[displayName] = res[displayName].concat(t)
|
||||
} else {
|
||||
props[propName].xml.name = props[propName].xml.name || propName
|
||||
props[propName].example = props[propName].example !== undefined ? props[propName].example : example[propName]
|
||||
let t = sampleXmlFromSchema(props[propName])
|
||||
if (Array.isArray(t)) {
|
||||
res[displayName] = res[displayName].concat(t)
|
||||
} else {
|
||||
res[displayName].push(t)
|
||||
}
|
||||
|
||||
res[displayName].push(t)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user