File tree 2 files changed +35
-15
lines changed
2 files changed +35
-15
lines changed Original file line number Diff line number Diff line change @@ -113,8 +113,26 @@ export type SerDesMap = {
113
113
[ format : string ] : SerDes
114
114
} ;
115
115
116
+ type Primitive = undefined | null | boolean | string | number | Function
117
+
118
+ type Immutable < T > =
119
+ T extends Primitive ? T :
120
+ T extends Array < infer U > ? ReadonlyArray < U > :
121
+ T extends Map < infer K , infer V > ? ReadonlyMap < K , V > : Readonly < T >
122
+
123
+ type DeepImmutable < T > =
124
+ T extends Primitive ? T :
125
+ T extends Array < infer U > ? DeepImmutableArray < U > :
126
+ T extends Map < infer K , infer V > ? DeepImmutableMap < K , V > : DeepImmutableObject < T >
127
+
128
+ interface DeepImmutableArray < T > extends ReadonlyArray < DeepImmutable < T > > { }
129
+ interface DeepImmutableMap < K , V > extends ReadonlyMap < DeepImmutable < K > , DeepImmutable < V > > { }
130
+ type DeepImmutableObject < T > = {
131
+ readonly [ K in keyof T ] : DeepImmutable < T [ K ] >
132
+ }
133
+
116
134
export interface OpenApiValidatorOpts {
117
- apiSpec : OpenAPIV3 . Document | string ;
135
+ apiSpec : DeepImmutable < OpenAPIV3 . Document > | string ;
118
136
validateApiSpec ?: boolean ;
119
137
validateResponses ?: boolean | ValidateResponseOpts ;
120
138
validateRequests ?: boolean | ValidateRequestOpts ;
Original file line number Diff line number Diff line change @@ -4,27 +4,29 @@ import { expect } from 'chai';
4
4
import * as request from 'supertest' ;
5
5
import * as path from 'path' ;
6
6
7
+ const schema = {
8
+ openapi : '3.0.0' ,
9
+ info : { version : '1.0.0' , title : 'test bug OpenApiValidator' } ,
10
+ servers : [ ] ,
11
+ paths : {
12
+ '/' : {
13
+ get : {
14
+ operationId : 'anything' ,
15
+ 'x-eov-operation-handler' : 'controller-with-default' ,
16
+ responses : { 200 : { description : 'home api' } }
17
+ }
18
+ } ,
19
+ } ,
20
+ } as const ;
21
+
7
22
describe ( 'default export resolver' , ( ) => {
8
23
let server = null ;
9
24
let app = express ( ) ;
10
25
11
26
before ( async ( ) => {
12
27
app . use (
13
28
OpenApiValidator . middleware ( {
14
- apiSpec : {
15
- openapi : '3.0.0' ,
16
- info : { version : '1.0.0' , title : 'test bug OpenApiValidator' } ,
17
- paths : {
18
- '/' : {
19
- get : {
20
- operationId : 'anything' ,
21
- // @ts -ignore
22
- 'x-eov-operation-handler' : 'controller-with-default' ,
23
- responses : { 200 : { description : 'home api' } }
24
- }
25
- } ,
26
- } ,
27
- } ,
29
+ apiSpec : schema ,
28
30
operationHandlers : path . join ( __dirname , 'resources' ) ,
29
31
} ) ,
30
32
) ;
You can’t perform that action at this time.
0 commit comments