@sleeksky/alt-swagger
Version:
A fluent, programmatic API for generating OpenAPI 3.0 specifications with TypeScript support. Define REST API endpoints, schemas, parameters, and security using a simple, chainable syntax.
126 lines • 3.46 kB
TypeScript
/**
Author: Yusuf Bhabhrawala
*/
import "./utils";
import { SwaggerSchema, PathParameter, Parameter } from "./utils";
interface Server {
url: string;
description?: string;
}
interface Tag {
name: string;
description?: string;
}
interface SecurityScheme {
type: string;
scheme?: string;
bearerFormat?: string | null;
in?: string;
required?: boolean;
}
interface Components {
securitySchemes?: {
[key: string]: SecurityScheme;
};
schemas?: {
[key: string]: SwaggerSchema;
};
[key: string]: any;
}
interface ResponseSpec {
content?: {
[key: string]: {
schema: SwaggerSchema;
};
};
description: string;
}
interface PathSpec {
parameters: (PathParameter | Parameter)[];
responses: {
[key: string]: ResponseSpec;
};
description: string;
tags?: string[];
summary?: string;
security?: {
[key: string]: string[];
}[];
deprecated?: boolean;
requestBody?: {
content: {
[key: string]: {
schema: SwaggerSchema;
};
};
};
}
interface Paths {
[key: string]: {
[method: string]: PathSpec;
};
}
declare function reset(): void;
declare function server(url: string, description?: string): void;
interface ApiOptions {
path: string;
method: string;
tag?: string;
desc?: string;
summary?: string;
req?: string;
header?: string | string[];
query?: string | string[];
security?: string;
deprecated?: boolean;
[key: string]: any;
}
interface ApiExtension {
req: (flatSch: string) => ApiExtension;
body: (flatSch: string) => ApiExtension;
res: (code: string | number, flatSch: string) => ApiExtension;
query: (strArr: string | string[]) => ApiExtension;
header: (strArr: string | string[]) => ApiExtension;
tag: (str: string) => ApiExtension;
summary: (str: string) => ApiExtension;
desc: (str: string) => ApiExtension;
security: (str: string) => ApiExtension;
deprecate: () => ApiExtension;
remove: () => void;
}
declare function get(path?: string, opt?: Partial<ApiOptions>): ApiExtension;
declare function post(path?: string, opt?: Partial<ApiOptions>): ApiExtension;
declare function put(path?: string, opt?: Partial<ApiOptions>): ApiExtension;
declare function patch(path?: string, opt?: Partial<ApiOptions>): ApiExtension;
declare function del(path?: string, opt?: Partial<ApiOptions>): ApiExtension;
interface RemoveOptions {
path?: string;
tag?: string;
}
declare function remove({ path, tag }: RemoveOptions): void;
interface SecurityOptions {
type?: string;
schema?: string;
bearerFormat?: string | null;
required?: boolean;
}
declare function security(name: string, { type, schema, bearerFormat, required }?: SecurityOptions): string;
declare const ref: {
schema(name: string, flatSch: string): string;
};
declare function tag(name: string, description?: string): void;
interface SwaggerDoc {
info: {
title: string;
version: string;
};
openapi: string;
servers: Server[];
tags: Tag[];
paths: Paths;
components: Components;
}
declare function swaggerDoc(title?: string): SwaggerDoc;
export { tag, server, ref, get, post, put, patch, del, security, swaggerDoc, reset, remove, };
export type { ApiOptions, ApiExtension, SwaggerDoc };
//# sourceMappingURL=index.d.ts.map