Allow showing SchemaDefinition as child

This commit is contained in:
Magnus Jensen 2024-04-28 13:15:51 +02:00
parent 31d88a184b
commit 88e7d72d56
2 changed files with 6 additions and 9 deletions

View File

@ -15,6 +15,7 @@ export interface ObjectDescriptionProps {
showReadOnly?: boolean; showReadOnly?: boolean;
showWriteOnly?: boolean; showWriteOnly?: boolean;
showExample?: boolean; showExample?: boolean;
showAsChild?: boolean;
parser: OpenAPIParser; parser: OpenAPIParser;
options: RedocNormalizedOptions; options: RedocNormalizedOptions;
} }
@ -39,15 +40,10 @@ export class SchemaDefinition extends React.PureComponent<ObjectDescriptionProps
private _mediaModel: MediaTypeModel; private _mediaModel: MediaTypeModel;
private get mediaModel() { private get mediaModel() {
const { parser, schemaRef, exampleRef, options } = this.props; const { parser, schemaRef, exampleRef, options, showAsChild } = this.props;
if (!this._mediaModel) { if (!this._mediaModel) {
this._mediaModel = new MediaTypeModel( const info = SchemaDefinition.getMediaType(schemaRef, exampleRef);
parser, this._mediaModel = new MediaTypeModel(parser, 'json', false, info, options, showAsChild);
'json',
false,
SchemaDefinition.getMediaType(schemaRef, exampleRef),
options,
);
} }
return this._mediaModel; return this._mediaModel;

View File

@ -25,10 +25,11 @@ export class MediaTypeModel {
isRequestType: boolean, isRequestType: boolean,
info: OpenAPIMediaType, info: OpenAPIMediaType,
options: RedocNormalizedOptions, options: RedocNormalizedOptions,
showAsChild?: boolean,
) { ) {
this.name = name; this.name = name;
this.isRequestType = isRequestType; this.isRequestType = isRequestType;
this.schema = info.schema && new SchemaModel(parser, info.schema, '', options); this.schema = info.schema && new SchemaModel(parser, info.schema, '', options, showAsChild);
this.onlyRequiredInSamples = options.onlyRequiredInSamples; this.onlyRequiredInSamples = options.onlyRequiredInSamples;
this.generatedPayloadSamplesMaxDepth = options.generatedPayloadSamplesMaxDepth; this.generatedPayloadSamplesMaxDepth = options.generatedPayloadSamplesMaxDepth;
if (info.examples !== undefined) { if (info.examples !== undefined) {