import React, { Component, } from "react" import PropTypes from "prop-types" import { List } from "immutable" const braceOpen = "{" const braceClose = "}" export default class ObjectModel extends Component { static propTypes = { schema: PropTypes.object.isRequired, getComponent: PropTypes.func.isRequired, specSelectors: PropTypes.object.isRequired, name: PropTypes.string, isRef: PropTypes.bool, expandDepth: PropTypes.number, depth: PropTypes.number } render(){ let { schema, name, isRef, getComponent, depth, expandDepth, ...otherProps } = this.props let { specSelectors } = otherProps let { isOAS3 } = specSelectors if(!schema) { return null } let description = schema.get("description") let properties = schema.get("properties") let additionalProperties = schema.get("additionalProperties") let title = schema.get("title") || name let requiredProperties = schema.get("required") const JumpToPath = getComponent("JumpToPath", true) const Markdown = getComponent("Markdown") const Model = getComponent("Model") const ModelCollapse = getComponent("ModelCollapse") const JumpToPathSection = ({ name }) => { const path = isOAS3 && isOAS3() ? `components.schemas.${name}` : `definitions.${name}` return } const collapsedContent = ( { braceOpen }...{ braceClose } { isRef ? : "" } ) const anyOf = specSelectors.isOAS3() ? schema.get("anyOf") : null const oneOf = specSelectors.isOAS3() ? schema.get("oneOf") : null const not = specSelectors.isOAS3() ? schema.get("not") : null const titleEl = title && { isRef && schema.get("$$ref") && { schema.get("$$ref") } } { title } return expandDepth } collapsedContent={ collapsedContent }> { braceOpen } { !isRef ? null : } { { !description ? null : } { !(properties && properties.size) ? null : properties.entrySeq().map( ([key, value]) => { let isRequired = List.isList(requiredProperties) && requiredProperties.contains(key) let propertyStyle = { verticalAlign: "top", paddingRight: "0.2em" } if ( isRequired ) { propertyStyle.fontWeight = "bold" } return () }).toArray() } { !additionalProperties || !additionalProperties.size ? null : } { !anyOf ? null : } { !oneOf ? null : } { !not ? null : }
description:
{ key }{ isRequired && * }
{ "< * >:" }
{ "anyOf ->" } {anyOf.map((schema, k) => { return
})}
{ "oneOf ->" } {oneOf.map((schema, k) => { return
})}
{ "not ->" } {not.map((schema, k) => { return
})}
}
{ braceClose }
} }