mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-07 13:30:33 +03:00
feat: support for ignoring specified named schemas
This commit is contained in:
parent
a5468fb7bb
commit
9730c4ee1c
|
@ -5,6 +5,7 @@ import { OpenAPIRef, OpenAPISchema, OpenAPISpec, Referenced } from '../types';
|
|||
import { appendToMdHeading, IS_BROWSER } from '../utils/';
|
||||
import { JsonPointer } from '../utils/JsonPointer';
|
||||
import {
|
||||
getDefinitionName,
|
||||
isNamedDefinition,
|
||||
SECURITY_DEFINITIONS_COMPONENT_NAME,
|
||||
SECURITY_DEFINITIONS_JSX_NAME,
|
||||
|
@ -150,6 +151,11 @@ export class OpenAPIParser {
|
|||
*/
|
||||
deref<T extends object>(obj: OpenAPIRef | T, forceCircular = false): T {
|
||||
if (this.isRef(obj)) {
|
||||
const schemaName = getDefinitionName(obj.$ref);
|
||||
if (schemaName && this.options.ignoreNamedSchemas.has(schemaName)) {
|
||||
return { type: 'object', title: schemaName } as T;
|
||||
}
|
||||
|
||||
const resolved = this.byRef<T>(obj.$ref)!;
|
||||
const visited = this._refCounter.visited(obj.$ref);
|
||||
this._refCounter.visit(obj.$ref);
|
||||
|
@ -202,7 +208,7 @@ export class OpenAPIParser {
|
|||
...schema,
|
||||
allOf: undefined,
|
||||
parentRefs: [],
|
||||
title: schema.title || (isNamedDefinition($ref) ? JsonPointer.baseName($ref) : undefined),
|
||||
title: schema.title || getDefinitionName($ref),
|
||||
};
|
||||
|
||||
// avoid mutating inner objects
|
||||
|
@ -214,7 +220,7 @@ export class OpenAPIParser {
|
|||
}
|
||||
|
||||
const allOfSchemas = schema.allOf
|
||||
.map(subSchema => {
|
||||
.map((subSchema) => {
|
||||
if (subSchema && subSchema.$ref && used$Refs.has(subSchema.$ref)) {
|
||||
return undefined;
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ export interface RedocRawOptions {
|
|||
|
||||
expandDefaultServerVariables?: boolean;
|
||||
maxDisplayedEnumValues?: number;
|
||||
ignoreNamedSchemas?: string[] | string;
|
||||
}
|
||||
|
||||
function argValueToBoolean(val?: string | boolean, defaultValue?: boolean): boolean {
|
||||
|
@ -192,6 +193,8 @@ export class RedocNormalizedOptions {
|
|||
expandDefaultServerVariables: boolean;
|
||||
maxDisplayedEnumValues?: number;
|
||||
|
||||
ignoreNamedSchemas: Set<string>;
|
||||
|
||||
constructor(raw: RedocRawOptions, defaults: RedocRawOptions = {}) {
|
||||
raw = { ...defaults, ...raw };
|
||||
const hook = raw.theme && raw.theme.extensionsHook;
|
||||
|
@ -247,5 +250,7 @@ export class RedocNormalizedOptions {
|
|||
|
||||
this.expandDefaultServerVariables = argValueToBoolean(raw.expandDefaultServerVariables);
|
||||
this.maxDisplayedEnumValues = argValueToNumber(raw.maxDisplayedEnumValues);
|
||||
const ignoreNamedSchemas = Array.isArray(raw.ignoreNamedSchemas) ? raw.ignoreNamedSchemas : raw.ignoreNamedSchemas?.split(',').map(s => s.trim());
|
||||
this.ignoreNamedSchemas = new Set(ignoreNamedSchemas);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -369,6 +369,12 @@ export function isNamedDefinition(pointer?: string): boolean {
|
|||
return /^#\/components\/schemas\/[^\/]+$/.test(pointer || '');
|
||||
}
|
||||
|
||||
export function getDefinitionName(pointer?: string): string | undefined {
|
||||
if (!pointer) return undefined;
|
||||
const match = pointer.match(/^#\/components\/schemas\/([^\/]+)$/);
|
||||
return match === null ? undefined : match[1]
|
||||
}
|
||||
|
||||
function humanizeMultipleOfConstraint(multipleOf: number | undefined): string | undefined {
|
||||
if (multipleOf === undefined) {
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue
Block a user