在哪里可以找到定义OpenAPI Json的TypeScript接口?

在哪里可以找到定义OpenAPI Json的TypeScript接口?,typescript,types,openapi,Typescript,Types,Openapi,OpenApi规范列出了一系列可以为其设置的字段和值。你可以看到规格 我想有一套定义这些规范的接口。。。我已经从零开始做了一个,到目前为止看起来是这样的: // Totally incomplete export interface IEndpointDocs { path: string, methods: { get?: IMethodDocs, post?: IMethodDocs } } export interface IM

OpenApi规范列出了一系列可以为其设置的字段和值。你可以看到规格

我想有一套定义这些规范的接口。。。我已经从零开始做了一个,到目前为止看起来是这样的:

// Totally incomplete


export interface IEndpointDocs {
    path: string,
    methods: {
        get?: IMethodDocs,
        post?: IMethodDocs
    }
}

export interface IMethodDocs {
    description?: string,
    operationId?: string,
    produces?: Array<
        | "application/json"
        | "application/xml"
        | "text/xml"
        | "text/html"
    >,
    parameters: IMethodParameterDocs[],
}

export interface IMethodParameterDocs {
    name: string,
    in: "query" | "body" | "path",
    description?: string,
    required?: boolean,
    // really, barely started
    type?: "array",
    items: {
        type: "string"
    },
    collectionFormat: "csv"
    format: "int32"
};
//完全不完整
导出接口IEndpointDocs{
路径:字符串,
方法:{
获取?:i方法,
邮政?:IMethododocs
}
}
导出接口方法{
描述?:字符串,
操作ID?:字符串,
生成?:数组<
|“应用程序/json”
|“应用程序/xml”
|“文本/xml”
|“文本/html”
>,
参数:IMethodParameterDocs[],
}
导出接口IMethodParameterDocs{
名称:string,
在:“查询”|“正文”|“路径”中,
描述?:字符串,
必需?:布尔值,
//真的,才刚刚开始
类型?:“数组”,
项目:{
类型:“字符串”
},
收集格式:“csv”
格式:“int32”
};

当然这已经完成了,那么我在哪里可以找到这些接口呢?

这里有一个项目,其类型如下:

/*tslint:disable:无命名空间无空接口*/
导出命名空间OpenAPI{
导出类型Document=OpenAPIV2.Document | OpenAPIV3.Document;
导出类型操作=OpenAPIV2.OperationObject | OpenAPIV3.OperationObject;
导出类型参数=
|OpenAPIV3.ReferenceObject
|OpenAPIV3.ParameterObject
|OpenAPIV2.ReferenceObject
|OpenAPIV2.参数;
导出类型参数=
|排列
|阵列;
导出接口请求{
身体?:任何;
标题?:对象;
参数?:对象;
查询?:对象;
}
}
导出命名空间OpenAPIV3{
导出接口文档{
openapi:string;
信息:信息对象;
服务器?:服务器对象[];
路径:PathsObject;
组件?:组件对象;
安全性?:安全性要求对象[];
标记?:标记对象[];
externalDocs?:ExternalDocumentationObject;
}
导出接口信息对象{
标题:字符串;
description?:字符串;
termsOfService?:字符串;
接触?:接触对象;
许可证?:许可证对象;
版本:字符串;
}
导出接口ContactObject{
名称?:字符串;
url?:字符串;
电子邮件?:字符串;
}
导出接口许可证对象{
名称:字符串;
url?:字符串;
}
导出接口服务器对象{
url:string;
description?:字符串;
变量?:{[变量:字符串]:ServerVariableObject};
}
导出接口ServerVariableObject{
枚举?:字符串[];
默认值:字符串;
description?:字符串;
}
导出接口路径对象{
[模式:字符串]:PathItemObject;
}
导出接口PathItemObject{
$ref?:字符串;
摘要?:字符串;
description?:字符串;
获取?:操作对象;
put?:操作对象;
post?:操作对象;
删除?:操作对象;
选项?:操作对象;
头?:操作对象;
补丁?:操作对象;
跟踪?:操作对象;
服务器?:服务器对象[];
参数?:数组;
}
导出接口操作对象{
标签?:字符串[];
摘要?:字符串;
description?:字符串;
externalDocs?:ExternalDocumentationObject;
操作ID?:字符串;
参数?:数组;
requestBody?:ReferenceObject | requestBody对象;
响应?:响应对象;
回调?:{[callback:string]:ReferenceObject | CallbackObject};
不推荐?:布尔值;
安全性?:安全性要求对象[];
服务器?:服务器对象[];
}
导出接口ExternalDocumentationObject{
description?:字符串;
url:string;
}
导出接口ParameterObject扩展ParameterBaseObject{
名称:字符串;
在:字符串;
}
导出接口HeaderObject扩展参数BaseObject{}
接口参数BaseObject{
description?:字符串;
必需?:布尔值;
不推荐?:布尔值;
allowEmptyValue?:布尔值;
样式?:字符串;
分解?:布尔值;
allowReserved?:布尔值;
模式?:引用对象|模式对象;
例如:任何;
示例?:{[media:string]:ReferenceObject | ExampleObject};
内容?:{[media:string]:MediaTypeObject};
}
导出类型非ArraySchemaObject类型=
|“空”
|“布尔”
|“对象”
|“数字”
|“字符串”
|“整数”;
导出类型ArraySchemaObjectType='array';
导出类型SchemaObject=ArraySchemaObject |非ArraySchemaObject;
接口ArraySchemaObject扩展BaseSchemaObject{
类型:ArraySchemaObject类型;
项目:ReferenceObject | SchemaObject;
}
接口NonArraySchemaObject扩展BaseSchemaObject{
类型:非ArraySchemaObject类型;
}
接口BaseSchemaObject{
//JSON模式允许的属性,针对OpenAPI进行了调整
标题?:字符串;
description?:字符串;
格式?:字符串;
默认?:任何;
倍数:数字;
最大?:数量;
排他最大值?:布尔值;
最小?:数量;
排他最小值?:布尔值;
maxLength?:数字;
minLength?:数字;
模式?:字符串;
附加属性?:布尔|引用对象|模式对象;
maxItems?:编号;
最小项:数字;
唯一项?:布尔值;
maxProperties?:数字;
minProperties?:数字;
必需?:字符串[];
枚举?:任何[];
属性?:{
[名称:字符串]:ReferenceObject | SchemaObject;
};
allOf?:数组;
其中一个:数组;
anyOf?:数组;
非?:引用对象| SchemaObject;
//OpenAPI特定属性
可为空?:布尔值;
鉴别器?:鉴别器对象;
只读?:布尔值;
写?:布尔;
xml?:xml对象;
externalDocs?:ExternalDocumentationObject;
例如:任何;
不推荐?:布尔值;
}
导出接口鉴别器对象{
propertyName:字符串;
映射?:{[value:string]:string};
}
导出接口XMLObject{
名称?:字符串;
名称空间?:字符串;
P
/* tslint:disable:no-namespace no-empty-interface */
export namespace OpenAPI {
  export type Document = OpenAPIV2.Document | OpenAPIV3.Document;
  export type Operation = OpenAPIV2.OperationObject | OpenAPIV3.OperationObject;
  export type Parameter =
    | OpenAPIV3.ReferenceObject
    | OpenAPIV3.ParameterObject
    | OpenAPIV2.ReferenceObject
    | OpenAPIV2.Parameter;
  export type Parameters =
    | Array<OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject>
    | Array<OpenAPIV2.ReferenceObject | OpenAPIV2.Parameter>;

  export interface Request {
    body?: any;
    headers?: object;
    params?: object;
    query?: object;
  }
}

export namespace OpenAPIV3 {
  export interface Document {
    openapi: string;
    info: InfoObject;
    servers?: ServerObject[];
    paths: PathsObject;
    components?: ComponentsObject;
    security?: SecurityRequirementObject[];
    tags?: TagObject[];
    externalDocs?: ExternalDocumentationObject;
  }

  export interface InfoObject {
    title: string;
    description?: string;
    termsOfService?: string;
    contact?: ContactObject;
    license?: LicenseObject;
    version: string;
  }

  export interface ContactObject {
    name?: string;
    url?: string;
    email?: string;
  }

  export interface LicenseObject {
    name: string;
    url?: string;
  }

  export interface ServerObject {
    url: string;
    description?: string;
    variables?: { [variable: string]: ServerVariableObject };
  }

  export interface ServerVariableObject {
    enum?: string[];
    default: string;
    description?: string;
  }

  export interface PathsObject {
    [pattern: string]: PathItemObject;
  }

  export interface PathItemObject {
    $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?: Array<ReferenceObject | ParameterObject>;
  }

  export interface OperationObject {
    tags?: string[];
    summary?: string;
    description?: string;
    externalDocs?: ExternalDocumentationObject;
    operationId?: string;
    parameters?: Array<ReferenceObject | ParameterObject>;
    requestBody?: ReferenceObject | RequestBodyObject;
    responses?: ResponsesObject;
    callbacks?: { [callback: string]: ReferenceObject | CallbackObject };
    deprecated?: boolean;
    security?: SecurityRequirementObject[];
    servers?: ServerObject[];
  }

  export interface ExternalDocumentationObject {
    description?: string;
    url: string;
  }

  export interface ParameterObject extends ParameterBaseObject {
    name: string;
    in: string;
  }

  export interface HeaderObject extends ParameterBaseObject {}

  interface ParameterBaseObject {
    description?: string;
    required?: boolean;
    deprecated?: boolean;
    allowEmptyValue?: boolean;
    style?: string;
    explode?: boolean;
    allowReserved?: boolean;
    schema?: ReferenceObject | SchemaObject;
    example?: any;
    examples?: { [media: string]: ReferenceObject | ExampleObject };
    content?: { [media: string]: MediaTypeObject };
  }
  export type NonArraySchemaObjectType =
    | 'null'
    | 'boolean'
    | 'object'
    | 'number'
    | 'string'
    | 'integer';
  export type ArraySchemaObjectType = 'array';
  export type SchemaObject = ArraySchemaObject | NonArraySchemaObject;

  interface ArraySchemaObject extends BaseSchemaObject {
    type: ArraySchemaObjectType;
    items: ReferenceObject | SchemaObject;
  }

  interface NonArraySchemaObject extends BaseSchemaObject {
    type: NonArraySchemaObjectType;
  }

  interface BaseSchemaObject {
    // JSON schema allowed properties, adjusted for OpenAPI
    title?: string;
    description?: string;
    format?: string;
    default?: any;
    multipleOf?: number;
    maximum?: number;
    exclusiveMaximum?: boolean;
    minimum?: number;
    exclusiveMinimum?: boolean;
    maxLength?: number;
    minLength?: number;
    pattern?: string;
    additionalProperties?: boolean | ReferenceObject | SchemaObject;
    maxItems?: number;
    minItems?: number;
    uniqueItems?: boolean;
    maxProperties?: number;
    minProperties?: number;
    required?: string[];
    enum?: any[];
    properties?: {
      [name: string]: ReferenceObject | SchemaObject;
    };
    allOf?: Array<ReferenceObject | SchemaObject>;
    oneOf?: Array<ReferenceObject | SchemaObject>;
    anyOf?: Array<ReferenceObject | SchemaObject>;
    not?: ReferenceObject | SchemaObject;

    // OpenAPI-specific properties
    nullable?: boolean;
    discriminator?: DiscriminatorObject;
    readOnly?: boolean;
    writeOnly?: boolean;
    xml?: XMLObject;
    externalDocs?: ExternalDocumentationObject;
    example?: any;
    deprecated?: boolean;
  }

  export interface DiscriminatorObject {
    propertyName: string;
    mapping?: { [value: string]: string };
  }

  export interface XMLObject {
    name?: string;
    namespace?: string;
    prefix?: string;
    attribute?: boolean;
    wrapped?: boolean;
  }

  export interface ReferenceObject {
    $ref: string;
  }

  export interface ExampleObject {
    summary?: string;
    description?: string;
    value?: any;
    externalValue?: string;
  }

  export interface MediaTypeObject {
    schema?: ReferenceObject | SchemaObject;
    example?: any;
    examples?: { [media: string]: ReferenceObject | ExampleObject };
    encoding?: { [media: string]: EncodingObject };
  }

  export interface EncodingObject {
    contentType?: string;
    headers?: { [header: string]: ReferenceObject | HeaderObject };
    style?: string;
    explode?: boolean;
    allowReserved?: boolean;
  }

  export interface RequestBodyObject {
    description?: string;
    content: { [media: string]: MediaTypeObject };
    required?: boolean;
  }

  export interface ResponsesObject {
    [code: string]: ReferenceObject | ResponseObject;
  }

  export interface ResponseObject {
    description: string;
    headers?: { [header: string]: ReferenceObject | HeaderObject };
    content?: { [media: string]: MediaTypeObject };
    links?: { [link: string]: ReferenceObject | LinkObject };
  }

  export interface LinkObject {
    operationRef?: string;
    operationId?: string;
    parameters?: { [parameter: string]: any };
    requestBody?: any;
    description?: string;
    server?: ServerObject;
  }

  export interface CallbackObject {
    [url: string]: PathItemObject;
  }

  export interface SecurityRequirementObject {
    [name: string]: string[];
  }

  export interface ComponentsObject {
    schemas?: { [key: string]: ReferenceObject | SchemaObject };
    responses?: { [key: string]: ReferenceObject | ResponseObject };
    parameters?: { [key: string]: ReferenceObject | ParameterObject };
    examples?: { [key: string]: ReferenceObject | ExampleObject };
    requestBodies?: { [key: string]: ReferenceObject | RequestBodyObject };
    headers?: { [key: string]: ReferenceObject | HeaderObject };
    securitySchemes?: { [key: string]: ReferenceObject | SecuritySchemeObject };
    links?: { [key: string]: ReferenceObject | LinkObject };
    callbacks?: { [key: string]: ReferenceObject | CallbackObject };
  }

  export type SecuritySchemeObject =
    | HttpSecurityScheme
    | ApiKeySecurityScheme
    | OAuth2SecurityScheme
    | OpenIdSecurityScheme;

  export interface HttpSecurityScheme {
    type: 'http';
    description?: string;
    scheme: string;
    bearerFormat?: string;
  }

  export interface ApiKeySecurityScheme {
    type: 'apiKey';
    description?: string;
    name: string;
    in: string;
  }

  export interface OAuth2SecurityScheme {
    type: 'oauth2';
    flows: {
      implicit?: {
        authorizationUrl: string;
        refreshUrl?: string;
        scopes: { [scope: string]: string };
      };
      password?: {
        tokenUrl: string;
        refreshUrl?: string;
        scopes: { [scope: string]: string };
      };
      clientCredentials?: {
        tokenUrl: string;
        refreshUrl?: string;
        scopes: { [scope: string]: string };
      };
      authorizationCode?: {
        authorizationUrl: string;
        tokenUrl: string;
        refreshUrl?: string;
        scopes: { [scope: string]: string };
      };
    };
  }

  export interface OpenIdSecurityScheme {
    type: 'openIdConnect';
    description?: string;
    openIdConnectUrl: string;
  }

  export interface TagObject {
    name: string;
    description?: string;
    externalDocs?: ExternalDocumentationObject;
  }
}

export namespace OpenAPIV2 {
  export interface Document {
    basePath?: string;
    consumes?: MimeTypes;
    definitions?: DefinitionsObject;
    externalDocs?: ExternalDocumentationObject;
    host?: string;
    info: InfoObject;
    parameters?: ParametersDefinitionsObject;
    paths: PathsObject;
    produces?: MimeTypes;
    responses?: ResponsesDefinitionsObject;
    schemes?: string[];
    security?: SecurityRequirementObject[];
    securityDefinitions?: SecurityDefinitionsObject;
    swagger: string;
    tags?: TagObject[];
  }

  export interface TagObject {
    name: string;
    description?: string;
    externalDocs?: ExternalDocumentationObject;
  }

  interface SecuritySchemeObjectBase {
    type: 'basic' | 'apiKey' | 'oauth2';
    description?: string;
  }

  interface SecuritySchemeBasic extends SecuritySchemeObjectBase {
    type: 'basic';
  }

  interface SecuritySchemeApiKey extends SecuritySchemeObjectBase {
    type: 'apiKey';
    name: string;
    in: string;
  }

  type SecuritySchemeOauth2 =
    | SecuritySchemeOauth2Implicit
    | SecuritySchemeOauth2AccessCode
    | SecuritySchemeOauth2Password
    | SecuritySchemeOauth2Application;

  export interface ScopesObject {
    [index: string]: any;
  }

  interface SecuritySchemeOauth2Base extends SecuritySchemeObjectBase {
    flow: 'implicit' | 'password' | 'application' | 'accessCode';
    scopes: ScopesObject;
  }

  interface SecuritySchemeOauth2Implicit extends SecuritySchemeOauth2Base {
    flow: 'implicit';
    authorizationUrl: string;
  }

  interface SecuritySchemeOauth2AccessCode extends SecuritySchemeOauth2Base {
    flow: 'accessCode';
    authorizationUrl: string;
    tokenUrl: string;
  }

  interface SecuritySchemeOauth2Password extends SecuritySchemeOauth2Base {
    flow: 'password';
    tokenUrl: string;
  }

  interface SecuritySchemeOauth2Application extends SecuritySchemeOauth2Base {
    flow: 'application';
    tokenUrl: string;
  }

  export type SecuritySchemeObject =
    | SecuritySchemeBasic
    | SecuritySchemeApiKey
    | SecuritySchemeOauth2;

  export interface SecurityDefinitionsObject {
    [index: string]: SecuritySchemeObject;
  }

  export interface SecurityRequirementObject {
    [index: string]: string[];
  }

  export interface ReferenceObject {
    $ref: string;
  }

  type Response = ResponseObject | ReferenceObject;

  export interface ResponsesDefinitionsObject {
    [index: string]: ResponseObject;
  }

  type Schema = SchemaObject | ReferenceObject;

  export interface ResponseObject {
    description: string;
    schema?: Schema;
    headers?: HeadersObject;
    examples?: ExampleObject;
  }

  export interface HeadersObject {
    [index: string]: HeaderObject;
  }

  export interface HeaderObject extends ItemsObject {}

  export interface ExampleObject {
    [index: string]: any;
  }

  export interface ResponseObject {
    description: string;
    schema?: Schema;
    headers?: HeadersObject;
    examples?: ExampleObject;
  }

  export interface OperationObject {
    tags?: string[];
    summary?: string;
    description?: string;
    externalDocs?: ExternalDocumentationObject;
    operationId?: string;
    consumes?: MimeTypes;
    produces?: MimeTypes;
    parameters?: Parameters;
    responses: ResponsesObject;
    schemes?: string[];
    deprecated?: boolean;
    security?: SecurityRequirementObject[];
    [index: string]: any;
  }

  export interface ResponsesObject {
    [index: string]: Response | any;
    default: Response;
  }

  export type Parameters = Array<ReferenceObject | Parameter>;

  export type Parameter = InBodyParameterObject | GeneralParameterObject;

  export interface InBodyParameterObject extends ParameterObject {
    schema: Schema;
  }

  export interface GeneralParameterObject extends ParameterObject, ItemsObject {
    allowEmptyValue?: boolean;
  }

  export interface PathItemObject {
    $ref?: string;
    get?: OperationObject;
    put?: OperationObject;
    post?: OperationObject;
    del?: OperationObject;
    delete?: OperationObject;
    options?: OperationObject;
    head?: OperationObject;
    patch?: OperationObject;
    parameters?: Parameters;
  }

  export interface PathsObject {
    [index: string]: PathItemObject | any;
  }

  export interface ParametersDefinitionsObject {
    [index: string]: ParameterObject;
  }

  interface ParameterObject {
    name: string;
    in: string;
    description?: string;
    required?: boolean;
    [index: string]: any;
  }

  export type MimeTypes = string[];

  export interface DefinitionsObject {
    [index: string]: SchemaObject;
  }

  export interface SchemaObject extends IJsonSchema {
    [index: string]: any;
    discriminator?: string;
    readOnly?: boolean;
    xml?: XMLObject;
    externalDocs?: ExternalDocumentationObject;
    example?: any;
    default?: any;
    items?: ItemsObject;
    properties?: {
      [name: string]: SchemaObject;
    };
  }

  export interface ExternalDocumentationObject {
    [index: string]: any;
    description?: string;
    url: string;
  }

  export interface ItemsObject {
    type: string;
    format?: string;
    items?: ItemsObject;
    collectionFormat?: string;
    default?: any;
    maximum?: number;
    exclusiveMaximum?: boolean;
    minimum?: number;
    exclusiveMinimum?: boolean;
    maxLength?: number;
    minLength?: number;
    pattern?: string;
    maxItems?: number;
    minItems?: number;
    uniqueItems?: boolean;
    enum?: any[];
    multipleOf?: number;
    $ref?: string;
  }

  export interface XMLObject {
    [index: string]: any;
    name?: string;
    namespace?: string;
    prefix?: string;
    attribute?: boolean;
    wrapped?: boolean;
  }

  export interface InfoObject {
    title: string;
    description?: string;
    termsOfService?: string;
    contact?: ContactObject;
    license?: LicenseObject;
    version: string;
  }

  export interface ContactObject {
    name?: string;
    url?: string;
    email?: string;
  }

  export interface LicenseObject {
    name: string;
    url?: string;
  }
}

export interface IJsonSchema {
  id?: string;
  $schema?: string;
  title?: string;
  description?: string;
  multipleOf?: number;
  maximum?: number;
  exclusiveMaximum?: boolean;
  minimum?: number;
  exclusiveMinimum?: boolean;
  maxLength?: number;
  minLength?: number;
  pattern?: string;
  additionalItems?: boolean | IJsonSchema;
  items?: IJsonSchema | IJsonSchema[];
  maxItems?: number;
  minItems?: number;
  uniqueItems?: boolean;
  maxProperties?: number;
  minProperties?: number;
  required?: string[];
  additionalProperties?: boolean | IJsonSchema;
  definitions?: {
    [name: string]: IJsonSchema;
  };
  properties?: {
    [name: string]: IJsonSchema;
  };
  patternProperties?: {
    [name: string]: IJsonSchema;
  };
  dependencies?: {
    [name: string]: IJsonSchema | string[];
  };
  enum?: any[];
  type?: string | string[];
  allOf?: IJsonSchema[];
  anyOf?: IJsonSchema[];
  oneOf?: IJsonSchema[];
  not?: IJsonSchema;
}