1
1
import Ajv , { ValidateFunction } from 'ajv' ;
2
- import { createRequestAjv } from '../framework/ajv' ;
3
- import {
4
- ContentType ,
5
- ajvErrorsToValidatorError ,
6
- augmentAjvErrors ,
7
- } from './util' ;
8
2
import { NextFunction , RequestHandler , Response } from 'express' ;
3
+ import { createRequestAjv } from '../framework/ajv' ;
9
4
import {
5
+ BadRequest ,
6
+ BodySchema ,
7
+ NotFound ,
10
8
OpenAPIV3 ,
11
9
OpenApiRequest ,
12
- RequestValidatorOptions ,
13
- ValidateRequestOpts ,
14
10
OpenApiRequestMetadata ,
15
- NotFound ,
16
- BadRequest ,
17
11
ParametersSchema ,
18
- BodySchema ,
12
+ RequestValidatorOptions ,
13
+ ValidateRequestOpts ,
19
14
ValidationSchema ,
20
15
} from '../framework/types' ;
21
16
import { BodySchemaParser } from './parsers/body.parse' ;
22
- import { ParametersSchemaParser } from './parsers/schema.parse' ;
23
17
import { RequestParameterMutator } from './parsers/req.parameter.mutator' ;
18
+ import { ParametersSchemaParser } from './parsers/schema.parse' ;
19
+ import {
20
+ ContentType ,
21
+ ajvErrorsToValidatorError ,
22
+ augmentAjvErrors ,
23
+ } from './util' ;
24
24
25
25
type OperationObject = OpenAPIV3 . OperationObject ;
26
26
type SchemaObject = OpenAPIV3 . SchemaObject ;
@@ -140,6 +140,12 @@ export class RequestValidator {
140
140
req . params = openapi . pathParams ?? req . params ;
141
141
}
142
142
143
+ // HACK for express 5, temporarily make req.query mutable
144
+ const reqQueryDescriptor = Object . getOwnPropertyDescriptor ( req , 'query' ) ;
145
+ Object . defineProperty ( req , 'query' , {
146
+ writable : true ,
147
+ value : req . query ,
148
+ } )
143
149
const schemaProperties = validator . allSchemaProperties ;
144
150
const mutator = new RequestParameterMutator (
145
151
this . ajv ,
@@ -158,6 +164,11 @@ export class RequestValidator {
158
164
) ;
159
165
}
160
166
167
+ // HACK for express 5, Restore the original descriptor
168
+ if ( reqQueryDescriptor ) {
169
+ Object . defineProperty ( req , 'query' , reqQueryDescriptor ) ;
170
+ }
171
+
161
172
const cookies = req . cookies
162
173
? {
163
174
...req . cookies ,
0 commit comments