mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-09 06:34:53 +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}
|
schema={field.schema}
|
||||||
skipReadOnly={this.props.skipReadOnly}
|
skipReadOnly={this.props.skipReadOnly}
|
||||||
skipWriteOnly={this.props.skipWriteOnly}
|
skipWriteOnly={this.props.skipWriteOnly}
|
||||||
showTitle={this.props.showTitle}
|
skipObjectTitle={this.props.skipObjectTitle}
|
||||||
/>
|
/>
|
||||||
</InnerPropertiesWrap>
|
</InnerPropertiesWrap>
|
||||||
</PropertyCellWithInner>
|
</PropertyCellWithInner>
|
||||||
|
|
|
@ -60,11 +60,14 @@ export class ObjectSchema extends React.Component<ObjectSchemaProps> {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<ObjectSchemaDetails>
|
<ObjectSchemaDetails>
|
||||||
|
{!this.props.skipObjectTitle && (
|
||||||
<ObjectSchemaTitle>{this.props.schema.title}</ObjectSchemaTitle>
|
<ObjectSchemaTitle>{this.props.schema.title}</ObjectSchemaTitle>
|
||||||
|
)}
|
||||||
|
{!this.props.skipObjectDescription && (
|
||||||
<ObjectSchemaDescription>
|
<ObjectSchemaDescription>
|
||||||
<Markdown dense={true} source={this.props.schema.description} />
|
<Markdown compact={true} source={this.props.schema.description} />
|
||||||
</ObjectSchemaDescription>
|
</ObjectSchemaDescription>
|
||||||
|
)}
|
||||||
</ObjectSchemaDetails>
|
</ObjectSchemaDetails>
|
||||||
|
|
||||||
<PropertiesTable>
|
<PropertiesTable>
|
||||||
|
|
|
@ -15,6 +15,8 @@ import { l } from '../../services/Labels';
|
||||||
export interface SchemaOptions {
|
export interface SchemaOptions {
|
||||||
skipReadOnly?: boolean;
|
skipReadOnly?: boolean;
|
||||||
skipWriteOnly?: boolean;
|
skipWriteOnly?: boolean;
|
||||||
|
skipObjectTitle?: boolean;
|
||||||
|
skipObjectDescription?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SchemaProps extends SchemaOptions {
|
export interface SchemaProps extends SchemaOptions {
|
||||||
|
@ -43,9 +45,7 @@ export class Schema extends React.Component<Partial<SchemaProps>> {
|
||||||
if (discriminatorProp !== undefined) {
|
if (discriminatorProp !== undefined) {
|
||||||
if (!oneOf || !oneOf.length) {
|
if (!oneOf || !oneOf.length) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Looks like you are using discriminator wrong: you don't have any definition inherited from the ${
|
`Looks like you are using discriminator wrong: you don't have any definition inherited from the ${schema.title}`,
|
||||||
schema.title
|
|
||||||
}`,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
|
@ -65,9 +65,9 @@ export class Schema extends React.Component<Partial<SchemaProps>> {
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'object':
|
case 'object':
|
||||||
return <ObjectSchema {...this.props as any} />;
|
return <ObjectSchema {...(this.props as any)} />;
|
||||||
case 'array':
|
case 'array':
|
||||||
return <ArraySchema {...this.props as any} />;
|
return <ArraySchema {...(this.props as any)} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: maybe adjust FieldDetails to accept schema
|
// TODO: maybe adjust FieldDetails to accept schema
|
||||||
|
|
|
@ -14,6 +14,8 @@ export interface ObjectDescriptionProps {
|
||||||
exampleRef?: string;
|
exampleRef?: string;
|
||||||
showReadOnly?: boolean;
|
showReadOnly?: boolean;
|
||||||
showWriteOnly?: boolean;
|
showWriteOnly?: boolean;
|
||||||
|
showObjectTitle?: boolean;
|
||||||
|
showObjectDescription?: boolean;
|
||||||
parser: OpenAPIParser;
|
parser: OpenAPIParser;
|
||||||
options: RedocNormalizedOptions;
|
options: RedocNormalizedOptions;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +55,12 @@ export class SchemaDefinition extends React.PureComponent<ObjectDescriptionProps
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { showReadOnly = true, showWriteOnly = false } = this.props;
|
const {
|
||||||
|
showReadOnly = true,
|
||||||
|
showWriteOnly = false,
|
||||||
|
showObjectTitle = false,
|
||||||
|
showObjectDescription = false,
|
||||||
|
} = this.props;
|
||||||
return (
|
return (
|
||||||
<Section>
|
<Section>
|
||||||
<Row>
|
<Row>
|
||||||
|
@ -61,6 +68,8 @@ export class SchemaDefinition extends React.PureComponent<ObjectDescriptionProps
|
||||||
<Schema
|
<Schema
|
||||||
skipWriteOnly={!showWriteOnly}
|
skipWriteOnly={!showWriteOnly}
|
||||||
skipReadOnly={!showReadOnly}
|
skipReadOnly={!showReadOnly}
|
||||||
|
skipObjectTitle={!showObjectTitle}
|
||||||
|
skipObjectDescription={!showObjectDescription}
|
||||||
schema={this.mediaModel.schema}
|
schema={this.mediaModel.schema}
|
||||||
/>
|
/>
|
||||||
</MiddlePanel>
|
</MiddlePanel>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user