|
| 1 | +// Type definitions for express-openapi 0.6.x |
| 2 | +// Project: https://github.com/kogosoftwarellc/express-openapi |
| 3 | +// Definitions by: TANAKA Koichi <https://github.com/mugeso/> |
| 4 | +// Definitions: https://github.com/borisyankov/DefinitelyTyped |
| 5 | + |
| 6 | +/* =================== USAGE =================== |
| 7 | + import express = require('express'); |
| 8 | + import bodyParser = require('body-parser'); |
| 9 | + import openapi = require('express-openapi'); |
| 10 | + import cors = require('cors'); |
| 11 | +
|
| 12 | + var app = express(); |
| 13 | + app.use(cors()); |
| 14 | + app.use(bodyParser.json()); |
| 15 | +
|
| 16 | + var api: openapi.InitializedApi; |
| 17 | + api = openapi.initialize({ |
| 18 | + apiDoc: require('./api-doc.js'), |
| 19 | + app: app, |
| 20 | + routes: './api-routes' |
| 21 | + }); |
| 22 | +
|
| 23 | + app.use(function(err, req, res, next) { |
| 24 | + res.status(err.status).json(err); |
| 25 | + }); |
| 26 | +
|
| 27 | + app.listen(3000); |
| 28 | + =============================================== */ |
| 29 | + |
| 30 | +/// <reference path="../express/express.d.ts" /> |
| 31 | + |
| 32 | +declare module "express-openapi" { |
| 33 | + import express = require('express'); |
| 34 | + |
| 35 | + export function initialize(args:Args):InitializedApi; |
| 36 | + |
| 37 | + export interface InitializedApi { |
| 38 | + apiDoc: OpenApi.ApiDefinition; |
| 39 | + } |
| 40 | + |
| 41 | + export module OpenApi { |
| 42 | + export interface ApiDefinition { |
| 43 | + swagger: string |
| 44 | + info: InfoObject |
| 45 | + host?: string |
| 46 | + basePath?: string |
| 47 | + schemes?: string[] |
| 48 | + consumes?: MimeTypes |
| 49 | + produces?: MimeTypes |
| 50 | + paths: PathsObject |
| 51 | + definitions?: DefinitionsObject |
| 52 | + parameters?: ParametersDefinitionsObject |
| 53 | + responses?: ResponsesDefinitionsObject |
| 54 | + securityDefinitions?: SecurityDefinitionsObject |
| 55 | + security?: SecurityRequirementObject[] |
| 56 | + tags?: TagObject[] |
| 57 | + externalDocs?: ExternalDocumentationObject |
| 58 | + } |
| 59 | + |
| 60 | + type MimeTypes = string[] |
| 61 | + |
| 62 | + export interface InfoObject { |
| 63 | + title: string |
| 64 | + description?: string |
| 65 | + termsOfService?: string |
| 66 | + contact?: ContactObject |
| 67 | + license?: LicenseObject |
| 68 | + version: string |
| 69 | + } |
| 70 | + |
| 71 | + export interface ContactObject { |
| 72 | + name?: string |
| 73 | + url?: string |
| 74 | + email?: string |
| 75 | + } |
| 76 | + |
| 77 | + export interface LicenseObject { |
| 78 | + name: string |
| 79 | + url?: string |
| 80 | + } |
| 81 | + |
| 82 | + export interface PathsObject { |
| 83 | + [index: string]: PathItemObject|any |
| 84 | + } |
| 85 | + |
| 86 | + export interface PathItemObject { |
| 87 | + $ref?: string |
| 88 | + get?: OperationObject |
| 89 | + put?: OperationObject |
| 90 | + post?: OperationObject |
| 91 | + 'delete'?: OperationObject |
| 92 | + options?: OperationObject |
| 93 | + head?: OperationObject |
| 94 | + patch?: OperationObject |
| 95 | + parameters?: Parameters |
| 96 | + } |
| 97 | + |
| 98 | + export interface OperationObject { |
| 99 | + tags?: string[] |
| 100 | + summary?: string |
| 101 | + description?: string |
| 102 | + externalDocs?: ExternalDocumentationObject |
| 103 | + operationId?: string |
| 104 | + consumes?: MimeTypes |
| 105 | + produces?: MimeTypes |
| 106 | + parameters?: Parameters |
| 107 | + responses: ResponsesObject |
| 108 | + schemes?: string[] |
| 109 | + deprecated?: boolean |
| 110 | + security?: SecurityRequirementObject[], |
| 111 | + [index: string]: any |
| 112 | + } |
| 113 | + |
| 114 | + export interface DefinitionsObject { |
| 115 | + [index: string]: SchemaObject |
| 116 | + } |
| 117 | + |
| 118 | + export interface ResponsesObject { |
| 119 | + [index: string]: Response|any |
| 120 | + 'default': Response |
| 121 | + } |
| 122 | + |
| 123 | + type Response = ResponseObject|ReferenceObject |
| 124 | + |
| 125 | + export interface ResponsesDefinitionsObject { |
| 126 | + [index: string]: ResponseObject |
| 127 | + } |
| 128 | + |
| 129 | + export interface ResponseObject { |
| 130 | + description: string |
| 131 | + schema?: SchemaObject |
| 132 | + headers?: HeadersObject |
| 133 | + examples?: ExampleObject |
| 134 | + } |
| 135 | + |
| 136 | + export interface HeadersObject { |
| 137 | + [index: string]: HeaderObject |
| 138 | + } |
| 139 | + |
| 140 | + export interface HeaderObject extends ItemsObject { |
| 141 | + } |
| 142 | + |
| 143 | + export interface ExampleObject { |
| 144 | + [index: string]: any |
| 145 | + } |
| 146 | + |
| 147 | + export interface SecurityDefinitionsObject { |
| 148 | + [index: string]: SecuritySchemeObject |
| 149 | + } |
| 150 | + |
| 151 | + export interface SecuritySchemeObject { |
| 152 | + type: string |
| 153 | + description?: string |
| 154 | + name: string |
| 155 | + 'in': string |
| 156 | + flow: string |
| 157 | + authorizationUrl: string |
| 158 | + tokenUrl: string |
| 159 | + scopes: ScopesObject |
| 160 | + } |
| 161 | + |
| 162 | + export interface ScopesObject { |
| 163 | + [index: string]: any |
| 164 | + } |
| 165 | + |
| 166 | + export interface SecurityRequirementObject { |
| 167 | + [index: string]: string[] |
| 168 | + } |
| 169 | + |
| 170 | + export interface TagObject { |
| 171 | + name: string |
| 172 | + description?: string |
| 173 | + externalDocs?: ExternalDocumentationObject |
| 174 | + } |
| 175 | + |
| 176 | + export interface ItemsObject { |
| 177 | + type: string |
| 178 | + format?: string |
| 179 | + items?: ItemsObject |
| 180 | + collectionFormat?: string |
| 181 | + 'default'?: any |
| 182 | + maximum?: number |
| 183 | + exclusiveMaximum: boolean |
| 184 | + minimum?: number |
| 185 | + exclusiveMinimum?: boolean |
| 186 | + maxLength?: number |
| 187 | + minLength?: number |
| 188 | + pattern?: string |
| 189 | + maxItems?: number |
| 190 | + minItems?: number |
| 191 | + uniqueItems?: boolean |
| 192 | + 'enum'?: any[] |
| 193 | + multipleOf?: number |
| 194 | + } |
| 195 | + |
| 196 | + export interface ParametersDefinitionsObject { |
| 197 | + [index: string]: ParameterObject |
| 198 | + } |
| 199 | + |
| 200 | + type Parameters = (ParameterObject|ReferenceObject)[] |
| 201 | + |
| 202 | + export interface ParameterObject { |
| 203 | + name: string |
| 204 | + 'in': string |
| 205 | + description?: string |
| 206 | + required?: boolean |
| 207 | + } |
| 208 | + |
| 209 | + export interface InBodyParameterObject extends ParameterObject { |
| 210 | + schema: SchemaObject |
| 211 | + } |
| 212 | + |
| 213 | + export interface GeneralParameterObject extends ParameterObject, ItemsObject { |
| 214 | + allowEmptyValue?: boolean |
| 215 | + } |
| 216 | + |
| 217 | + export interface ReferenceObject { |
| 218 | + $ref: string |
| 219 | + } |
| 220 | + |
| 221 | + export interface ExternalDocumentationObject { |
| 222 | + [index: string]: any |
| 223 | + description?: string |
| 224 | + url: string |
| 225 | + } |
| 226 | + |
| 227 | + export interface SchemaObject extends IJsonSchema { |
| 228 | + [index: string]: any |
| 229 | + discriminator?: string |
| 230 | + readOnly?: boolean |
| 231 | + xml?: XMLObject |
| 232 | + externalDocs: ExternalDocumentationObject |
| 233 | + example: any |
| 234 | + } |
| 235 | + |
| 236 | + export interface XMLObject { |
| 237 | + [index: string]: any |
| 238 | + name?: string |
| 239 | + namespace?: string |
| 240 | + prefix?: string |
| 241 | + attribute?: boolean |
| 242 | + wrapped?: boolean |
| 243 | + } |
| 244 | + } |
| 245 | + |
| 246 | + export interface Args { |
| 247 | + apiDoc: OpenApi.ApiDefinition, |
| 248 | + app: express.Application, |
| 249 | + routes: string |
| 250 | + } |
| 251 | + |
| 252 | + interface IJsonSchema { |
| 253 | + id?: string |
| 254 | + $schema?: string |
| 255 | + title?: string |
| 256 | + description?: string |
| 257 | + multipleOf?: number |
| 258 | + maximum?: number |
| 259 | + exclusiveMaximum?: boolean |
| 260 | + minimum?: number |
| 261 | + exclusiveMinimum?: boolean |
| 262 | + maxLength?: number |
| 263 | + minLength?: number |
| 264 | + pattern?: string |
| 265 | + additionalItems?: boolean | IJsonSchema |
| 266 | + items?: IJsonSchema | IJsonSchema[] |
| 267 | + maxItems?: number |
| 268 | + minItems?: number |
| 269 | + uniqueItems?: boolean |
| 270 | + maxProperties?: number |
| 271 | + minProperties?: number |
| 272 | + required?: string[] |
| 273 | + additionalProperties?: boolean | IJsonSchema |
| 274 | + definitions?: { |
| 275 | + [name: string]: IJsonSchema |
| 276 | + } |
| 277 | + properties?: { |
| 278 | + [name: string]: IJsonSchema |
| 279 | + } |
| 280 | + patternProperties?: { |
| 281 | + [name: string]: IJsonSchema |
| 282 | + } |
| 283 | + dependencies?: { |
| 284 | + [name: string]: IJsonSchema | string[] |
| 285 | + } |
| 286 | + 'enum'?: any[] |
| 287 | + type?: string | string[] |
| 288 | + allOf?: IJsonSchema[] |
| 289 | + anyOf?: IJsonSchema[] |
| 290 | + oneOf?: IJsonSchema[] |
| 291 | + not?: IJsonSchema |
| 292 | + } |
| 293 | +} |
0 commit comments