This commit is contained in:
Oprysk Viacheslav 2025-03-12 14:39:44 +01:00 committed by GitHub
commit 593f537ad6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -53,7 +53,7 @@ export class SchemaModel {
constraints: string[];
fields?: FieldModel[];
private _fields?: FieldModel[];
items?: SchemaModel;
oneOf?: SchemaModel[];
@ -77,7 +77,7 @@ export class SchemaModel {
* When true forces dereferencing in allOfs even if circular
*/
constructor(
parser: OpenAPIParser,
private parser: OpenAPIParser,
schemaOrRef: Referenced<OpenAPISchema>,
pointer: string,
private options: RedocNormalizedOptions,
@ -113,6 +113,23 @@ export class SchemaModel {
return this.type === type || (isArray(this.type) && this.type.includes(type));
}
get fields(): FieldModel[] | undefined {
if (this.isCircular) {
return undefined;
}
if (!this._fields && this.hasType('object')) {
this._fields = buildFields(
this.parser,
this.schema,
this.pointer,
this.options,
this.refsStack,
);
}
return this._fields;
}
init(parser: OpenAPIParser, isChild: boolean) {
const schema = this.schema;
this.isCircular = !!schema['x-circular-ref'];
@ -192,11 +209,9 @@ export class SchemaModel {
return;
}
if (this.hasType('object')) {
this.fields = buildFields(parser, schema, this.pointer, this.options, this.refsStack);
} else if (this.hasType('array')) {
if (this.hasType('array')) {
if (isArray(schema.items) || isArray(schema.prefixItems)) {
this.fields = buildFields(parser, schema, this.pointer, this.options, this.refsStack);
this._fields = buildFields(parser, schema, this.pointer, this.options, this.refsStack);
} else if (schema.items) {
this.items = new SchemaModel(
parser,