mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-09 14:44:51 +03:00
Update schema render to optionally render title and description
This commit is contained in:
parent
108bb01f27
commit
67be0580ca
|
@ -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>
|
||||
|
|
|
@ -60,11 +60,14 @@ export class ObjectSchema extends React.Component<ObjectSchemaProps> {
|
|||
return (
|
||||
<div>
|
||||
<ObjectSchemaDetails>
|
||||
{!this.props.skipObjectTitle && (
|
||||
<ObjectSchemaTitle>{this.props.schema.title}</ObjectSchemaTitle>
|
||||
|
||||
)}
|
||||
{!this.props.skipObjectDescription && (
|
||||
<ObjectSchemaDescription>
|
||||
<Markdown dense={true} source={this.props.schema.description} />
|
||||
<Markdown compact={true} source={this.props.schema.description} />
|
||||
</ObjectSchemaDescription>
|
||||
)}
|
||||
</ObjectSchemaDetails>
|
||||
|
||||
<PropertiesTable>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue
Block a user