2828 // build our application with a route
2929 Router :: new ( )
3030 . route ( "/" , post ( foo :: < I , A , E > ) )
31- . route ( "/issue21143" , post ( i21143 :: < I , A , E > ) )
31+ . route ( "/issue21143_1" , post ( i211431 :: < I , A , E > ) )
32+ . route ( "/issue21143_2" , post ( i211432 :: < I , A , E > ) )
33+ . route ( "/issue21143_3" , post ( i211433 :: < I , A , E > ) )
3234 . with_state ( api_impl)
3335}
3436
@@ -117,20 +119,20 @@ where
117119
118120#[ derive( validator:: Validate ) ]
119121#[ allow( dead_code) ]
120- struct I21143BodyValidator < ' a > {
122+ struct I211431BodyValidator < ' a > {
121123 body : & ' a Vec < i32 > ,
122124}
123125
124126#[ tracing:: instrument( skip_all) ]
125- fn i21143_validation ( body : Vec < i32 > ) -> std:: result:: Result < ( Vec < i32 > , ) , ValidationErrors > {
126- let b = I21143BodyValidator { body : & body } ;
127+ fn i211431_validation ( body : Vec < i32 > ) -> std:: result:: Result < ( Vec < i32 > , ) , ValidationErrors > {
128+ let b = I211431BodyValidator { body : & body } ;
127129 b. validate ( ) ?;
128130
129131 Ok ( ( body, ) )
130132}
131- /// I21143 - POST /issue21143
133+ /// I211431 - POST /issue21143_1
132134#[ tracing:: instrument( skip_all) ]
133- async fn i21143 < I , A , E > (
135+ async fn i211431 < I , A , E > (
134136 method : Method ,
135137 host : Host ,
136138 cookies : CookieJar ,
@@ -143,7 +145,7 @@ where
143145 E : std:: fmt:: Debug + Send + Sync + ' static ,
144146{
145147 #[ allow( clippy:: redundant_closure) ]
146- let validation = tokio:: task:: spawn_blocking ( move || i21143_validation ( body) )
148+ let validation = tokio:: task:: spawn_blocking ( move || i211431_validation ( body) )
147149 . await
148150 . unwrap ( ) ;
149151
@@ -156,14 +158,181 @@ where
156158
157159 let result = api_impl
158160 . as_ref ( )
159- . i21143 ( & method, & host, & cookies, & body)
161+ . i211431 ( & method, & host, & cookies, & body)
160162 . await ;
161163
162164 let mut response = Response :: builder ( ) ;
163165
164166 let resp = match result {
165167 Ok ( rsp) => match rsp {
166- apis:: default:: I21143Response :: Status200_Re ( body) => {
168+ apis:: default:: I211431Response :: Status200_Re ( body) => {
169+ let mut response = response. status ( 200 ) ;
170+ {
171+ let mut response_headers = response. headers_mut ( ) . unwrap ( ) ;
172+ response_headers
173+ . insert ( CONTENT_TYPE , HeaderValue :: from_static ( "application/json" ) ) ;
174+ }
175+
176+ let body_content = tokio:: task:: spawn_blocking ( move || {
177+ serde_json:: to_vec ( & body) . map_err ( |e| {
178+ error ! ( error = ?e) ;
179+ StatusCode :: INTERNAL_SERVER_ERROR
180+ } )
181+ } )
182+ . await
183+ . unwrap ( ) ?;
184+ response. body ( Body :: from ( body_content) )
185+ }
186+ } ,
187+ Err ( why) => {
188+ // Application code returned an error. This should not happen, as the implementation should
189+ // return a valid response.
190+ return api_impl
191+ . as_ref ( )
192+ . handle_error ( & method, & host, & cookies, why)
193+ . await ;
194+ }
195+ } ;
196+
197+ resp. map_err ( |e| {
198+ error ! ( error = ?e) ;
199+ StatusCode :: INTERNAL_SERVER_ERROR
200+ } )
201+ }
202+
203+ #[ derive( validator:: Validate ) ]
204+ #[ allow( dead_code) ]
205+ struct I211432BodyValidator < ' a > {
206+ #[ validate( custom( function = "check_xss_string" ) ) ]
207+ body : & ' a String ,
208+ }
209+
210+ #[ tracing:: instrument( skip_all) ]
211+ fn i211432_validation ( body : String ) -> std:: result:: Result < ( String , ) , ValidationErrors > {
212+ let b = I211432BodyValidator { body : & body } ;
213+ b. validate ( ) ?;
214+
215+ Ok ( ( body, ) )
216+ }
217+ /// I211432 - POST /issue21143_2
218+ #[ tracing:: instrument( skip_all) ]
219+ async fn i211432 < I , A , E > (
220+ method : Method ,
221+ host : Host ,
222+ cookies : CookieJar ,
223+ State ( api_impl) : State < I > ,
224+ Json ( body) : Json < String > ,
225+ ) -> Result < Response , StatusCode >
226+ where
227+ I : AsRef < A > + Send + Sync ,
228+ A : apis:: default:: Default < E > + Send + Sync ,
229+ E : std:: fmt:: Debug + Send + Sync + ' static ,
230+ {
231+ #[ allow( clippy:: redundant_closure) ]
232+ let validation = tokio:: task:: spawn_blocking ( move || i211432_validation ( body) )
233+ . await
234+ . unwrap ( ) ;
235+
236+ let Ok ( ( body, ) ) = validation else {
237+ return Response :: builder ( )
238+ . status ( StatusCode :: BAD_REQUEST )
239+ . body ( Body :: from ( validation. unwrap_err ( ) . to_string ( ) ) )
240+ . map_err ( |_| StatusCode :: BAD_REQUEST ) ;
241+ } ;
242+
243+ let result = api_impl
244+ . as_ref ( )
245+ . i211432 ( & method, & host, & cookies, & body)
246+ . await ;
247+
248+ let mut response = Response :: builder ( ) ;
249+
250+ let resp = match result {
251+ Ok ( rsp) => match rsp {
252+ apis:: default:: I211432Response :: Status200_Re ( body) => {
253+ let mut response = response. status ( 200 ) ;
254+ {
255+ let mut response_headers = response. headers_mut ( ) . unwrap ( ) ;
256+ response_headers
257+ . insert ( CONTENT_TYPE , HeaderValue :: from_static ( "application/json" ) ) ;
258+ }
259+
260+ let body_content = tokio:: task:: spawn_blocking ( move || {
261+ serde_json:: to_vec ( & body) . map_err ( |e| {
262+ error ! ( error = ?e) ;
263+ StatusCode :: INTERNAL_SERVER_ERROR
264+ } )
265+ } )
266+ . await
267+ . unwrap ( ) ?;
268+ response. body ( Body :: from ( body_content) )
269+ }
270+ } ,
271+ Err ( why) => {
272+ // Application code returned an error. This should not happen, as the implementation should
273+ // return a valid response.
274+ return api_impl
275+ . as_ref ( )
276+ . handle_error ( & method, & host, & cookies, why)
277+ . await ;
278+ }
279+ } ;
280+
281+ resp. map_err ( |e| {
282+ error ! ( error = ?e) ;
283+ StatusCode :: INTERNAL_SERVER_ERROR
284+ } )
285+ }
286+
287+ #[ derive( validator:: Validate ) ]
288+ #[ allow( dead_code) ]
289+ struct I211433BodyValidator < ' a > {
290+ body : & ' a i32 ,
291+ }
292+
293+ #[ tracing:: instrument( skip_all) ]
294+ fn i211433_validation ( body : i32 ) -> std:: result:: Result < ( i32 , ) , ValidationErrors > {
295+ let b = I211433BodyValidator { body : & body } ;
296+ b. validate ( ) ?;
297+
298+ Ok ( ( body, ) )
299+ }
300+ /// I211433 - POST /issue21143_3
301+ #[ tracing:: instrument( skip_all) ]
302+ async fn i211433 < I , A , E > (
303+ method : Method ,
304+ host : Host ,
305+ cookies : CookieJar ,
306+ State ( api_impl) : State < I > ,
307+ Json ( body) : Json < i32 > ,
308+ ) -> Result < Response , StatusCode >
309+ where
310+ I : AsRef < A > + Send + Sync ,
311+ A : apis:: default:: Default < E > + Send + Sync ,
312+ E : std:: fmt:: Debug + Send + Sync + ' static ,
313+ {
314+ #[ allow( clippy:: redundant_closure) ]
315+ let validation = tokio:: task:: spawn_blocking ( move || i211433_validation ( body) )
316+ . await
317+ . unwrap ( ) ;
318+
319+ let Ok ( ( body, ) ) = validation else {
320+ return Response :: builder ( )
321+ . status ( StatusCode :: BAD_REQUEST )
322+ . body ( Body :: from ( validation. unwrap_err ( ) . to_string ( ) ) )
323+ . map_err ( |_| StatusCode :: BAD_REQUEST ) ;
324+ } ;
325+
326+ let result = api_impl
327+ . as_ref ( )
328+ . i211433 ( & method, & host, & cookies, & body)
329+ . await ;
330+
331+ let mut response = Response :: builder ( ) ;
332+
333+ let resp = match result {
334+ Ok ( rsp) => match rsp {
335+ apis:: default:: I211433Response :: Status200_Re ( body) => {
167336 let mut response = response. status ( 200 ) ;
168337 {
169338 let mut response_headers = response. headers_mut ( ) . unwrap ( ) ;
0 commit comments