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