UNPKG

8.02 kBTypeScriptView Raw
1export interface Info {
2 title: string;
3 version: string;
4 description?: string | undefined;
5 termsOfService?: string | undefined;
6 contact?: Contact | undefined;
7 license?: License | undefined;
8}
9
10export interface Contact {
11 name?: string | undefined;
12 email?: string | undefined;
13 url?: string | undefined;
14}
15
16export interface License {
17 name: string;
18 url?: string | undefined;
19}
20
21export interface ExternalDocs {
22 url: string;
23 description?: string | undefined;
24}
25
26export interface Tag {
27 name: string;
28 description?: string | undefined;
29 externalDocs?: ExternalDocs | undefined;
30}
31
32export interface Header extends BaseSchema {
33 type: ParameterType;
34}
35
36// ----------------------------- Parameter -----------------------------------
37
38export type ParameterType = "string" | "number" | "integer" | "boolean" | "array" | "object" | "file";
39
40export type BaseParameter = {
41 name: string;
42 in: "body" | "query" | "path" | "header" | "formData" | "body";
43 required?: boolean | undefined;
44 description?: string | undefined;
45};
46
47export type BodyParameter = BaseParameter & {
48 in: "body";
49 schema?: Schema | undefined;
50};
51
52export type GenericFormat = {
53 type?: ParameterType | undefined;
54 format?: string | undefined;
55};
56
57export type IntegerFormat = {
58 type: "integer";
59 format?: "int32" | "int64" | undefined;
60};
61
62export type NumberFormat = {
63 type: "number";
64 format?: "float" | "double" | undefined;
65};
66
67export type StringFormat = {
68 type: "string";
69 format?: "" | "byte" | "binary" | "date" | "date-time" | "password" | undefined;
70};
71
72export type SchemaFormatConstraints = GenericFormat | IntegerFormat | NumberFormat | StringFormat;
73export type BaseFormatContrainedParameter = BaseParameter & SchemaFormatConstraints;
74export type ParameterCollectionFormat = "csv" | "ssv" | "tsv" | "pipes" | "multi";
75
76export type QueryParameter =
77 & BaseFormatContrainedParameter
78 & BaseSchema
79 & {
80 in: "query";
81 allowEmptyValue?: boolean | undefined;
82 collectionFormat?: ParameterCollectionFormat | undefined;
83 };
84
85export type PathParameter =
86 & BaseFormatContrainedParameter
87 & BaseSchema
88 & {
89 in: "path";
90 required: true;
91 };
92
93export type HeaderParameter =
94 & BaseFormatContrainedParameter
95 & BaseSchema
96 & {
97 in: "header";
98 };
99
100export type FormDataParameter =
101 & BaseFormatContrainedParameter
102 & BaseSchema
103 & {
104 in: "formData";
105 type: ParameterType | "file";
106 allowEmptyValue?: boolean | undefined;
107 collectionFormat?: ParameterCollectionFormat | undefined;
108 };
109
110export type Parameter = BodyParameter | FormDataParameter | QueryParameter | PathParameter | HeaderParameter;
111
112// ------------------------------- Path --------------------------------------
113export interface Path {
114 $ref?: string | undefined;
115 get?: Operation | undefined;
116 put?: Operation | undefined;
117 post?: Operation | undefined;
118 delete?: Operation | undefined;
119 options?: Operation | undefined;
120 head?: Operation | undefined;
121 patch?: Operation | undefined;
122 parameters?: Array<Parameter | Reference> | undefined;
123}
124
125// ----------------------------- Operation -----------------------------------
126export interface Operation {
127 responses: { [responseName: string]: Response | Reference };
128 summary?: string | undefined;
129 description?: string | undefined;
130 externalDocs?: ExternalDocs | undefined;
131 operationId?: string | undefined;
132 produces?: string[] | undefined;
133 consumes?: string[] | undefined;
134 parameters?: Array<Parameter | Reference> | undefined;
135 schemes?: string[] | undefined;
136 deprecated?: boolean | undefined;
137 security?: Array<{ [securityDefinitionName: string]: string[] }> | undefined;
138 tags?: string[] | undefined;
139}
140
141// ----------------------------- Reference -----------------------------------
142export interface Reference {
143 $ref: string;
144}
145
146// ----------------------------- Response ------------------------------------
147export interface Response {
148 description: string;
149 schema?: Schema | undefined;
150 headers?: { [headerName: string]: Header } | undefined;
151 examples?: { [exampleName: string]: {} } | undefined;
152}
153
154// ------------------------------ Schema -------------------------------------
155export type BaseSchema = {
156 type?: ParameterType | undefined;
157 format?: string | undefined;
158 title?: string | undefined;
159 description?: string | undefined;
160 default?: any;
161 multipleOf?: number | undefined;
162 maximum?: number | undefined;
163 exclusiveMaximum?: boolean | undefined;
164 minimum?: number | undefined;
165 exclusiveMinimum?: boolean | undefined;
166 maxLength?: number | undefined;
167 minLength?: number | undefined;
168 pattern?: string | undefined;
169 maxItems?: number | undefined;
170 minItems?: number | undefined;
171 uniqueItems?: boolean | undefined;
172 maxProperties?: number | undefined;
173 minProperties?: number | undefined;
174 enum?: any[] | undefined;
175 items?: Schema | Schema[] | undefined;
176};
177
178export interface Schema extends BaseSchema {
179 $ref?: string | undefined;
180 allOf?: Schema[] | undefined;
181 additionalProperties?: Schema | boolean | undefined;
182 properties?: { [propertyName: string]: Schema } | undefined;
183 discriminator?: string | undefined;
184 readOnly?: boolean | undefined;
185 xml?: XML | undefined;
186 externalDocs?: ExternalDocs | undefined;
187 example?: any;
188 required?: string[] | undefined;
189}
190
191export interface XML {
192 name?: string | undefined;
193 namespace?: string | undefined;
194 prefix?: string | undefined;
195 attribute?: boolean | undefined;
196 wrapped?: boolean | undefined;
197}
198
199// ----------------------------- Security ------------------------------------
200export interface BaseSecurity {
201 type: "basic" | "apiKey" | "oauth2";
202 description?: string | undefined;
203}
204
205export interface BasicAuthenticationSecurity extends BaseSecurity {
206 type: "basic";
207}
208
209export interface ApiKeySecurity extends BaseSecurity {
210 type: "apiKey";
211 name: string;
212 in: "query" | "header";
213}
214
215export interface BaseOAuthSecurity extends BaseSecurity {
216 type: "oauth2";
217 flow: "accessCode" | "application" | "implicit" | "password";
218 scopes?: OAuthScope | undefined;
219}
220
221export interface OAuth2ImplicitSecurity extends BaseOAuthSecurity {
222 type: "oauth2";
223 flow: "implicit";
224 authorizationUrl: string;
225}
226
227export interface OAuth2PasswordSecurity extends BaseOAuthSecurity {
228 type: "oauth2";
229 flow: "password";
230 tokenUrl: string;
231}
232
233export interface OAuth2ApplicationSecurity extends BaseOAuthSecurity {
234 type: "oauth2";
235 flow: "application";
236 tokenUrl: string;
237}
238
239export interface OAuth2AccessCodeSecurity extends BaseOAuthSecurity {
240 type: "oauth2";
241 flow: "accessCode";
242 tokenUrl: string;
243 authorizationUrl: string;
244}
245
246export interface OAuthScope {
247 [scopeName: string]: string;
248}
249
250export type Security =
251 | BasicAuthenticationSecurity
252 | OAuth2AccessCodeSecurity
253 | OAuth2ApplicationSecurity
254 | OAuth2ImplicitSecurity
255 | OAuth2PasswordSecurity
256 | ApiKeySecurity;
257
258// --------------------------------- Spec ------------------------------------
259export interface Spec {
260 swagger: string;
261 info: Info;
262 externalDocs?: ExternalDocs | undefined;
263 host?: string | undefined;
264 basePath?: string | undefined;
265 schemes?: string[] | undefined;
266 consumes?: string[] | undefined;
267 produces?: string[] | undefined;
268 paths: { [pathName: string]: Path };
269 definitions?: { [definitionsName: string]: Schema } | undefined;
270 parameters?: { [parameterName: string]: BodyParameter | QueryParameter } | undefined;
271 responses?: { [responseName: string]: Response } | undefined;
272 security?: Array<{ [securityDefinitionName: string]: string[] }> | undefined;
273 securityDefinitions?: { [securityDefinitionName: string]: Security } | undefined;
274 tags?: Tag[] | undefined;
275}