7
7
* We deal with user input and can’t assume they really stick to any official specification.
8
8
*/
9
9
10
+ /** any other attribute, for example x-* extensions */
11
+ type AnyOtherAttribute = {
12
+ /** OpenAPI extension */
13
+ [ customExtension : `x-${string } `] : any
14
+ /** Unknown attribute */
15
+ [ key : string ] : any
16
+ }
17
+
10
18
export namespace OpenAPI {
11
19
// OpenAPI extensions can be declared using generics
12
20
// e.g.:
13
21
// OpenAPI.Document<{
14
22
// 'x-foobar': Foobar
15
23
// }>
16
- export type Document <
17
- T extends {
18
- // any other attribute
19
- [ key : string ] : any
20
- } = { } ,
21
- > = OpenAPIV2 . Document < T > | OpenAPIV3 . Document < T > | OpenAPIV3_1 . Document < T >
22
-
23
- export type Operation < T extends { } = { } > =
24
+ export type Document < T extends AnyOtherAttribute = { } > =
25
+ | OpenAPIV2 . Document < T >
26
+ | OpenAPIV3 . Document < T >
27
+ | OpenAPIV3_1 . Document < T >
28
+
29
+ export type Operation < T = { } > =
24
30
| OpenAPIV2 . OperationObject < T >
25
31
| OpenAPIV3 . OperationObject < T >
26
32
| OpenAPIV3_1 . OperationObject < T >
@@ -64,20 +70,20 @@ export namespace OpenAPI {
64
70
export namespace OpenAPIV3_1 {
65
71
type Modify < T , R > = Omit < T , keyof R > & R
66
72
67
- type PathsWebhooksComponents < T extends { } = { } > = {
73
+ type PathsWebhooksComponents < T = { } > = {
68
74
paths ?: PathsObject < T >
69
75
webhooks ?: Record < string , PathItemObject | ReferenceObject >
70
76
components ?: ComponentsObject
71
77
}
72
78
73
- export type Document < T extends { } = { } > = Modify <
79
+ export type Document < T = { } > = Modify <
74
80
Omit < OpenAPIV3 . Document < T > , 'paths' | 'components' > ,
75
81
{
76
82
/**
77
83
* Version of the OpenAPI specification
78
84
* @see https://github.com/OAI/OpenAPI-Specification/tree/main/versions
79
85
*/
80
- openapi : '3.1.0'
86
+ openapi ? : '3.1.0'
81
87
info ?: InfoObject
82
88
jsonSchemaDialect ?: string
83
89
servers ?: ServerObject [ ]
@@ -88,7 +94,9 @@ export namespace OpenAPIV3_1 {
88
94
Omit < Partial < PathsWebhooksComponents < T > > , 'webhooks' > )
89
95
| ( Pick < PathsWebhooksComponents < T > , 'components' > &
90
96
Omit < Partial < PathsWebhooksComponents < T > > , 'components' > )
91
- )
97
+ ) &
98
+ T &
99
+ AnyOtherAttribute
92
100
>
93
101
94
102
export type InfoObject = Modify <
@@ -124,14 +132,14 @@ export namespace OpenAPIV3_1 {
124
132
}
125
133
>
126
134
127
- export type PathsObject < T extends { } = { } , P extends { } = { } > = Record <
135
+ export type PathsObject < T = { } , P extends { } = { } > = Record <
128
136
string ,
129
137
( PathItemObject < T > & P ) | undefined
130
138
>
131
139
132
140
export type HttpMethods = OpenAPIV3 . HttpMethods
133
141
134
- export type PathItemObject < T extends { } = { } > = Modify <
142
+ export type PathItemObject < T = { } > = Modify <
135
143
OpenAPIV3 . PathItemObject < T > ,
136
144
{
137
145
servers ?: ServerObject [ ]
@@ -141,7 +149,7 @@ export namespace OpenAPIV3_1 {
141
149
[ method in HttpMethods ] ?: OperationObject < T >
142
150
}
143
151
144
- export type OperationObject < T extends { } = { } > = Modify <
152
+ export type OperationObject < T = { } > = Modify <
145
153
OpenAPIV3 . OperationObject < T > ,
146
154
{
147
155
parameters ?: ( ReferenceObject | ParameterObject ) [ ]
@@ -173,11 +181,13 @@ export namespace OpenAPIV3_1 {
173
181
* 'items' will be always visible as optional
174
182
* Casting schema object to ArraySchemaObject or NonArraySchemaObject will work fine
175
183
*/
176
- export type SchemaObject =
184
+ export type SchemaObject = (
177
185
| ArraySchemaObject
178
186
| NonArraySchemaObject
179
187
| MixedSchemaObject
180
188
| boolean
189
+ ) &
190
+ AnyOtherAttribute
181
191
182
192
export interface ArraySchemaObject extends BaseSchemaObject {
183
193
type ?: ArraySchemaObjectType
@@ -299,8 +309,7 @@ export namespace OpenAPIV3_1 {
299
309
}
300
310
301
311
export namespace OpenAPIV3 {
302
- export interface Document < T extends { } = { } > {
303
- [ propName : string ] : any
312
+ export type Document < T = { } > = {
304
313
/**
305
314
* Version of the OpenAPI specification
306
315
* @see https://github.com/OAI/OpenAPI-Specification/tree/main/versions
@@ -313,7 +322,8 @@ export namespace OpenAPIV3 {
313
322
security ?: SecurityRequirementObject [ ]
314
323
tags ?: TagObject [ ]
315
324
externalDocs ?: ExternalDocumentationObject
316
- }
325
+ } & T &
326
+ AnyOtherAttribute
317
327
318
328
export interface InfoObject {
319
329
title ?: string
@@ -347,7 +357,7 @@ export namespace OpenAPIV3 {
347
357
description ?: string
348
358
}
349
359
350
- export interface PathsObject < T extends { } = { } , P extends { } = { } > {
360
+ export interface PathsObject < T = { } , P extends { } = { } > {
351
361
[ pattern : string ] : ( PathItemObject < T > & P ) | undefined
352
362
}
353
363
@@ -366,19 +376,19 @@ export namespace OpenAPIV3 {
366
376
TRACE = 'trace' ,
367
377
}
368
378
369
- export type PathItemObject < T extends { } = { } > = {
379
+ export type PathItemObject < T = { } > = {
370
380
$ref ?: string
371
381
summary ?: string
372
382
description ?: string
373
383
servers ?: ServerObject [ ]
374
384
parameters ?: ( ReferenceObject | ParameterObject ) [ ]
375
385
} & {
376
386
[ method in HttpMethods ] ?: OperationObject < T >
377
- }
387
+ } & T &
388
+ AnyOtherAttribute
378
389
379
- export type OperationObject < T extends { } = { } > = {
390
+ export type OperationObject < T = { } > = {
380
391
tags ?: string [ ]
381
- [ key : string ] : any
382
392
summary ?: string
383
393
description ?: string
384
394
externalDocs ?: ExternalDocumentationObject
@@ -390,7 +400,8 @@ export namespace OpenAPIV3 {
390
400
deprecated ?: boolean
391
401
security ?: SecurityRequirementObject [ ]
392
402
servers ?: ServerObject [ ]
393
- } & T
403
+ } & T &
404
+ AnyOtherAttribute
394
405
395
406
export interface ExternalDocumentationObject {
396
407
description ?: string
@@ -424,7 +435,8 @@ export namespace OpenAPIV3 {
424
435
| 'string'
425
436
| 'integer'
426
437
export type ArraySchemaObjectType = 'array'
427
- export type SchemaObject = ArraySchemaObject | NonArraySchemaObject
438
+ export type SchemaObject = ( ArraySchemaObject | NonArraySchemaObject ) &
439
+ AnyOtherAttribute
428
440
429
441
export interface ArraySchemaObject extends BaseSchemaObject {
430
442
type ?: ArraySchemaObjectType
@@ -489,9 +501,8 @@ export namespace OpenAPIV3 {
489
501
wrapped ?: boolean
490
502
}
491
503
492
- export interface ReferenceObject {
504
+ export interface ReferenceObject extends AnyOtherAttribute {
493
505
$ref ?: string
494
- [ key : string ] : any
495
506
}
496
507
497
508
export interface ExampleObject {
@@ -526,12 +537,11 @@ export namespace OpenAPIV3 {
526
537
[ code : string ] : ReferenceObject | ResponseObject
527
538
}
528
539
529
- export interface ResponseObject {
540
+ export interface ResponseObject extends AnyOtherAttribute {
530
541
description ?: string
531
542
headers ?: { [ header : string ] : ReferenceObject | HeaderObject }
532
543
content ?: { [ media : string ] : MediaTypeObject }
533
544
links ?: { [ link : string ] : ReferenceObject | LinkObject }
534
- [ key : string ] : any
535
545
}
536
546
537
547
export interface LinkObject {
@@ -617,19 +627,20 @@ export namespace OpenAPIV3 {
617
627
openIdConnectUrl ?: string
618
628
}
619
629
620
- export interface TagObject {
630
+ export interface TagObject extends AnyOtherAttribute {
621
631
name ?: string
622
632
description ?: string
623
633
externalDocs ?: ExternalDocumentationObject
624
- [ key : string ] : any
625
634
}
626
635
}
627
636
628
637
export namespace OpenAPIV2 {
629
- export interface Document < T extends { } = { } > {
630
- [ propName : string ] : any
631
- /** To make it easier to use openapi as a type guard */
632
- openapi : undefined
638
+ export type Document < T = { } > = {
639
+ /**
640
+ * Version of the OpenAPI specification
641
+ * @see https://github.com/OAI/OpenAPI-Specification/tree/main/versions
642
+ */
643
+ swagger ?: '2.0'
633
644
basePath ?: string
634
645
consumes ?: MimeTypes
635
646
definitions ?: DefinitionsObject
@@ -643,19 +654,15 @@ export namespace OpenAPIV2 {
643
654
schemes ?: string [ ]
644
655
security ?: SecurityRequirementObject [ ]
645
656
securityDefinitions ?: SecurityDefinitionsObject
646
- /**
647
- * Version of the OpenAPI specification
648
- * @see https://github.com/OAI/OpenAPI-Specification/tree/main/versions
649
- */
650
- swagger ?: '2.0'
651
657
tags ?: TagObject [ ]
652
- }
658
+ [ key : string ] : any
659
+ } & T &
660
+ AnyOtherAttribute
653
661
654
- export interface TagObject {
662
+ export interface TagObject extends AnyOtherAttribute {
655
663
name ?: string
656
664
description ?: string
657
665
externalDocs ?: ExternalDocumentationObject
658
- [ key : string ] : any
659
666
}
660
667
661
668
export interface SecuritySchemeObjectBase {
@@ -727,9 +734,8 @@ export namespace OpenAPIV2 {
727
734
[ index : string ] : string [ ]
728
735
}
729
736
730
- export interface ReferenceObject {
737
+ export interface ReferenceObject extends AnyOtherAttribute {
731
738
$ref : string
732
- [ key : string ] : any
733
739
}
734
740
735
741
export type Response = ResponseObject | ReferenceObject
@@ -740,12 +746,11 @@ export namespace OpenAPIV2 {
740
746
741
747
export type Schema = SchemaObject | ReferenceObject
742
748
743
- export interface ResponseObject {
749
+ export interface ResponseObject extends AnyOtherAttribute {
744
750
description ?: string
745
751
schema ?: Schema
746
752
headers ?: HeadersObject
747
753
examples ?: ExampleObject
748
- [ key : string ] : any
749
754
}
750
755
751
756
export interface HeadersObject {
@@ -760,9 +765,8 @@ export namespace OpenAPIV2 {
760
765
[ index : string ] : any
761
766
}
762
767
763
- export type OperationObject < T extends { } = { } > = {
768
+ export type OperationObject < T = { } > = {
764
769
tags ?: string [ ]
765
- [ key : string ] : any
766
770
summary ?: string
767
771
description ?: string
768
772
externalDocs ?: ExternalDocumentationObject
@@ -774,7 +778,8 @@ export namespace OpenAPIV2 {
774
778
schemes ?: string [ ]
775
779
deprecated ?: boolean
776
780
security ?: SecurityRequirementObject [ ]
777
- } & T
781
+ } & T &
782
+ AnyOtherAttribute
778
783
779
784
export interface ResponsesObject {
780
785
[ index : string ] : Response | undefined
@@ -807,14 +812,14 @@ export namespace OpenAPIV2 {
807
812
PATCH = 'patch' ,
808
813
}
809
814
810
- export type PathItemObject < T extends { } = { } > = {
815
+ export type PathItemObject < T = { } > = {
811
816
$ref ?: string
812
817
parameters ?: Parameters
813
818
} & {
814
819
[ method in HttpMethods ] ?: OperationObject < T >
815
820
}
816
821
817
- export interface PathsObject < T extends { } = { } > {
822
+ export interface PathsObject < T = { } > {
818
823
[ index : string ] : PathItemObject < T >
819
824
}
820
825
@@ -907,7 +912,7 @@ export namespace OpenAPIV2 {
907
912
}
908
913
}
909
914
910
- export interface IJsonSchema {
915
+ export interface IJsonSchema extends AnyOtherAttribute {
911
916
id ?: string
912
917
$schema ?: string
913
918
title ?: string
0 commit comments