mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-26 18:43:43 +03:00
fix: false-positive recursive detection with allOf at the same level
This commit is contained in:
parent
4649683785
commit
faa74d6002
|
@ -44,6 +44,7 @@ class RefCounter {
|
||||||
export class OpenAPIParser {
|
export class OpenAPIParser {
|
||||||
specUrl?: string;
|
specUrl?: string;
|
||||||
spec: OpenAPISpec;
|
spec: OpenAPISpec;
|
||||||
|
mergeRefs: Set<string>;
|
||||||
|
|
||||||
private _refCounter: RefCounter = new RefCounter();
|
private _refCounter: RefCounter = new RefCounter();
|
||||||
|
|
||||||
|
@ -57,6 +58,8 @@ export class OpenAPIParser {
|
||||||
|
|
||||||
this.spec = spec;
|
this.spec = spec;
|
||||||
|
|
||||||
|
this.mergeRefs = new Set();
|
||||||
|
|
||||||
const href = IS_BROWSER ? window.location.href : '';
|
const href = IS_BROWSER ? window.location.href : '';
|
||||||
if (typeof specUrl === 'string') {
|
if (typeof specUrl === 'string') {
|
||||||
this.specUrl = urlResolve(href, specUrl);
|
this.specUrl = urlResolve(href, specUrl);
|
||||||
|
@ -183,7 +186,12 @@ export class OpenAPIParser {
|
||||||
schema: OpenAPISchema,
|
schema: OpenAPISchema,
|
||||||
$ref?: string,
|
$ref?: string,
|
||||||
forceCircular: boolean = false,
|
forceCircular: boolean = false,
|
||||||
|
used$Refs = new Set<string>(),
|
||||||
): MergedOpenAPISchema {
|
): MergedOpenAPISchema {
|
||||||
|
if ($ref) {
|
||||||
|
used$Refs.add($ref);
|
||||||
|
}
|
||||||
|
|
||||||
schema = this.hoistOneOfs(schema);
|
schema = this.hoistOneOfs(schema);
|
||||||
|
|
||||||
if (schema.allOf === undefined) {
|
if (schema.allOf === undefined) {
|
||||||
|
@ -205,16 +213,25 @@ export class OpenAPIParser {
|
||||||
receiver.items = { ...receiver.items };
|
receiver.items = { ...receiver.items };
|
||||||
}
|
}
|
||||||
|
|
||||||
const allOfSchemas = schema.allOf.map(subSchema => {
|
const allOfSchemas = schema.allOf
|
||||||
|
.map(subSchema => {
|
||||||
|
if (subSchema && subSchema.$ref && used$Refs.has(subSchema.$ref)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const resolved = this.deref(subSchema, forceCircular);
|
const resolved = this.deref(subSchema, forceCircular);
|
||||||
const subRef = subSchema.$ref || undefined;
|
const subRef = subSchema.$ref || undefined;
|
||||||
const subMerged = this.mergeAllOf(resolved, subRef, forceCircular);
|
const subMerged = this.mergeAllOf(resolved, subRef, forceCircular, used$Refs);
|
||||||
receiver.parentRefs!.push(...(subMerged.parentRefs || []));
|
receiver.parentRefs!.push(...(subMerged.parentRefs || []));
|
||||||
return {
|
return {
|
||||||
$ref: subRef,
|
$ref: subRef,
|
||||||
schema: subMerged,
|
schema: subMerged,
|
||||||
};
|
};
|
||||||
});
|
})
|
||||||
|
.filter(child => child !== undefined) as Array<{
|
||||||
|
$ref: string | undefined;
|
||||||
|
schema: MergedOpenAPISchema;
|
||||||
|
}>;
|
||||||
|
|
||||||
for (const { $ref: subSchemaRef, schema: subSchema } of allOfSchemas) {
|
for (const { $ref: subSchemaRef, schema: subSchema } of allOfSchemas) {
|
||||||
if (
|
if (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user