Skip to content

Commit 157cf35

Browse files
openapi-types: support x- specification extensions everywhere without a pre-existing index signature (fixes #768)
1 parent 09fed6d commit 157cf35

File tree

3 files changed

+53
-52
lines changed

3 files changed

+53
-52
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"lerna": "^3.22.1",
4444
"mocha": "10.2.0",
4545
"nyc": "15.1.0",
46-
"prettier": "^2.0.0",
46+
"prettier": "^2.2.0",
4747
"source-map-support": "0.5.17",
4848
"supertest": "4.0.1",
4949
"ts-node": "8.8.2",

packages/openapi-types/index.ts

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
/* tslint:disable:no-namespace no-empty-interface */
22
export namespace OpenAPI {
3+
export type SpecificationExtensionKey = `x-${string}`;
4+
export interface Extensible {
5+
[key: SpecificationExtensionKey]: unknown;
6+
}
7+
38
// OpenAPI extensions can be declared using generics
49
// e.g.:
510
// OpenAPI.Document<{
@@ -268,7 +273,7 @@ export namespace OpenAPIV3_1 {
268273
}
269274

270275
export namespace OpenAPIV3 {
271-
export interface Document<T extends {} = {}> {
276+
export interface Document<T extends {} = {}> extends OpenAPI.Extensible {
272277
openapi: string;
273278
info: InfoObject;
274279
servers?: ServerObject[];
@@ -284,7 +289,7 @@ export namespace OpenAPIV3 {
284289
'x-express-openapi-validation-strict'?: boolean;
285290
}
286291

287-
export interface InfoObject {
292+
export interface InfoObject extends OpenAPI.Extensible {
288293
title: string;
289294
description?: string;
290295
termsOfService?: string;
@@ -293,24 +298,24 @@ export namespace OpenAPIV3 {
293298
version: string;
294299
}
295300

296-
export interface ContactObject {
301+
export interface ContactObject extends OpenAPI.Extensible {
297302
name?: string;
298303
url?: string;
299304
email?: string;
300305
}
301306

302-
export interface LicenseObject {
307+
export interface LicenseObject extends OpenAPI.Extensible {
303308
name: string;
304309
url?: string;
305310
}
306311

307-
export interface ServerObject {
312+
export interface ServerObject extends OpenAPI.Extensible {
308313
url: string;
309314
description?: string;
310315
variables?: { [variable: string]: ServerVariableObject };
311316
}
312317

313-
export interface ServerVariableObject {
318+
export interface ServerVariableObject extends OpenAPI.Extensible {
314319
enum?: string[];
315320
default: string;
316321
description?: string;
@@ -343,7 +348,8 @@ export namespace OpenAPIV3 {
343348
parameters?: (ReferenceObject | ParameterObject)[];
344349
} & {
345350
[method in HttpMethods]?: OperationObject<T>;
346-
};
351+
} &
352+
OpenAPI.Extensible;
347353

348354
export type OperationObject<T extends {} = {}> = {
349355
tags?: string[];
@@ -358,9 +364,10 @@ export namespace OpenAPIV3 {
358364
deprecated?: boolean;
359365
security?: SecurityRequirementObject[];
360366
servers?: ServerObject[];
361-
} & T;
367+
} & T &
368+
OpenAPI.Extensible;
362369

363-
export interface ExternalDocumentationObject {
370+
export interface ExternalDocumentationObject extends OpenAPI.Extensible {
364371
description?: string;
365372
url: string;
366373
}
@@ -372,7 +379,7 @@ export namespace OpenAPIV3 {
372379

373380
export interface HeaderObject extends ParameterBaseObject {}
374381

375-
export interface ParameterBaseObject {
382+
export interface ParameterBaseObject extends OpenAPI.Extensible {
376383
description?: string;
377384
required?: boolean;
378385
deprecated?: boolean;
@@ -403,7 +410,7 @@ export namespace OpenAPIV3 {
403410
type?: NonArraySchemaObjectType;
404411
}
405412

406-
export interface BaseSchemaObject {
413+
export interface BaseSchemaObject extends OpenAPI.Extensible {
407414
// JSON schema allowed properties, adjusted for OpenAPI
408415
title?: string;
409416
description?: string;
@@ -444,46 +451,46 @@ export namespace OpenAPIV3 {
444451
deprecated?: boolean;
445452
}
446453

447-
export interface DiscriminatorObject {
454+
export interface DiscriminatorObject extends OpenAPI.Extensible {
448455
propertyName: string;
449456
mapping?: { [value: string]: string };
450457
}
451458

452-
export interface XMLObject {
459+
export interface XMLObject extends OpenAPI.Extensible {
453460
name?: string;
454461
namespace?: string;
455462
prefix?: string;
456463
attribute?: boolean;
457464
wrapped?: boolean;
458465
}
459466

460-
export interface ReferenceObject {
467+
export interface ReferenceObject extends OpenAPI.Extensible {
461468
$ref: string;
462469
}
463470

464-
export interface ExampleObject {
471+
export interface ExampleObject extends OpenAPI.Extensible {
465472
summary?: string;
466473
description?: string;
467474
value?: any;
468475
externalValue?: string;
469476
}
470477

471-
export interface MediaTypeObject {
478+
export interface MediaTypeObject extends OpenAPI.Extensible {
472479
schema?: ReferenceObject | SchemaObject;
473480
example?: any;
474481
examples?: { [media: string]: ReferenceObject | ExampleObject };
475482
encoding?: { [media: string]: EncodingObject };
476483
}
477484

478-
export interface EncodingObject {
485+
export interface EncodingObject extends OpenAPI.Extensible {
479486
contentType?: string;
480487
headers?: { [header: string]: ReferenceObject | HeaderObject };
481488
style?: string;
482489
explode?: boolean;
483490
allowReserved?: boolean;
484491
}
485492

486-
export interface RequestBodyObject {
493+
export interface RequestBodyObject extends OpenAPI.Extensible {
487494
description?: string;
488495
content: { [media: string]: MediaTypeObject };
489496
required?: boolean;
@@ -493,14 +500,14 @@ export namespace OpenAPIV3 {
493500
[code: string]: ReferenceObject | ResponseObject;
494501
}
495502

496-
export interface ResponseObject {
503+
export interface ResponseObject extends OpenAPI.Extensible {
497504
description: string;
498505
headers?: { [header: string]: ReferenceObject | HeaderObject };
499506
content?: { [media: string]: MediaTypeObject };
500507
links?: { [link: string]: ReferenceObject | LinkObject };
501508
}
502509

503-
export interface LinkObject {
510+
export interface LinkObject extends OpenAPI.Extensible {
504511
operationRef?: string;
505512
operationId?: string;
506513
parameters?: { [parameter: string]: any };
@@ -517,7 +524,7 @@ export namespace OpenAPIV3 {
517524
[name: string]: string[];
518525
}
519526

520-
export interface ComponentsObject {
527+
export interface ComponentsObject extends OpenAPI.Extensible {
521528
schemas?: { [key: string]: ReferenceObject | SchemaObject };
522529
responses?: { [key: string]: ReferenceObject | ResponseObject };
523530
parameters?: { [key: string]: ReferenceObject | ParameterObject };
@@ -535,21 +542,21 @@ export namespace OpenAPIV3 {
535542
| OAuth2SecurityScheme
536543
| OpenIdSecurityScheme;
537544

538-
export interface HttpSecurityScheme {
545+
export interface HttpSecurityScheme extends OpenAPI.Extensible {
539546
type: 'http';
540547
description?: string;
541548
scheme: string;
542549
bearerFormat?: string;
543550
}
544551

545-
export interface ApiKeySecurityScheme {
552+
export interface ApiKeySecurityScheme extends OpenAPI.Extensible {
546553
type: 'apiKey';
547554
description?: string;
548555
name: string;
549556
in: string;
550557
}
551558

552-
export interface OAuth2SecurityScheme {
559+
export interface OAuth2SecurityScheme extends OpenAPI.Extensible {
553560
type: 'oauth2';
554561
description?: string;
555562
flows: {
@@ -577,21 +584,21 @@ export namespace OpenAPIV3 {
577584
};
578585
}
579586

580-
export interface OpenIdSecurityScheme {
587+
export interface OpenIdSecurityScheme extends OpenAPI.Extensible {
581588
type: 'openIdConnect';
582589
description?: string;
583590
openIdConnectUrl: string;
584591
}
585592

586-
export interface TagObject {
593+
export interface TagObject extends OpenAPI.Extensible {
587594
name: string;
588595
description?: string;
589596
externalDocs?: ExternalDocumentationObject;
590597
}
591598
}
592599

593600
export namespace OpenAPIV2 {
594-
export interface Document<T extends {} = {}> {
601+
export interface Document<T extends {} = {}> extends OpenAPI.Extensible {
595602
basePath?: string;
596603
consumes?: MimeTypes;
597604
definitions?: DefinitionsObject;
@@ -614,13 +621,13 @@ export namespace OpenAPIV2 {
614621
'x-express-openapi-validation-strict'?: boolean;
615622
}
616623

617-
export interface TagObject {
624+
export interface TagObject extends OpenAPI.Extensible {
618625
name: string;
619626
description?: string;
620627
externalDocs?: ExternalDocumentationObject;
621628
}
622629

623-
export interface SecuritySchemeObjectBase {
630+
export interface SecuritySchemeObjectBase extends OpenAPI.Extensible {
624631
type: 'basic' | 'apiKey' | 'oauth2';
625632
description?: string;
626633
}
@@ -689,7 +696,7 @@ export namespace OpenAPIV2 {
689696
[index: string]: string[];
690697
}
691698

692-
export interface ReferenceObject {
699+
export interface ReferenceObject extends OpenAPI.Extensible {
693700
$ref: string;
694701
}
695702

@@ -701,7 +708,7 @@ export namespace OpenAPIV2 {
701708

702709
export type Schema = SchemaObject | ReferenceObject;
703710

704-
export interface ResponseObject {
711+
export interface ResponseObject extends OpenAPI.Extensible {
705712
description: string;
706713
schema?: Schema;
707714
headers?: HeadersObject;
@@ -720,13 +727,6 @@ export namespace OpenAPIV2 {
720727
[index: string]: any;
721728
}
722729

723-
export interface ResponseObject {
724-
description: string;
725-
schema?: Schema;
726-
headers?: HeadersObject;
727-
examples?: ExampleObject;
728-
}
729-
730730
export type OperationObject<T extends {} = {}> = {
731731
tags?: string[];
732732
summary?: string;
@@ -740,7 +740,8 @@ export namespace OpenAPIV2 {
740740
schemes?: string[];
741741
deprecated?: boolean;
742742
security?: SecurityRequirementObject[];
743-
} & T;
743+
} & T &
744+
OpenAPI.Extensible;
744745

745746
export interface ResponsesObject {
746747
[index: string]: Response | undefined;
@@ -802,7 +803,7 @@ export namespace OpenAPIV2 {
802803
[index: string]: SchemaObject;
803804
}
804805

805-
export interface SchemaObject extends IJsonSchema {
806+
export interface SchemaObject extends IJsonSchema, OpenAPI.Extensible {
806807
[index: string]: any;
807808
discriminator?: string;
808809
readOnly?: boolean;
@@ -822,7 +823,7 @@ export namespace OpenAPIV2 {
822823
url: string;
823824
}
824825

825-
export interface ItemsObject {
826+
export interface ItemsObject extends OpenAPI.Extensible {
826827
type: string;
827828
format?: string;
828829
items?: ItemsObject | ReferenceObject;
@@ -852,7 +853,7 @@ export namespace OpenAPIV2 {
852853
wrapped?: boolean;
853854
}
854855

855-
export interface InfoObject {
856+
export interface InfoObject extends OpenAPI.Extensible {
856857
title: string;
857858
description?: string;
858859
termsOfService?: string;
@@ -861,13 +862,13 @@ export namespace OpenAPIV2 {
861862
version: string;
862863
}
863864

864-
export interface ContactObject {
865+
export interface ContactObject extends OpenAPI.Extensible {
865866
name?: string;
866867
url?: string;
867868
email?: string;
868869
}
869870

870-
export interface LicenseObject {
871+
export interface LicenseObject extends OpenAPI.Extensible {
871872
name: string;
872873
url?: string;
873874
}

0 commit comments

Comments
 (0)