UNPKG

fastman

Version:

快速api测试及文档生成

337 lines (336 loc) 11.9 kB
/// <reference path="../../../node_modules/@types/node/index.d.ts" /> import Spec from "./base"; export declare namespace OpenApi3 { interface ISpecificationExtension { [extensionName: string]: any; } interface OpenAPIObject extends ISpecificationExtension { openapi: string; info: InfoObject; servers?: ServerObject[]; paths: PathsObject; components?: ComponentsObject; security?: SecurityRequirementObject[]; tags?: TagObject[]; externalDocs?: ExternalDocumentationObject; } interface InfoObject extends ISpecificationExtension { title: string; description?: string; termsOfService?: string; contact?: ContactObject; license?: LicenseObject; version: string; } interface ContactObject extends ISpecificationExtension { name: string; url: string; email: string; } interface LicenseObject extends ISpecificationExtension { name: string; url?: string; } interface ServerObject extends ISpecificationExtension { url: string; description?: string; variables?: { [v: string]: ServerVariableObject; }; } interface ServerVariableObject extends ISpecificationExtension { enum?: string[] | boolean[] | number[]; default: string | boolean | number; description?: string; } interface ComponentsObject extends ISpecificationExtension { schemas?: { [schema: string]: SchemaObject; }; responses?: { [response: string]: ResponseObject; }; parameters?: { [parameter: string]: ParameterObject; }; examples?: { [example: string]: ExampleObject; }; requestBodies?: { [request: string]: RequestBodyObject; }; headers?: { [heaer: string]: HeaderObject; }; securitySchemes?: { [securityScheme: string]: SecuritySchemeObject; }; links?: { [link: string]: LinkObject; }; callbacks?: { [callback: string]: CallbackObject; }; } type Component = SchemaObject | ResponseObject | ParameterObject | ExampleObject | RequestBodyObject | HeaderObject | SecuritySchemeObject | LinkObject | CallbackObject; /** * Rename it to Paths Object to be consistent with the spec * See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#pathsObject */ interface PathsObject extends ISpecificationExtension { [path: string]: PathItemObject | any; } interface PathItemObject extends ISpecificationExtension { $ref?: string; summary?: string; description?: string; get?: OperationObject; put?: OperationObject; post?: OperationObject; delete?: OperationObject; options?: OperationObject; head?: OperationObject; patch?: OperationObject; trace?: OperationObject; servers?: ServerObject; parameters?: (ParameterObject | ReferenceObject)[]; } interface OperationObject extends ISpecificationExtension { tags?: string[]; summary?: string; description?: string; externalDocs?: ExternalDocumentationObject; operationId?: string; parameters?: (ParameterObject | ReferenceObject)[]; requestBody?: RequestBodyObject | ReferenceObject; responses?: ResponsesObject; callbacks?: CallbacksObject; deprecated?: boolean; security?: SecurityRequirementObject[]; servers?: ServerObject; } interface ExternalDocumentationObject extends ISpecificationExtension { description?: string; url: string; } /** * The location of a parameter. * Possible values are "query", "header", "path" or "cookie". * Specification: * https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#parameter-locations */ type ParameterLocation = "query" | "header" | "path" | "cookie"; /** * The style of a parameter. * Describes how the parameter value will be serialized. * (serialization is not implemented yet) * Specification: * https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#style-values */ type ParameterStyle = "matrix" | "label" | "form" | "simple" | "spaceDelimited" | "pipeDelimited" | "deepObject"; interface ParameterObject extends ISpecificationExtension { name: string; in: ParameterLocation; description?: string; required?: boolean; deprecated?: boolean; allowEmptyValue?: boolean; style?: ParameterStyle; explode?: boolean; allowReserved?: boolean; schema?: SchemaObject | ReferenceObject; examples?: { [param: string]: ExampleObject | ReferenceObject; }; example?: any; content?: ContentObject; } interface RequestBodyObject extends ISpecificationExtension { description?: string; content: ContentObject; required?: boolean; } interface ContentObject { [mediatype: string]: MediaTypeObject; } interface MediaTypeObject extends ISpecificationExtension { schema?: SchemaObject | ReferenceObject; examples?: ExampleObject; example?: ExampleObject | ReferenceObject; encoding?: EncodingObject; } interface EncodingObject extends ISpecificationExtension { [property: string]: EncodingPropertyObject | any; } interface EncodingPropertyObject { contentType?: string; headers?: { [key: string]: HeaderObject | ReferenceObject; }; style?: string; explode?: boolean; allowReserved?: boolean; [key: string]: any; } interface ResponsesObject extends ISpecificationExtension { default?: ResponseObject | ReferenceObject; [statuscode: string]: ResponseObject | ReferenceObject | any; } interface ResponseObject extends ISpecificationExtension { description: string; headers?: HeadersObject; content?: ContentObject; links?: LinksObject; } interface CallbacksObject extends ISpecificationExtension { [name: string]: CallbackObject | ReferenceObject | any; } interface CallbackObject extends ISpecificationExtension { [name: string]: PathItemObject | any; } interface HeadersObject { [name: string]: HeaderObject | ReferenceObject; } interface ExampleObject { summary?: string; description?: string; value?: any; externalValue?: string; [property: string]: any; } interface LinksObject { [name: string]: LinkObject | ReferenceObject; } interface LinkObject extends ISpecificationExtension { operationRef?: string; operationId?: string; parameters?: LinkParametersObject; requestBody?: any | string; description?: string; server?: ServerObject; [property: string]: any; } interface LinkParametersObject { [name: string]: any | string; } interface HeaderObject extends ParameterObject { } interface TagObject extends ISpecificationExtension { name: string; description?: string; externalDocs?: ExternalDocumentationObject; [extension: string]: any; } interface ExamplesObject { [name: string]: any; } interface ReferenceObject { $ref: string; } interface SchemaObject extends ISpecificationExtension { nullable?: boolean; discriminator?: DiscriminatorObject; readOnly?: boolean; writeOnly?: boolean; xml?: XmlObject; externalDocs?: ExternalDocumentationObject; example?: any; examples?: any[]; deprecated?: boolean; type?: string; allOf?: (SchemaObject | ReferenceObject)[]; oneOf?: (SchemaObject | ReferenceObject)[]; anyOf?: (SchemaObject | ReferenceObject)[]; not?: SchemaObject | ReferenceObject; items?: SchemaObject | ReferenceObject; properties?: { [propertyName: string]: (SchemaObject | ReferenceObject); }; additionalProperties?: (SchemaObject | ReferenceObject); description?: string; format?: string; default?: any; title?: string; multipleOf?: number; maximum?: number; exclusiveMaximum?: boolean; minimum?: number; exclusiveMinimum?: boolean; maxLength?: number; minLength?: number; pattern?: string; maxItems?: number; minItems?: number; uniqueItems?: boolean; maxProperties?: number; minProperties?: number; required?: string[]; enum?: any[]; } interface SchemasObject { [schema: string]: SchemaObject; } interface DiscriminatorObject { propertyName: string; mapping?: { [key: string]: string; }; } interface XmlObject extends ISpecificationExtension { name?: string; namespace?: string; prefix?: string; attribute?: boolean; wrapped?: boolean; } type SecuritySchemeType = "apiKey" | "http" | "oauth2" | "openIdConnect"; interface SecuritySchemeObject extends ISpecificationExtension { type: SecuritySchemeType; description?: string; name?: string; in?: string; scheme?: string; bearerFormat?: string; flow?: OAuthFlowObject; openIdConnectUrl?: string; } interface OAuthFlowsObject extends ISpecificationExtension { implicit?: OAuthFlowObject; password?: OAuthFlowObject; clientCredentials?: OAuthFlowObject; authorizationCode?: OAuthFlowObject; } interface OAuthFlowObject extends ISpecificationExtension { authorizationUrl: string; tokenUrl: string; refreshUrl?: string; scopes: ScopesObject; } interface ScopesObject extends ISpecificationExtension { [scope: string]: any; } interface SecurityRequirementObject { [name: string]: string[]; } } export default class OpenApi3Spec extends Spec { private oasUtils; private openapiDoc; tag(tag: OpenApi3.TagObject): void; info(info: OpenApi3.InfoObject): void; load(spec: string | object): this; write(format?: string): string; server(server?: OpenApi3.ServerObject): OpenApi3.ServerObject[]; /** * 添加或查找一个资源 * @param {string} path * @returns {OasPathItem} */ path(path: string): OpenApi3.PathItemObject; operation(path: string, method: string, operation?: OpenApi3.OperationObject): OpenApi3.OperationObject; response(status: string, path: string, method: string, response?: OpenApi3.ResponseObject): OpenApi3.ResponseObject; component(name: string, value: OpenApi3.Component, type?: string): any; version(version?: string): number; example(name: string, example: OpenApi3.ExampleObject, path: string, method: string, status: string, mediaType?: string): any; requestExample(name: string, example: OpenApi3.ExampleObject, path: string, method: string, mediaType?: string): any; }