Merge branch 'master' into ft/map-state-to-props-for-components
This commit is contained in:
@@ -4,19 +4,24 @@ import ImPropTypes from "react-immutable-proptypes"
|
||||
|
||||
class OperationLink extends Component {
|
||||
render() {
|
||||
const { link, name } = this.props
|
||||
const { link, name, getComponent } = this.props
|
||||
|
||||
const Markdown = getComponent("Markdown")
|
||||
|
||||
let targetOp = link.get("operationId") || link.get("operationRef")
|
||||
let parameters = link.get("parameters") && link.get("parameters").toJS()
|
||||
let description = link.get("description")
|
||||
|
||||
return <span>
|
||||
<div style={{ padding: "5px 2px" }}>{name}{description ? `: ${description}` : ""}</div>
|
||||
return <div style={{ marginBottom: "1.5em" }}>
|
||||
<div style={{ marginBottom: ".5em" }}>
|
||||
<b><code>{name}</code></b>
|
||||
{ description ? <Markdown source={description}></Markdown> : null }
|
||||
</div>
|
||||
<pre>
|
||||
Operation `{targetOp}`<br /><br />
|
||||
Parameters {padString(0, JSON.stringify(parameters, null, 2)) || "{}"}<br />
|
||||
</pre>
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,6 +35,7 @@ function padString(n, string) {
|
||||
}
|
||||
|
||||
OperationLink.propTypes = {
|
||||
getComponent: PropTypes.func.isRequired,
|
||||
link: ImPropTypes.orderedMap.isRequired,
|
||||
name: PropTypes.String
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@ const RequestBody = ({ requestBody, getComponent, specSelectors, contentType })
|
||||
|
||||
const mediaTypeValue = requestBodyContent.get(contentType)
|
||||
|
||||
const sampleSchema = getSampleSchema(mediaTypeValue.get("schema").toJS(), contentType)
|
||||
const sampleSchema = getSampleSchema(mediaTypeValue.get("schema").toJS(), contentType, {
|
||||
includeWriteOnly: true
|
||||
})
|
||||
|
||||
return <div>
|
||||
{ requestBodyDescription &&
|
||||
|
||||
@@ -3,7 +3,6 @@ import PropTypes from "prop-types"
|
||||
import { OAS3ComponentWrapFactory } from "../helpers"
|
||||
import { Model } from "core/components/model"
|
||||
|
||||
|
||||
class ModelComponent extends Component {
|
||||
static propTypes = {
|
||||
schema: PropTypes.object.isRequired,
|
||||
|
||||
@@ -9,7 +9,7 @@ const primitives = {
|
||||
"number": () => 0,
|
||||
"number_float": () => 0.0,
|
||||
"integer": () => 0,
|
||||
"boolean": (schema) => typeof schema.default === "boolean" ? schema.default : true
|
||||
"boolean": (schema) => typeof schema.default === "boolean" ? schema.default : true
|
||||
}
|
||||
|
||||
const primitive = (schema) => {
|
||||
@@ -27,7 +27,7 @@ const primitive = (schema) => {
|
||||
|
||||
export const sampleFromSchema = (schema, config={}) => {
|
||||
let { type, example, properties, additionalProperties, items } = objectify(schema)
|
||||
let { includeReadOnly } = config
|
||||
let { includeReadOnly, includeWriteOnly } = config
|
||||
|
||||
if(example !== undefined)
|
||||
return example
|
||||
@@ -46,16 +46,20 @@ export const sampleFromSchema = (schema, config={}) => {
|
||||
let props = objectify(properties)
|
||||
let obj = {}
|
||||
for (var name in props) {
|
||||
if ( !props[name].readOnly || includeReadOnly ) {
|
||||
obj[name] = sampleFromSchema(props[name], { includeReadOnly: includeReadOnly })
|
||||
if ( props[name].readOnly && !includeReadOnly ) {
|
||||
continue
|
||||
}
|
||||
if ( props[name].writeOnly && !includeWriteOnly ) {
|
||||
continue
|
||||
}
|
||||
obj[name] = sampleFromSchema(props[name], config)
|
||||
}
|
||||
|
||||
if ( additionalProperties === true ) {
|
||||
obj.additionalProp1 = {}
|
||||
} else if ( additionalProperties ) {
|
||||
let additionalProps = objectify(additionalProperties)
|
||||
let additionalPropVal = sampleFromSchema(additionalProps, { includeReadOnly: includeReadOnly })
|
||||
let additionalPropVal = sampleFromSchema(additionalProps, config)
|
||||
|
||||
for (let i = 1; i < 4; i++) {
|
||||
obj["additionalProp" + i] = additionalPropVal
|
||||
@@ -65,7 +69,7 @@ export const sampleFromSchema = (schema, config={}) => {
|
||||
}
|
||||
|
||||
if(type === "array") {
|
||||
return [ sampleFromSchema(items, { includeReadOnly: includeReadOnly }) ]
|
||||
return [ sampleFromSchema(items, config) ]
|
||||
}
|
||||
|
||||
if(schema["enum"]) {
|
||||
@@ -96,7 +100,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 +181,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