@kubb/oas
Version:
OpenAPI Specification (OAS) utilities and helpers for Kubb, providing parsing, normalization, and manipulation of OpenAPI/Swagger schemas.
102 lines (97 loc) • 4.1 kB
text/typescript
import * as OasTypes from 'oas/types';
import { OASDocument, User, SchemaObject as SchemaObject$1, ParameterObject } from 'oas/types';
export { OasTypes };
export { HttpMethods as HttpMethod } from 'oas/types';
export { findSchemaDefinition, matchesMimeType } from 'oas/utils';
import { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
export { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
import * as oas_normalize_lib_types from 'oas-normalize/lib/types';
import BaseOas from 'oas';
import { Operation } from 'oas/operation';
export { Operation } from 'oas/operation';
export { Infer, Model, RequestParams, Response } from './infer.cjs';
import 'hotscript';
import 'ts-toolbelt';
import 'json-schema-to-ts';
type contentType = 'application/json' | (string & {});
type SchemaObject = OasTypes.SchemaObject & {
'x-nullable'?: boolean;
$ref?: string;
};
declare const HttpMethods: {
GET: "get";
POST: "post";
PUT: "put";
PATCH: "patch";
DELETE: "delete";
HEAD: "head";
OPTIONS: "options";
TRACE: "trace";
};
type Options = {
contentType?: contentType;
discriminator?: 'strict' | 'inherit';
};
declare class Oas<const TOAS = unknown> extends BaseOas {
#private;
document: TOAS;
constructor({ oas, user }: {
oas: TOAS | OASDocument | string;
user?: User;
});
setOptions(options: Options): void;
get options(): Options;
get($ref: string): any;
getKey($ref: string): string | undefined;
set($ref: string, value: unknown): false | undefined;
getDiscriminator(schema: OasTypes.SchemaObject): OpenAPIV3.DiscriminatorObject | undefined;
dereferenceWithRef(schema?: unknown): any;
getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject$1;
getRequestSchema(operation: Operation): SchemaObject$1 | undefined;
getParametersSchema(operation: Operation, inKey: 'path' | 'query' | 'header'): SchemaObject$1 | null;
valdiate(): Promise<oas_normalize_lib_types.ValidationResult>;
}
declare function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document;
declare function isParameterObject(obj: ParameterObject | SchemaObject$1): obj is ParameterObject;
/**
* Determines if a schema is nullable, considering both the standard `nullable` property and the legacy `x-nullable` extension.
*
* @param schema - The schema object to check.
* @returns `true` if the schema is marked as nullable; otherwise, `false`.
*/
declare function isNullable(schema?: SchemaObject$1 & {
'x-nullable'?: boolean;
}): boolean;
/**
* Determines if the given object is an OpenAPI ReferenceObject.
*
* @returns True if {@link obj} is a ReferenceObject; otherwise, false.
*/
declare function isReference(obj?: any): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject;
/**
* Determines if the given object is a SchemaObject with a discriminator property of type DiscriminatorObject.
*
* @returns True if {@link obj} is a SchemaObject containing a non-string {@link discriminator} property.
*/
declare function isDiscriminator(obj?: any): obj is SchemaObject$1 & {
discriminator: OpenAPIV3.DiscriminatorObject;
};
/**
* Determines whether a schema is required.
*
* Returns true if the schema has a non-empty {@link SchemaObject.required} array or a truthy {@link SchemaObject.required} property.
*
* @param schema - The schema object to check.
* @returns True if the schema is required; otherwise, false.
*/
declare function isRequired(schema?: SchemaObject$1): boolean;
declare function isOptional(schema?: SchemaObject$1): boolean;
declare function parse(pathOrApi: string | OASDocument, { oasClass, canBundle, enablePaths }?: {
oasClass?: typeof Oas;
canBundle?: boolean;
enablePaths?: boolean;
}): Promise<Oas>;
declare function merge(pathOrApi: Array<string | OASDocument>, { oasClass }?: {
oasClass?: typeof Oas;
}): Promise<Oas>;
export { HttpMethods, Oas, type SchemaObject, type contentType, isDiscriminator, isNullable, isOpenApiV3_1Document, isOptional, isParameterObject, isReference, isRequired, merge, parse };