Update schema render to optionally render title and description

This commit is contained in:
Steven Nguyen 2019-09-09 11:27:03 -07:00
parent 108bb01f27
commit 67be0580ca
4 changed files with 24 additions and 12 deletions

View File

@ -73,7 +73,7 @@ export class Field extends React.Component<FieldProps> {
schema={field.schema}
skipReadOnly={this.props.skipReadOnly}
skipWriteOnly={this.props.skipWriteOnly}
showTitle={this.props.showTitle}
skipObjectTitle={this.props.skipObjectTitle}
/>
</InnerPropertiesWrap>
</PropertyCellWithInner>

View File

@ -60,11 +60,14 @@ export class ObjectSchema extends React.Component<ObjectSchemaProps> {
return (
<div>
<ObjectSchemaDetails>
<ObjectSchemaTitle>{this.props.schema.title}</ObjectSchemaTitle>
<ObjectSchemaDescription>
<Markdown dense={true} source={this.props.schema.description} />
</ObjectSchemaDescription>
{!this.props.skipObjectTitle && (
<ObjectSchemaTitle>{this.props.schema.title}</ObjectSchemaTitle>
)}
{!this.props.skipObjectDescription && (
<ObjectSchemaDescription>
<Markdown compact={true} source={this.props.schema.description} />
</ObjectSchemaDescription>
)}
</ObjectSchemaDetails>
<PropertiesTable>

View File

@ -15,6 +15,8 @@ import { l } from '../../services/Labels';
export interface SchemaOptions {
skipReadOnly?: boolean;
skipWriteOnly?: boolean;
skipObjectTitle?: boolean;
skipObjectDescription?: boolean;
}
export interface SchemaProps extends SchemaOptions {
@ -43,9 +45,7 @@ export class Schema extends React.Component<Partial<SchemaProps>> {
if (discriminatorProp !== undefined) {
if (!oneOf || !oneOf.length) {
throw new Error(
`Looks like you are using discriminator wrong: you don't have any definition inherited from the ${
schema.title
}`,
`Looks like you are using discriminator wrong: you don't have any definition inherited from the ${schema.title}`,
);
}
return (
@ -65,9 +65,9 @@ export class Schema extends React.Component<Partial<SchemaProps>> {
switch (type) {
case 'object':
return <ObjectSchema {...this.props as any} />;
return <ObjectSchema {...(this.props as any)} />;
case 'array':
return <ArraySchema {...this.props as any} />;
return <ArraySchema {...(this.props as any)} />;
}
// TODO: maybe adjust FieldDetails to accept schema

View File

@ -14,6 +14,8 @@ export interface ObjectDescriptionProps {
exampleRef?: string;
showReadOnly?: boolean;
showWriteOnly?: boolean;
showObjectTitle?: boolean;
showObjectDescription?: boolean;
parser: OpenAPIParser;
options: RedocNormalizedOptions;
}
@ -53,7 +55,12 @@ export class SchemaDefinition extends React.PureComponent<ObjectDescriptionProps
}
render() {
const { showReadOnly = true, showWriteOnly = false } = this.props;
const {
showReadOnly = true,
showWriteOnly = false,
showObjectTitle = false,
showObjectDescription = false,
} = this.props;
return (
<Section>
<Row>
@ -61,6 +68,8 @@ export class SchemaDefinition extends React.PureComponent<ObjectDescriptionProps
<Schema
skipWriteOnly={!showWriteOnly}
skipReadOnly={!showReadOnly}
skipObjectTitle={!showObjectTitle}
skipObjectDescription={!showObjectDescription}
schema={this.mediaModel.schema}
/>
</MiddlePanel>