@@ -123,15 +123,27 @@ async function exposeRoutes(
123
123
const method : fastify . HTTPMethods = ( operation . route ?. method . toUpperCase ( ) ||
124
124
'GET' ) as fastify . HTTPMethods ;
125
125
const { url = '' } = operation . route || { } ;
126
- const requestSchema =
127
- operation . route ?. schema && operation . requestValidationEnabled
128
- ? {
129
- body : operation . route ?. schema . body ,
130
- params : operation . route ?. schema . params ,
131
- headers : operation . route ?. schema . headers ,
132
- querystring : operation . route ?. schema . querystring
133
- }
134
- : { } ;
126
+ const requestSchema : any = { } ;
127
+ // Avoid defining the request schema member as undefined
128
+ // to prevent https://github.com/fastify/fastify/issues/4634
129
+ if ( operation . route ?. schema && operation . requestValidationEnabled ) {
130
+ if ( operation . route ?. schema . body ) {
131
+ requestSchema . body = operation . route ?. schema . body ;
132
+ }
133
+
134
+ if ( operation . route ?. schema . params ) {
135
+ requestSchema . params = operation . route ?. schema . params ;
136
+ }
137
+
138
+ if ( operation . route ?. schema . headers ) {
139
+ requestSchema . headers = operation . route ?. schema . headers ;
140
+ }
141
+
142
+ if ( operation . route ?. schema . querystring ) {
143
+ requestSchema . querystring = operation . route ?. schema . querystring ;
144
+ }
145
+ }
146
+
135
147
const responseSchema = operation . route ?. schema
136
148
? { response : operation . route ?. schema . response }
137
149
: { } ;
0 commit comments