mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-11 03:16:48 +03:00
fix: allOf and deref exit not only named refs
This commit is contained in:
parent
14f8408e8d
commit
435cccd72f
|
@ -9,7 +9,7 @@ import { COMPONENT_REGEXP, buildComponentComment } from './MarkdownRenderer';
|
|||
import { RedocNormalizedOptions } from './RedocNormalizedOptions';
|
||||
import { appendToMdHeading } from '../utils/index';
|
||||
|
||||
export type MergedOpenAPISchema = OpenAPISchema & { namedParents?: string[] };
|
||||
export type MergedOpenAPISchema = OpenAPISchema & { parentRefs?: string[] };
|
||||
|
||||
/**
|
||||
* Helper class to keep track of visited references to avoid
|
||||
|
@ -166,7 +166,7 @@ export class OpenAPIParser {
|
|||
*/
|
||||
mergeAllOf(
|
||||
schema: OpenAPISchema,
|
||||
$ref: string,
|
||||
$ref?: string,
|
||||
forceCircular: boolean = false,
|
||||
): MergedOpenAPISchema {
|
||||
if (schema.allOf === undefined) {
|
||||
|
@ -176,14 +176,14 @@ export class OpenAPIParser {
|
|||
let receiver: MergedOpenAPISchema = {
|
||||
...schema,
|
||||
allOf: undefined,
|
||||
namedParents: [],
|
||||
parentRefs: [],
|
||||
};
|
||||
|
||||
const allOfSchemas = schema.allOf.map((subSchema, idx) => {
|
||||
const allOfSchemas = schema.allOf.map(subSchema => {
|
||||
const resolved = this.deref(subSchema, forceCircular);
|
||||
const subRef = subSchema.$ref || $ref + '/allOf/' + idx;
|
||||
const subRef = subSchema.$ref || undefined;
|
||||
const subMerged = this.mergeAllOf(resolved, subRef, forceCircular);
|
||||
receiver.namedParents!.push(...(subMerged.namedParents || []));
|
||||
receiver.parentRefs!.push(...(subMerged.parentRefs || []));
|
||||
return {
|
||||
$ref: subRef,
|
||||
schema: subMerged,
|
||||
|
@ -219,9 +219,9 @@ export class OpenAPIParser {
|
|||
receiver.required = (receiver.required || []).concat(subSchema.required);
|
||||
}
|
||||
|
||||
if (isNamedDefinition(subSchemaRef)) {
|
||||
receiver.namedParents!.push(subSchemaRef);
|
||||
if (receiver.title === undefined) {
|
||||
if (subSchemaRef) {
|
||||
receiver.parentRefs!.push(subSchemaRef);
|
||||
if (receiver.title === undefined && isNamedDefinition(subSchemaRef)) {
|
||||
receiver.title = JsonPointer.baseName(subSchemaRef);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ export class SchemaModel {
|
|||
|
||||
parser.exitRef(schemaOrRef);
|
||||
|
||||
for (let $ref of this.schema.namedParents || []) {
|
||||
for (let $ref of this.schema.parentRefs || []) {
|
||||
// exit all the refs visited during allOf traverse
|
||||
parser.exitRef({ $ref });
|
||||
}
|
||||
|
|
|
@ -113,8 +113,8 @@ export function langFromMime(contentType: string): string {
|
|||
return 'clike';
|
||||
}
|
||||
|
||||
export function isNamedDefinition(pointer: string): boolean {
|
||||
return /^#\/components\/schemas\/[^\/]+$/.test(pointer);
|
||||
export function isNamedDefinition(pointer?: string): boolean {
|
||||
return /^#\/components\/schemas\/[^\/]+$/.test(pointer || '');
|
||||
}
|
||||
|
||||
export function humanizeConstraints(schema: OpenAPISchema): string[] {
|
||||
|
|
Loading…
Reference in New Issue
Block a user