feat(model view): hide applicable readOnly and writeOnly properties (#5832)

This commit is contained in:
blacktemplar
2020-06-15 22:47:26 +02:00
committed by GitHub
parent 59bbe4ff2f
commit f8dd4e68ec
10 changed files with 44 additions and 14 deletions

View File

@@ -15,7 +15,9 @@ export default class ArrayModel extends Component {
required: PropTypes.bool, required: PropTypes.bool,
expandDepth: PropTypes.number, expandDepth: PropTypes.number,
specPath: ImPropTypes.list.isRequired, specPath: ImPropTypes.list.isRequired,
depth: PropTypes.number depth: PropTypes.number,
includeReadOnly: PropTypes.bool,
includeWriteOnly: PropTypes.bool,
} }
render(){ render(){

View File

@@ -11,6 +11,8 @@ export default class ModelExample extends React.Component {
isExecute: PropTypes.bool, isExecute: PropTypes.bool,
getConfigs: PropTypes.func.isRequired, getConfigs: PropTypes.func.isRequired,
specPath: ImPropTypes.list.isRequired, specPath: ImPropTypes.list.isRequired,
includeReadOnly: PropTypes.bool,
includeWriteOnly: PropTypes.bool,
} }
constructor(props, context) { constructor(props, context) {
@@ -52,7 +54,7 @@ export default class ModelExample extends React.Component {
} }
render() { render() {
let { getComponent, specSelectors, schema, example, isExecute, getConfigs, specPath } = this.props let { getComponent, specSelectors, schema, example, isExecute, getConfigs, specPath, includeReadOnly, includeWriteOnly } = this.props
let { defaultModelExpandDepth } = getConfigs() let { defaultModelExpandDepth } = getConfigs()
const ModelWrapper = getComponent("ModelWrapper") const ModelWrapper = getComponent("ModelWrapper")
const HighlightCode = getComponent("highlightCode") const HighlightCode = getComponent("highlightCode")
@@ -84,7 +86,9 @@ export default class ModelExample extends React.Component {
getConfigs={ getConfigs } getConfigs={ getConfigs }
specSelectors={ specSelectors } specSelectors={ specSelectors }
expandDepth={ defaultModelExpandDepth } expandDepth={ defaultModelExpandDepth }
specPath={specPath} /> specPath={specPath}
includeReadOnly = {includeReadOnly}
includeWriteOnly = {includeWriteOnly}/>
} }

View File

@@ -15,7 +15,9 @@ export default class ModelWrapper extends Component {
specSelectors: PropTypes.object.isRequired, specSelectors: PropTypes.object.isRequired,
expandDepth: PropTypes.number, expandDepth: PropTypes.number,
layoutActions: PropTypes.object, layoutActions: PropTypes.object,
layoutSelectors: PropTypes.object.isRequired layoutSelectors: PropTypes.object.isRequired,
includeReadOnly: PropTypes.bool,
includeWriteOnly: PropTypes.bool,
} }
getSchemaBasePath = () => { getSchemaBasePath = () => {

View File

@@ -16,6 +16,8 @@ export default class Model extends ImmutablePureComponent {
expandDepth: PropTypes.number, expandDepth: PropTypes.number,
depth: PropTypes.number, depth: PropTypes.number,
specPath: ImPropTypes.list.isRequired, specPath: ImPropTypes.list.isRequired,
includeReadOnly: PropTypes.bool,
includeWriteOnly: PropTypes.bool,
} }
getModelName =( ref )=> { getModelName =( ref )=> {
@@ -34,7 +36,8 @@ export default class Model extends ImmutablePureComponent {
} }
render () { render () {
let { getComponent, getConfigs, specSelectors, schema, required, name, isRef, specPath, displayName } = this.props let { getComponent, getConfigs, specSelectors, schema, required, name, isRef, specPath, displayName,
includeReadOnly, includeWriteOnly} = this.props
const ObjectModel = getComponent("ObjectModel") const ObjectModel = getComponent("ObjectModel")
const ArrayModel = getComponent("ArrayModel") const ArrayModel = getComponent("ArrayModel")
const PrimitiveModel = getComponent("PrimitiveModel") const PrimitiveModel = getComponent("PrimitiveModel")
@@ -70,7 +73,9 @@ export default class Model extends ImmutablePureComponent {
schema={ schema } schema={ schema }
name={ name } name={ name }
deprecated={deprecated} deprecated={deprecated}
isRef={ isRef } /> isRef={ isRef }
includeReadOnly = {includeReadOnly}
includeWriteOnly = {includeWriteOnly}/>
case "array": case "array":
return <ArrayModel return <ArrayModel
className="array" { ...this.props } className="array" { ...this.props }
@@ -78,7 +83,9 @@ export default class Model extends ImmutablePureComponent {
schema={ schema } schema={ schema }
name={ name } name={ name }
deprecated={deprecated} deprecated={deprecated}
required={ required } /> required={ required }
includeReadOnly = {includeReadOnly}
includeWriteOnly = {includeWriteOnly}/>
case "string": case "string":
case "number": case "number":
case "integer": case "integer":

View File

@@ -90,7 +90,9 @@ export default class Models extends Component {
specSelectors={ specSelectors } specSelectors={ specSelectors }
getConfigs = {getConfigs} getConfigs = {getConfigs}
layoutSelectors = {layoutSelectors} layoutSelectors = {layoutSelectors}
layoutActions = {layoutActions}/> layoutActions = {layoutActions}
includeReadOnly = {true}
includeWriteOnly = {true}/>
const title = <span className="model-box"> const title = <span className="model-box">
<span className="model model-title"> <span className="model model-title">

View File

@@ -19,12 +19,14 @@ export default class ObjectModel extends Component {
isRef: PropTypes.bool, isRef: PropTypes.bool,
expandDepth: PropTypes.number, expandDepth: PropTypes.number,
depth: PropTypes.number, depth: PropTypes.number,
specPath: ImPropTypes.list.isRequired specPath: ImPropTypes.list.isRequired,
includeReadOnly: PropTypes.bool,
includeWriteOnly: PropTypes.bool,
} }
render(){ render(){
let { schema, name, displayName, isRef, getComponent, getConfigs, depth, onToggle, expanded, specPath, ...otherProps } = this.props let { schema, name, displayName, isRef, getComponent, getConfigs, depth, onToggle, expanded, specPath, ...otherProps } = this.props
let { specSelectors,expandDepth } = otherProps let { specSelectors,expandDepth, includeReadOnly, includeWriteOnly} = otherProps
const { isOAS3 } = specSelectors const { isOAS3 } = specSelectors
if(!schema) { if(!schema) {
@@ -87,7 +89,12 @@ export default class ObjectModel extends Component {
</tr> </tr>
} }
{ {
!(properties && properties.size) ? null : properties.entrySeq().map( !(properties && properties.size) ? null : properties.entrySeq().filter(
([, value]) => {
return (!value.get("readOnly") || includeReadOnly) &&
(!value.get("writeOnly") || includeWriteOnly)
}
).map(
([key, value]) => { ([key, value]) => {
let isDeprecated = isOAS3() && value.get("deprecated") let isDeprecated = isOAS3() && value.get("deprecated")
let isRequired = List.isList(requiredProperties) && requiredProperties.contains(key) let isRequired = List.isList(requiredProperties) && requiredProperties.contains(key)

View File

@@ -105,6 +105,7 @@ export default class ParameterRow extends Component {
// getSampleSchema could return null // getSampleSchema could return null
const generatedSampleValue = schema ? getSampleSchema(schema.toJS(), parameterMediaType, { const generatedSampleValue = schema ? getSampleSchema(schema.toJS(), parameterMediaType, {
includeWriteOnly: true includeWriteOnly: true
}) : null }) : null
@@ -331,7 +332,8 @@ export default class ParameterRow extends Component {
isExecute={ isExecute } isExecute={ isExecute }
specSelectors={ specSelectors } specSelectors={ specSelectors }
schema={ schema } schema={ schema }
example={ bodyParam }/> example={ bodyParam }
includeWriteOnly={ true }/>
: null : null
} }

View File

@@ -218,7 +218,8 @@ export default class Response extends React.Component {
getConfigs={ getConfigs } getConfigs={ getConfigs }
specSelectors={ specSelectors } specSelectors={ specSelectors }
schema={ fromJSOrdered(schema) } schema={ fromJSOrdered(schema) }
example={ example }/> example={ example }
includeReadOnly={ true }/>
) : null } ) : null }
{ isOAS3 && examplesForMediaType ? ( { isOAS3 && examplesForMediaType ? (

View File

@@ -237,6 +237,7 @@ const RequestBody = ({
)} )}
/> />
} }
includeWriteOnly={true}
/> />
) )
} }

View File

@@ -10,7 +10,9 @@ class ModelComponent extends Component {
getComponent: PropTypes.func.isRequired, getComponent: PropTypes.func.isRequired,
getConfigs: PropTypes.func.isRequired, getConfigs: PropTypes.func.isRequired,
specSelectors: PropTypes.object.isRequired, specSelectors: PropTypes.object.isRequired,
expandDepth: PropTypes.number expandDepth: PropTypes.number,
includeReadOnly: PropTypes.bool,
includeWriteOnly: PropTypes.bool,
} }
render(){ render(){