@opendoc/openapi-reference-parser
Version:
Get the dependencies of reference in openapi.
46 lines (39 loc) • 1.29 kB
TypeScript
import { OpenAPIV3, OpenAPIV3_1 } from '@scalar/openapi-types';
interface OpenapiDependencies {
directDependencies: string[];
transitiveDependencies: string[];
dependencies: string[];
}
type ComponentKeys = keyof OpenAPIV3.ComponentsObject | keyof OpenAPIV3_1.ComponentsObject;
type HttpMethods = OpenAPIV3.HttpMethods | OpenAPIV3_1.HttpMethods;
interface ReferenceStorage<T> {
paths?: {
[pattern: string]: {
[key in HttpMethods]: T;
} | undefined;
};
components?: {
[key in ComponentKeys]: T;
};
}
type OpenapiReferenceParserResult = ReferenceStorage<OpenapiDependencies>;
interface OpenapiReferenceParserOptions {
/**
* 容忍 Swagger 异常结构
*/
tolerant?: boolean;
}
declare class OpenapiReferenceParser {
private document;
private options;
private directDependenciesStorage;
private transitiveDependenciesStorage;
private dependenciesStorage;
constructor(document: OpenAPIV3.Document | OpenAPIV3_1.Document, options?: OpenapiReferenceParserOptions);
private forEach;
private pickRefs;
private buildDirectDependenciesStorage;
private buildTransitiveDependenciesStorage;
parse(): OpenapiReferenceParserResult;
}
export { OpenapiReferenceParser };