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, getConfigs: PropTypes.func.isRequired, expanded: PropTypes.bool, onToggle: PropTypes.func.isRequired, specSelectors: PropTypes.object.isRequired, name: PropTypes.string, isRef: PropTypes.bool, expandDepth: PropTypes.number, depth: PropTypes.number, specPath: PropTypes.object.isRequired } render(){ let { schema, name, isRef, getComponent, getConfigs, depth, onToggle, expanded, specPath, ...otherProps } = this.props let { specSelectors,expandDepth } = otherProps const { isOAS3 } = specSelectors if(!schema) { return null } const { showExtensions } = getConfigs() 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 = () => { 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 { braceOpen } { !isRef ? null : } { { !description ? null : } { !(properties && properties.size) ? null : properties.entrySeq().map( ([key, value]) => { let isDeprecated = isOAS3() && value.get("deprecated") let isRequired = List.isList(requiredProperties) && requiredProperties.contains(key) let propertyStyle = { verticalAlign: "top", paddingRight: "0.2em" } if ( isRequired ) { propertyStyle.fontWeight = "bold" } return () }).toArray() } { // empty row befor extensions... !showExtensions ? null :   } { !showExtensions ? null : schema.entrySeq().map( ([key, value]) => { if(key.slice(0,2) !== "x-") { return } const normalizedValue = !value ? null : value.toJS ? value.toJS() : value return () }).toArray() } { !additionalProperties || !additionalProperties.size ? null : } { !anyOf ? null : } { !oneOf ? null : } { !not ? null : }
description:
{ key }{ isRequired && * }
{ key } { JSON.stringify(normalizedValue) }
{ "< * >:" }
{ "anyOf ->" } {anyOf.map((schema, k) => { return
})}
{ "oneOf ->" } {oneOf.map((schema, k) => { return
})}
{ "not ->" }
}
{ braceClose }
} }