openapi-specification-types 0.0.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # openapi-specification-types
2
+
3
+ TypeScript type definitions for [OpenAPI (Swagger) 2.0](https://swagger.io/specification/v2/) and [OpenAPI 3.x](https://spec.openapis.org/oas/v3.2.0) specifications.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add openapi-specification-types
9
+ # or
10
+ npm i openapi-specification-types
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import type {
17
+ OpenAPISpecificationV2,
18
+ OpenAPISpecificationV3,
19
+ Parameter,
20
+ Paths,
21
+ Schema,
22
+ Tag,
23
+ } from 'openapi-specification-types'
24
+
25
+ // OpenAPI 2.0 (Swagger) — required: swagger, info (title, version), paths
26
+ const v2: OpenAPISpecificationV2 = {
27
+ swagger: '2.0',
28
+ info: { title: 'API', version: '1.0' },
29
+ paths: {},
30
+ }
31
+
32
+ // OpenAPI 3.x — required: openapi, info, externalDocs, servers, tags, paths, components
33
+ const v3: OpenAPISpecificationV3 = {
34
+ openapi: '3.0.0',
35
+ info: {
36
+ title: 'API',
37
+ version: '1.0',
38
+ description: '',
39
+ termsOfService: '',
40
+ contact: { name: '', url: '', email: '' },
41
+ license: { name: '', url: '' },
42
+ },
43
+ externalDocs: { description: '', url: '' },
44
+ servers: [],
45
+ tags: [],
46
+ paths: {},
47
+ components: { schemas: {}, requestBodies: {} },
48
+ }
49
+ ```
50
+
51
+ ## Exported types
52
+
53
+ - **OpenAPI 2.0**: `OpenAPISpecificationV2`, `InfoV2`, `ContactV2`, `LicenseV2`, `ExternalDocsV2`, `Definitions`, `SecurityDefinitions`, `PathsV2`, etc.
54
+ - **OpenAPI 3.x**: `OpenAPISpecificationV3`, `Components`, `Server`, `RequestBody`, `SecurityScheme`, etc.
55
+ - **Shared**: `Schema`, `Paths`, `Parameter`, `Tag`, `Method`, `Responses`, `RequestBody`, `AnyObject`, etc.
56
+
57
+ ## Scripts
58
+
59
+ | Command | Description |
60
+ |---------|-------------|
61
+ | `pnpm run typecheck` | TypeScript type check |
62
+ | `pnpm run test` | Run Vitest (runtime + type tests) |
63
+ | `pnpm run lint` | Run ESLint |
64
+
65
+ ## Testing
66
+
67
+ Tests include:
68
+
69
+ - **Runtime tests** (`test/*.test.ts`): value checks with Vitest.
70
+ - **Type tests** (`test/*.test-d.ts`): compile-time checks with `expectTypeOf` / `assertType`; run via `pnpm test` (uses `vitest --typecheck`).
71
+
72
+ ## License
73
+
74
+ ISC
@@ -0,0 +1,595 @@
1
+ //#region src/common.d.ts
2
+ interface StringObject {
3
+ [key: string]: string;
4
+ }
5
+ interface AnyObject {
6
+ [key: string]: any;
7
+ }
8
+ /** JSON Reference — used for $ref in Swagger 2.0 / OpenAPI (parameter, response, path, schema). */
9
+ interface Reference {
10
+ $ref: string;
11
+ /** OpenAPI 3.x: override referenced component summary. */
12
+ summary?: string;
13
+ /** OpenAPI 3.x: override referenced component description. */
14
+ description?: string;
15
+ }
16
+ /** Security Requirement — scheme name to list of scopes ([] for apiKey/http/mutualTLS). Shared by Swagger 2.0 and OpenAPI 3.x. */
17
+ interface SecurityRequirement {
18
+ [schemeName: string]: string[];
19
+ }
20
+ /** Contact Object — optional contact for the API (Swagger 2.0 / OpenAPI 3.x). */
21
+ interface Contact {
22
+ name?: string;
23
+ url?: string;
24
+ email?: string;
25
+ }
26
+ /** License Object — name required when present; identifier/url optional (OpenAPI 3.x); v2 uses name + url only. */
27
+ interface License {
28
+ name: string;
29
+ identifier?: string;
30
+ url?: string;
31
+ }
32
+ /** Info Object — API metadata; title and version required (Swagger 2.0 / OpenAPI 3.x). */
33
+ interface Info {
34
+ title: string;
35
+ version: string;
36
+ summary?: string;
37
+ description?: string;
38
+ termsOfService?: string;
39
+ contact?: Contact;
40
+ license?: License;
41
+ }
42
+ //#endregion
43
+ //#region src/schema.d.ts
44
+ /** JSON Schema / Swagger 2.0 primitive types; file for Parameter/Response only; null for JSON Schema 2020-12 (OpenAPI 3.x). */
45
+ type SchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'file' | 'null';
46
+ interface Schema {
47
+ $ref?: string;
48
+ format?: string;
49
+ title?: string;
50
+ description?: string;
51
+ default?: unknown;
52
+ type?: SchemaType | SchemaType[];
53
+ /** JSON Schema validation. */
54
+ multipleOf?: number;
55
+ maximum?: number;
56
+ minimum?: number;
57
+ exclusiveMaximum?: boolean;
58
+ exclusiveMinimum?: boolean;
59
+ maxLength?: number;
60
+ minLength?: number;
61
+ pattern?: string;
62
+ maxItems?: number;
63
+ minItems?: number;
64
+ uniqueItems?: boolean;
65
+ maxProperties?: number;
66
+ minProperties?: number;
67
+ required?: string[];
68
+ enum?: unknown[];
69
+ items?: Schema;
70
+ allOf?: Schema[];
71
+ properties?: Properties;
72
+ additionalProperties?: Schema | boolean;
73
+ /** Swagger 2.0: polymorphism; property name in required; value = definition name. */
74
+ discriminator?: string;
75
+ /** Swagger 2.0: property only in response. */
76
+ readOnly?: boolean;
77
+ /** Swagger 2.0: example instance. */
78
+ example?: unknown;
79
+ xml?: {
80
+ name?: string;
81
+ namespace?: string;
82
+ prefix?: string;
83
+ attribute?: boolean;
84
+ wrapped?: boolean;
85
+ };
86
+ externalDocs?: {
87
+ url: string;
88
+ description?: string;
89
+ };
90
+ /** Legacy / codegen. */
91
+ originalRef?: string;
92
+ }
93
+ interface Properties {
94
+ [name: string]: Schema;
95
+ }
96
+ //#endregion
97
+ //#region src/body.d.ts
98
+ /** Media Type Object — content for a media type (RequestBody, Response) (OpenAPI 3.x). */
99
+ interface RequestBodyContent {
100
+ schema?: Schema;
101
+ itemSchema?: Schema;
102
+ example?: unknown;
103
+ examples?: Record<string, AnyObject>;
104
+ encoding?: Record<string, AnyObject>;
105
+ }
106
+ interface RequestBody {
107
+ description?: string;
108
+ /** **REQUIRED**. Media type or range → Media Type or Reference; at least one entry. */
109
+ content: Record<string, RequestBodyContent | Reference>;
110
+ required?: boolean;
111
+ }
112
+ //#endregion
113
+ //#region src/parameter.d.ts
114
+ /** collectionFormat for array parameters (Swagger 2.0; OpenAPI 3.x uses style/explode). */
115
+ type CollectionFormat = 'csv' | 'ssv' | 'tsv' | 'pipes' | 'multi';
116
+ /**
117
+ * Items (Swagger 2.0 only) — used for non-body array parameters and Header when type is array.
118
+ * Limited subset: no $ref, no file/object; only string, number, integer, boolean, or array (nested).
119
+ * OpenAPI 3.x uses Schema for parameter items.
120
+ * @see https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md
121
+ */
122
+ interface Items {
123
+ type: 'string' | 'number' | 'integer' | 'boolean' | 'array';
124
+ format?: string;
125
+ /** Required when type is "array"; recursive Items. */
126
+ items?: Items;
127
+ /** csv, ssv, tsv, pipes (default csv). No "multi" inside Items. */
128
+ collectionFormat?: 'csv' | 'ssv' | 'tsv' | 'pipes';
129
+ default?: unknown;
130
+ maximum?: number;
131
+ minimum?: number;
132
+ exclusiveMaximum?: boolean;
133
+ exclusiveMinimum?: boolean;
134
+ maxLength?: number;
135
+ minLength?: number;
136
+ pattern?: string;
137
+ maxItems?: number;
138
+ minItems?: number;
139
+ uniqueItems?: boolean;
140
+ enum?: unknown[];
141
+ multipleOf?: number;
142
+ }
143
+ /** Parameter style (OpenAPI 3.x). */
144
+ type ParameterStyle = 'matrix' | 'label' | 'simple' | 'form' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject' | 'cookie';
145
+ /**
146
+ * Parameter — body/formData/path/query/header (Swagger 2.0) or cookie/querystring (OpenAPI 3.x).
147
+ * Swagger 2.0: when in !== "body" and type === "array", items MUST be Items (see Items), not full Schema.
148
+ */
149
+ interface Parameter extends Omit<Schema, 'required'> {
150
+ name: string;
151
+ /** body/formData = Swagger 2.0; path/query/header/cookie/querystring = OpenAPI 3.x. */
152
+ in: 'body' | 'header' | 'query' | 'path' | 'formData' | 'cookie' | 'querystring';
153
+ /** Required when in is not body; one of string, number, integer, boolean, array, file. */
154
+ type?: Schema['type'] | 'file';
155
+ description?: string;
156
+ required?: boolean;
157
+ /** OpenAPI 3.x: default false. */
158
+ deprecated?: boolean;
159
+ /** Required when in is body; Schema Object for the whole body. For OpenAPI 3.x use schema OR content (not both). */
160
+ schema?: Schema;
161
+ /** For array: Swagger 2.0 non-body uses Items; body uses Schema. OpenAPI 3.x: Schema. */
162
+ items?: Schema | Items;
163
+ /** For array (non-body): csv, ssv, tsv, pipes, multi (query/formData only) — Swagger 2.0. */
164
+ collectionFormat?: CollectionFormat;
165
+ /** For query/formData — allows empty value. */
166
+ allowEmptyValue?: boolean;
167
+ /** OpenAPI 3.x: serialization style (path default simple; query form; header/cookie simple). */
168
+ style?: ParameterStyle;
169
+ /** OpenAPI 3.x: for array/object separate params per value. */
170
+ explode?: boolean;
171
+ /** OpenAPI 3.x: reserved expansion (RFC6570). */
172
+ allowReserved?: boolean;
173
+ /** OpenAPI 3.x: one media type → representation; required for in: "querystring". */
174
+ content?: Record<string, unknown>;
175
+ }
176
+ //#endregion
177
+ //#region src/header-link.d.ts
178
+ /**
179
+ * Header (OpenAPI 3.x) — response/multipart header; follows Parameter (schema or content).
180
+ * No name/in; style only "simple". Shared by Response.headers and Components.headers.
181
+ */
182
+ interface Header {
183
+ description?: string;
184
+ required?: boolean;
185
+ deprecated?: boolean;
186
+ style?: 'simple';
187
+ explode?: boolean;
188
+ schema?: Schema;
189
+ /** One media type → Media Type or Reference. */
190
+ content?: Record<string, unknown>;
191
+ example?: unknown;
192
+ examples?: Record<string, unknown>;
193
+ }
194
+ /**
195
+ * Link (OpenAPI 3.x) — design-time link to another operation.
196
+ * Shared by Response.links and Components.links.
197
+ */
198
+ interface Link {
199
+ operationRef?: string;
200
+ operationId?: string;
201
+ parameters?: Record<string, unknown>;
202
+ requestBody?: unknown;
203
+ description?: string;
204
+ server?: unknown;
205
+ }
206
+ //#endregion
207
+ //#region src/server.d.ts
208
+ /** Server Object — target host; supports variables in {braces} (OpenAPI 3.x). */
209
+ interface Server {
210
+ /** **REQUIRED**. Target host URL; query and fragment MUST NOT be used. */
211
+ url: string;
212
+ description?: string;
213
+ /** Optional unique string for the host (OpenAPI 3.1+). */
214
+ name?: string;
215
+ variables?: Record<string, ServerVariable>;
216
+ }
217
+ /** Server Variable Object — substitution in server url (OpenAPI 3.x). */
218
+ interface ServerVariable {
219
+ /** **REQUIRED**. Default for substitution; MUST be in enum if enum is defined. */
220
+ default: string;
221
+ /** If present, substitution values from this set. */
222
+ enum?: string[];
223
+ description?: string;
224
+ }
225
+ //#endregion
226
+ //#region src/paths.d.ts
227
+ /** Header (Swagger 2.0) — response header. Uses Items for array items, not full Schema. V3 uses schema/content. */
228
+ interface HeaderV2 {
229
+ description?: string;
230
+ type: 'string' | 'number' | 'integer' | 'boolean' | 'array';
231
+ format?: string;
232
+ /** Required when type is "array"; Items (no $ref/file). */
233
+ items?: Items;
234
+ collectionFormat?: 'csv' | 'ssv' | 'tsv' | 'pipes';
235
+ default?: unknown;
236
+ maximum?: number;
237
+ minimum?: number;
238
+ exclusiveMaximum?: boolean;
239
+ exclusiveMinimum?: boolean;
240
+ maxLength?: number;
241
+ minLength?: number;
242
+ pattern?: string;
243
+ maxItems?: number;
244
+ minItems?: number;
245
+ uniqueItems?: boolean;
246
+ enum?: unknown[];
247
+ multipleOf?: number;
248
+ }
249
+ /** Headers (Swagger 2.0) — header name to Header. */
250
+ interface HeadersV2 {
251
+ [name: string]: HeaderV2;
252
+ }
253
+ /** Response (Swagger 2.0) — at least description. */
254
+ interface ResponseV2 {
255
+ description: string;
256
+ schema?: Schema;
257
+ headers?: HeadersV2;
258
+ /** MIME type to example value. */
259
+ examples?: Record<string, unknown>;
260
+ }
261
+ /** Response definition or $ref (Swagger 2.0). */
262
+ type ResponseV2Ref = ResponseV2 | Reference;
263
+ /** Responses (Swagger 2.0) — status code or "default" to Response. */
264
+ interface ResponsesV2 {
265
+ [statusCode: string]: ResponseV2Ref;
266
+ }
267
+ /** Operation (Swagger 2.0). */
268
+ interface OperationV2 {
269
+ tags?: string[];
270
+ summary?: string;
271
+ description?: string;
272
+ externalDocs?: {
273
+ description?: string;
274
+ url: string;
275
+ };
276
+ operationId?: string;
277
+ consumes?: string[];
278
+ produces?: string[];
279
+ parameters?: (Parameter | Reference)[];
280
+ /** At least one response required. */
281
+ responses: ResponsesV2;
282
+ schemes?: ('http' | 'https' | 'ws' | 'wss')[];
283
+ deprecated?: boolean;
284
+ security?: SecurityRequirement[];
285
+ }
286
+ /** Path Item (Swagger 2.0) — inline definition; do not mix with $ref. */
287
+ interface PathItemV2 {
288
+ get?: OperationV2;
289
+ put?: OperationV2;
290
+ post?: OperationV2;
291
+ delete?: OperationV2;
292
+ options?: OperationV2;
293
+ head?: OperationV2;
294
+ patch?: OperationV2;
295
+ parameters?: (Parameter | Reference)[];
296
+ }
297
+ /** Path Item $ref (Swagger 2.0) — when present, other path fields must not be used. */
298
+ interface PathItemRefV2 {
299
+ $ref: string;
300
+ }
301
+ /** Path Item or $ref (Swagger 2.0). */
302
+ type PathItemV2Ref = PathItemRefV2 | PathItemV2;
303
+ /** Paths (Swagger 2.0). */
304
+ interface PathsV2 {
305
+ [path: string]: PathItemV2Ref;
306
+ }
307
+ /** Media Type (OpenAPI 3.x) — content for a media type. */
308
+ interface MediaType {
309
+ schema?: Schema;
310
+ /** Sequential media types (e.g. application/jsonl) — per-item schema (OpenAPI 3.1+). */
311
+ itemSchema?: Schema;
312
+ example?: unknown;
313
+ examples?: Record<string, unknown>;
314
+ encoding?: Record<string, unknown>;
315
+ }
316
+ /** Response (OpenAPI 3.x) — possible response. */
317
+ interface Response {
318
+ description?: string;
319
+ summary?: string;
320
+ /** Header name → Header or Reference (reused from Components). */
321
+ headers?: Record<string, Header | Reference>;
322
+ /** Media type or range → Media Type or Reference. */
323
+ content?: Record<string, MediaType | Reference>;
324
+ /** Link name → Link or Reference (reused from Components). */
325
+ links?: Record<string, Link | Reference>;
326
+ }
327
+ /** Response or $ref (OpenAPI 3.x). */
328
+ type ResponseRef = Response | Reference;
329
+ /** Responses (OpenAPI 3.x) — status code or "default" to Response. */
330
+ interface Responses {
331
+ [status: string]: ResponseRef;
332
+ }
333
+ /** Operation (OpenAPI 3.x) — one API operation. */
334
+ interface Method {
335
+ tags?: string[];
336
+ summary?: string;
337
+ description?: string;
338
+ externalDocs?: {
339
+ url: string;
340
+ description?: string;
341
+ };
342
+ operationId?: string;
343
+ parameters?: (Parameter | Reference)[];
344
+ requestBody?: RequestBody | Reference;
345
+ responses: Responses;
346
+ /** Runtime expression → Path Item or Reference (Callback). */
347
+ callbacks?: Record<string, PathItem | Reference>;
348
+ deprecated?: boolean;
349
+ security?: Security[];
350
+ servers?: Server[];
351
+ }
352
+ /** Path Item (OpenAPI 3.x) — operations on a single path. */
353
+ interface PathItem {
354
+ $ref?: string;
355
+ summary?: string;
356
+ description?: string;
357
+ get?: Method;
358
+ put?: Method;
359
+ post?: Method;
360
+ delete?: Method;
361
+ options?: Method;
362
+ head?: Method;
363
+ patch?: Method;
364
+ trace?: Method;
365
+ /** QUERY method (IETF safe-method-w-body) (OpenAPI 3.2). */
366
+ query?: Method;
367
+ /** Additional HTTP methods (OpenAPI 3.2). */
368
+ additionalOperations?: Record<string, Method>;
369
+ servers?: Server[];
370
+ parameters?: (Parameter | Reference)[];
371
+ }
372
+ interface Paths {
373
+ [path: string]: PathItem;
374
+ }
375
+ /** Security Requirement (OpenAPI 3.x) — alias of shared SecurityRequirement. */
376
+ type Security = SecurityRequirement;
377
+ //#endregion
378
+ //#region src/definitions.d.ts
379
+ /** Definition is a Schema Object — reusable type under definitions (Swagger 2.0). */
380
+ type Definition = Schema;
381
+ interface Definitions {
382
+ [name: string]: Definition;
383
+ }
384
+ /** Parameters Definitions Object — name maps to full Parameter Object; reference elsewhere with #/parameters/name (Spec § Parameters Definitions Object). */
385
+ interface ParametersDefinitions {
386
+ [name: string]: Parameter;
387
+ }
388
+ /** Responses Definitions (Swagger 2.0) — name maps to full Response; reference elsewhere with #/responses/name. */
389
+ interface ResponsesDefinitions {
390
+ [name: string]: ResponseV2;
391
+ }
392
+ /** OAuth2 flow (Swagger 2.0 only). OpenAPI 3.x uses OAuth Flows object. */
393
+ type OAuth2Flow = 'implicit' | 'password' | 'application' | 'accessCode';
394
+ /** Scopes — scope name to description (Swagger 2.0 only). */
395
+ interface Scopes {
396
+ [name: string]: string;
397
+ }
398
+ /** Security scheme (2.0 only): basic. Cannot merge with 3.x (http with scheme "basic" has different structure). */
399
+ interface SecuritySchemeBasicV2 {
400
+ type: 'basic';
401
+ description?: string;
402
+ }
403
+ /** Security scheme (2.0 only): apiKey, in query|header. 3.x adds cookie and different optional fields. */
404
+ interface SecuritySchemeApiKeyV2 {
405
+ type: 'apiKey';
406
+ name: string;
407
+ in: 'query' | 'header';
408
+ description?: string;
409
+ }
410
+ /** Security scheme (2.0 only): oauth2 with flow + authorizationUrl/tokenUrl. 3.x uses OAuth Flows object. */
411
+ interface SecuritySchemeOAuth2V2 {
412
+ type: 'oauth2';
413
+ flow: OAuth2Flow;
414
+ scopes: Scopes;
415
+ authorizationUrl?: string;
416
+ tokenUrl?: string;
417
+ description?: string;
418
+ }
419
+ type SecurityDefinitionScheme = SecuritySchemeBasicV2 | SecuritySchemeApiKeyV2 | SecuritySchemeOAuth2V2;
420
+ interface SecurityDefinitions {
421
+ [name: string]: SecurityDefinitionScheme;
422
+ }
423
+ //#endregion
424
+ //#region src/components.d.ts
425
+ /** Components (OpenAPI 3.x) — reusable objects. At least one of components, paths, or webhooks MUST be present at root. */
426
+ interface Components {
427
+ schemas?: Definitions;
428
+ responses?: Record<string, ResponseRef>;
429
+ parameters?: Record<string, Parameter | Reference>;
430
+ examples?: Record<string, Example | Reference>;
431
+ requestBodies?: Record<string, RequestBody | Reference>;
432
+ headers?: Record<string, Header | Reference>;
433
+ securitySchemes?: Record<string, SecurityScheme | Reference>;
434
+ links?: Record<string, Link | Reference>;
435
+ callbacks?: Record<string, Callback | Reference>;
436
+ pathItems?: Record<string, PathItem | Reference>;
437
+ mediaTypes?: Record<string, MediaType | Reference>;
438
+ }
439
+ /** Request Body or $ref (OpenAPI 3.x). */
440
+ interface RequestBodies {
441
+ [name: string]: RequestBody | Reference;
442
+ }
443
+ /** Example (OpenAPI 3.x) — summary, description, value/dataValue/serializedValue/externalValue. */
444
+ interface Example {
445
+ summary?: string;
446
+ description?: string;
447
+ value?: unknown;
448
+ dataValue?: unknown;
449
+ serializedValue?: string;
450
+ externalValue?: string;
451
+ }
452
+ /** Callback (OpenAPI 3.x) — runtime expression to Path Item. */
453
+ interface Callback {
454
+ [expression: string]: PathItem;
455
+ }
456
+ interface SecuritySchemes {
457
+ [name: string]: SecurityScheme | Reference;
458
+ }
459
+ /** apiKey — name and in required. */
460
+ interface ApiKeySecurityScheme {
461
+ type: 'apiKey';
462
+ name: string;
463
+ in: 'query' | 'header' | 'cookie';
464
+ description?: string;
465
+ deprecated?: boolean;
466
+ }
467
+ /** http — scheme required (e.g. basic, bearer); bearerFormat for bearer. */
468
+ interface HttpSecurityScheme {
469
+ type: 'http';
470
+ scheme: string;
471
+ bearerFormat?: string;
472
+ description?: string;
473
+ deprecated?: boolean;
474
+ }
475
+ /** mutualTLS — client certificate (OpenAPI 3.1+). */
476
+ interface MutualTlsSecurityScheme {
477
+ type: 'mutualTLS';
478
+ description?: string;
479
+ deprecated?: boolean;
480
+ }
481
+ /** OAuth Flow Object — URLs and scopes per flow (OpenAPI 3.x). */
482
+ interface OAuthFlow {
483
+ authorizationUrl?: string;
484
+ deviceAuthorizationUrl?: string;
485
+ tokenUrl?: string;
486
+ refreshUrl?: string;
487
+ scopes: StringObject;
488
+ }
489
+ /** OAuth Flows Object — implicit, password, clientCredentials, authorizationCode, deviceAuthorization (OpenAPI 3.2). */
490
+ interface OAuthFlows {
491
+ implicit?: OAuthFlow;
492
+ password?: OAuthFlow;
493
+ clientCredentials?: OAuthFlow;
494
+ authorizationCode?: OAuthFlow;
495
+ deviceAuthorization?: OAuthFlow;
496
+ }
497
+ /** oauth2 — flows required. */
498
+ interface OAuth2SecurityScheme {
499
+ type: 'oauth2';
500
+ flows: OAuthFlows;
501
+ oauth2MetadataUrl?: string;
502
+ description?: string;
503
+ deprecated?: boolean;
504
+ }
505
+ /** openIdConnect — openIdConnectUrl required. */
506
+ interface OpenIdConnectSecurityScheme {
507
+ type: 'openIdConnect';
508
+ openIdConnectUrl: string;
509
+ description?: string;
510
+ deprecated?: boolean;
511
+ }
512
+ type SecurityScheme = ApiKeySecurityScheme | HttpSecurityScheme | MutualTlsSecurityScheme | OAuth2SecurityScheme | OpenIdConnectSecurityScheme;
513
+ //#endregion
514
+ //#region src/tag.d.ts
515
+ /** External Documentation Object — url required when present (Swagger 2.0 / OpenAPI 3). */
516
+ interface ExternalDocs {
517
+ url: string;
518
+ description?: string;
519
+ }
520
+ /** Tag Object — metadata for tag used by Operation (OpenAPI 3.x). */
521
+ interface Tag {
522
+ /** **REQUIRED**. Tag name; use in Operation's tags array. */
523
+ name: string;
524
+ /** Short summary for display (OpenAPI 3.1+). */
525
+ summary?: string;
526
+ description?: string;
527
+ externalDocs?: ExternalDocs;
528
+ /** name of a tag this tag is nested under (OpenAPI 3.1+). */
529
+ parent?: string;
530
+ /** Machine-readable category e.g. nav, badge, audience (OpenAPI 3.1+). */
531
+ kind?: string;
532
+ }
533
+ //#endregion
534
+ //#region src/v2.d.ts
535
+ /** Swagger 2.0 root document. Metadata (info, tags, externalDocs, security) uses shared types with OpenAPI 3.x. */
536
+ interface OpenAPISpecificationV2 extends AnyObject {
537
+ /** MUST be "2.0". */
538
+ swagger: '2.0';
539
+ /** API metadata; required. Shared with OpenAPI 3.x (summary/identifier ignored in 2.0). */
540
+ info: Info;
541
+ /** Available paths and operations; required. */
542
+ paths: PathsV2;
543
+ /** Host only (no scheme/path); MAY include port. */
544
+ host?: string;
545
+ /** Path relative to host; MUST start with /. */
546
+ basePath?: string;
547
+ /** "http" | "https" | "ws" | "wss". */
548
+ schemes?: ('http' | 'https' | 'ws' | 'wss')[];
549
+ /** Global MIME types consumed; overridable per operation. */
550
+ consumes?: string[];
551
+ /** Global MIME types produced; overridable per operation. */
552
+ produces?: string[];
553
+ /** Reusable data types (Schema). */
554
+ definitions?: Definitions;
555
+ /** Reusable parameters; reference with #/parameters/name. */
556
+ parameters?: ParametersDefinitions;
557
+ /** Reusable responses; reference with #/responses/name. */
558
+ responses?: ResponsesDefinitions;
559
+ /** Security scheme definitions (2.0-only structure). */
560
+ securityDefinitions?: SecurityDefinitions;
561
+ /** API-wide security (OR between entries). Shared type with OpenAPI 3.x. */
562
+ security?: SecurityRequirement[];
563
+ /** Tag list with metadata. Shared with OpenAPI 3.x (summary/parent/kind ignored in 2.0). */
564
+ tags?: Tag[];
565
+ /** Additional documentation. Shared with OpenAPI 3.x. */
566
+ externalDocs?: ExternalDocs;
567
+ }
568
+ //#endregion
569
+ //#region src/v3.d.ts
570
+ interface OpenAPISpecificationV3 extends AnyObject {
571
+ /** OAS version (e.g. "3.0.0", "3.2.0"). */
572
+ openapi: string;
573
+ /** **REQUIRED**. API metadata. */
574
+ info: Info;
575
+ /** Base URI for this document (OpenAPI 3.1+). */
576
+ $self?: string;
577
+ /** Default $schema for Schema Objects (OpenAPI 3.1+). */
578
+ jsonSchemaDialect?: string;
579
+ /** Connectivity info; default one Server with url: / if absent. */
580
+ servers?: Server[];
581
+ /** Available paths and operations. At least one of paths, webhooks, or components MUST be present. */
582
+ paths?: Paths;
583
+ /** Incoming webhooks the consumer MAY implement; key = unique name, value = Path Item (OpenAPI 3.1+). */
584
+ webhooks?: Paths;
585
+ /** Reusable objects (schemas, parameters, responses, etc.). */
586
+ components?: Components;
587
+ /** API-wide security; OR between entries; operations can override. */
588
+ security?: SecurityRequirement[];
589
+ /** Tags with metadata. */
590
+ tags?: Tag[];
591
+ /** Additional external documentation. */
592
+ externalDocs?: ExternalDocs;
593
+ }
594
+ //#endregion
595
+ export { AnyObject, ApiKeySecurityScheme, Callback, CollectionFormat, Components, type Contact, Definition, Definitions, Example, ExternalDocs, type Header, HeaderV2, HeadersV2, HttpSecurityScheme, type Info, Items, type License, type Link, type MediaType, Method, MutualTlsSecurityScheme, OAuth2Flow, OAuth2SecurityScheme, OAuthFlow, OAuthFlows, OpenAPISpecificationV2, OpenAPISpecificationV3, OpenIdConnectSecurityScheme, OperationV2, Parameter, ParameterStyle, ParametersDefinitions, PathItem, PathItemRefV2, PathItemV2, PathItemV2Ref, Paths, PathsV2, Properties, Reference, RequestBodies, RequestBody, RequestBodyContent, Response, ResponseRef, ResponseV2, ResponseV2Ref, Responses, ResponsesDefinitions, ResponsesV2, Schema, SchemaType, Scopes, Security, SecurityDefinitionScheme, SecurityDefinitions, type SecurityRequirement, SecurityScheme, SecuritySchemeApiKeyV2, SecuritySchemeBasicV2, SecuritySchemeOAuth2V2, SecuritySchemes, Server, ServerVariable, StringObject, Tag };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export { };
package/package.json CHANGED
@@ -1,12 +1,55 @@
1
- {
2
- "name": "openapi-specification-types",
3
- "version": "0.0.4",
4
- "types": "./index.d.ts",
5
- "main": "index.js",
6
- "keywords": [
7
- "openapi",
8
- "types"
9
- ],
10
- "author": "",
11
- "license": "ISC"
12
- }
1
+ {
2
+ "name": "openapi-specification-types",
3
+ "type": "module",
4
+ "version": "0.3.0",
5
+ "description": "TypeScript types for OpenAPI 2.0 and 3.x specifications",
6
+ "author": "hairyf",
7
+ "license": "ISC",
8
+ "homepage": "https://github.com/hairyf/openapi-specification-types#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/hairyf/openapi-specification-types.git"
12
+ },
13
+ "bugs": "https://github.com/hairyf/openapi-specification-types/issues",
14
+ "keywords": [
15
+ "openapi",
16
+ "types",
17
+ "swagger"
18
+ ],
19
+ "exports": {
20
+ ".": "./dist/index.mjs",
21
+ "./package.json": "./package.json"
22
+ },
23
+ "types": "./dist/index.d.mts",
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "devDependencies": {
28
+ "@antfu/eslint-config": "^7.0.0",
29
+ "bumpp": "^10.0.0",
30
+ "eslint": "^9.0.0",
31
+ "lint-staged": "^15.0.0",
32
+ "publint": "^0.3.17",
33
+ "simple-git-hooks": "^2.13.0",
34
+ "skills": "^1.2.3",
35
+ "skills-manifest": "^0.2.1",
36
+ "tsdown": "^0.20.0",
37
+ "typescript": "^5.0.0",
38
+ "vitest": "^2.0.0",
39
+ "vitest-package-exports": "^1.0.0"
40
+ },
41
+ "simple-git-hooks": {
42
+ "pre-commit": "pnpm i --frozen-lockfile --ignore-scripts --offline && npx lint-staged"
43
+ },
44
+ "lint-staged": {
45
+ "*": "eslint --fix"
46
+ },
47
+ "scripts": {
48
+ "build": "tsdown",
49
+ "dev": "tsdown --watch",
50
+ "typecheck": "tsc",
51
+ "test": "vitest --typecheck",
52
+ "lint": "eslint .",
53
+ "release": "bumpp"
54
+ }
55
+ }
package/body.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import { AnyObject } from "./common"
2
- import { Schema } from "./schema"
3
-
4
- export interface RequestBody {
5
- description?: string
6
- content: {
7
- [type: string]: {
8
- schema: Schema
9
- example: AnyObject
10
- examples: Record<string, AnyObject>
11
- encoding: Record<string, AnyObject>
12
- }
13
- }
14
- required?: boolean
15
- }
package/common.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export type StringObject = { [key: string]: string }
2
- export type AnyObject = { [key: string]: any }
3
-
package/components.d.ts DELETED
@@ -1,39 +0,0 @@
1
- import { RequestBody } from './body'
2
- import { StringObject } from './common'
3
- import { Definitions } from './definitions'
4
-
5
- export interface Components {
6
- schemas: Definitions
7
- requestBodies: RequestBodies
8
- }
9
-
10
- export interface RequestBodies {
11
- [name: string]: RequestBody
12
- }
13
-
14
- export interface SecuritySchemes {
15
- [name: string]: SecurityScheme
16
- }
17
-
18
- export interface SecurityScheme {
19
- type: 'apiKey' | 'http' | 'oauth2' | 'openIdConnect'
20
- description: string
21
- name: string
22
- in: 'query' | 'header' | 'cookie'
23
- scheme: string
24
- bearerFormat: string
25
- flows: {
26
- implicit: OAuthFlow
27
- password: OAuthFlow
28
- clientCredentials: OAuthFlow
29
- authorizationCode: OAuthFlow
30
- }
31
- openIdConnectUrl: string
32
- }
33
-
34
- export interface OAuthFlow {
35
- authorizationUrl: string
36
- tokenUrl: string
37
- refreshUrl: string
38
- scopes: StringObject
39
- }
package/definitions.d.ts DELETED
@@ -1,28 +0,0 @@
1
- import { Properties, Schema } from './schema'
2
-
3
- export interface Definition {
4
- type: Schema['type']
5
- properties: Properties
6
- required: string[]
7
- }
8
-
9
- export interface Definitions {
10
- [name: string]: Definition
11
- }
12
-
13
- export interface SecurityDefinitions {
14
- api_key: {
15
- type: string
16
- name: string
17
- in: string
18
- }
19
- petstore_auth: {
20
- type: string
21
- authorizationUrl: string
22
- flow: string
23
- scopes: {
24
- 'read:pets': string
25
- 'write:pets': string
26
- }
27
- }
28
- }
package/index-v2.d.ts DELETED
@@ -1,30 +0,0 @@
1
- import { AnyObject } from './common'
2
- import { Tag } from './tag'
3
- import { Paths } from './paths'
4
- import { Definitions, SecurityDefinitions } from './definitions'
5
-
6
- export interface OpenAPISpecificationV2 extends AnyObject {
7
- swagger: string
8
- host: string
9
- basePath: string
10
- schemes: string[]
11
- consumes: string[]
12
- info: {
13
- description: string
14
- version: string
15
- title: string
16
- termsOfService: string
17
- contact: Record<'name' | 'url' | 'email', string>
18
- license: Record<'name' | 'url', string>
19
- }
20
-
21
- paths: Paths
22
- definitions: Definitions
23
-
24
- securityDefinitions: SecurityDefinitions
25
- tags: Tag[]
26
- externalDocs: {
27
- description: string
28
- url: string
29
- }
30
- }
package/index-v3.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import { AnyObject } from './common'
2
- import { Server } from './server'
3
- import { Tag } from './tag'
4
- import { Paths } from './paths'
5
- import { Components } from './components'
6
-
7
- export interface OpenAPISpecificationV3 extends AnyObject {
8
- openapi: string
9
- info: {
10
- description: string
11
- version: string
12
- title: string
13
- termsOfService: string
14
- contact: Record<'name' | 'url' | 'email', string>
15
- license: Record<'name' | 'url', string>
16
- }
17
- externalDocs: {
18
- description: string
19
- url: string
20
- }
21
- servers: Server[]
22
- tags: Tag[]
23
- paths: Paths
24
- components: Components
25
- }
package/index.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export * from './index-v2'
2
- export * from './index-v2'
3
-
4
- export * from './components'
5
- export * from './definitions'
6
- export * from './parameter'
7
- export * from './paths'
8
- export * from './schema'
9
- export * from './server'
10
- export * from './tag'
11
- export * from './body'
package/parameter.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { Schema } from './schema'
2
-
3
- export interface Parameter extends Schema {
4
- name: string
5
- in: 'body' | 'header' | 'query' | 'path' | 'formData'
6
- type?: Schema['type']
7
- description?: string
8
- required?: boolean
9
- schema?: Schema
10
- }
package/paths.d.ts DELETED
@@ -1,40 +0,0 @@
1
- import { RequestBody } from './body'
2
- import { Parameter } from './parameter'
3
- import { Schema, Properties } from './schema'
4
-
5
- export interface Paths {
6
- [path: string]: {
7
- get: Method
8
- put: Method
9
- post: Method
10
- delete: Method
11
- options: Method
12
- head: Method
13
- patch: Method
14
- parameters: Parameter[]
15
- }
16
- }
17
-
18
- export interface Method {
19
- tags: string[]
20
- summary: string
21
- description: string
22
- operationId: string
23
- consumes: string[]
24
- produces: string[]
25
- parameters: Parameter[]
26
- responses: Responses
27
- security: Security[]
28
- requestBody?: RequestBody
29
- }
30
-
31
- export interface Responses {
32
- [status: number]: {
33
- [type: string]: RequestBody
34
- }
35
- }
36
-
37
- export interface Security {
38
- petstore_auth: string[]
39
- api_key: string[]
40
- }
package/schema.d.ts DELETED
@@ -1,28 +0,0 @@
1
- type SchemaNumberType = 'integer' | 'long' | 'float' | 'byte' | 'TypesLong' | 'TypesString' | 'string'
2
- type SchemaStringType = 'byte' | 'binary' | 'date' | 'dateTime' | 'password'
3
- type SchemaBooleanType = 'boolean'
4
- type SchemaObjectType = 'object'
5
- type SchemaArrayType = 'array'
6
-
7
- type SchemaType = SchemaNumberType | SchemaStringType | SchemaBooleanType | SchemaObjectType | SchemaArrayType
8
-
9
- export interface Schema {
10
- type?: SchemaType | SchemaType[]
11
- items?: Schema
12
- additionalProperties?: Schema
13
- originalRef?: string
14
- $ref?: string
15
- required?: boolean
16
- format?: string
17
- description?: string
18
- schema?: Schema
19
- properties?: Properties
20
- xml?: { wrapped?: boolean }
21
- enum?: string[]
22
- allOf?: Schema[]
23
- example?: string
24
- }
25
-
26
- export interface Properties {
27
- [name: string]: Schema
28
- }
package/server.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export interface Server {
2
- url: string
3
- description: string
4
- variables: Record<string, Variable>
5
- }
6
-
7
- export interface Variable {
8
- enum: string[]
9
- default: string
10
- description: string
11
- }
package/tag.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export interface Tag {
2
- name: string
3
- description: string
4
- externalDocs?: { description: string; url: string }
5
- }