@@ -197,7 +197,10 @@ impl RequestBodyParams {
197197 }
198198
199199 pub fn get_default_request_body_param ( & self ) -> Option < & Vec < Param > > {
200- self . params . values ( ) . next ( ) . filter ( |_| self . has_single_content_type ( ) )
200+ self . params
201+ . values ( )
202+ . next ( )
203+ . filter ( |_| self . has_single_content_type ( ) )
201204 }
202205}
203206
@@ -324,38 +327,47 @@ fn request_body_params(
324327 body : & ReferenceOr < RequestBody > ,
325328 ref_cache : & mut RefCache ,
326329) -> Result < RequestBodyParams > {
327-
328330 let mut content_type_params = HashMap :: new ( ) ;
329331
330332 match body {
331- ReferenceOr :: Reference { reference } => return Err ( Error :: unimplemented ( format ! (
332- "Unexpected ref request body: '{reference}'."
333- ) ) ) ,
333+ ReferenceOr :: Reference { reference } => {
334+ return Err ( Error :: unimplemented ( format ! (
335+ "Unexpected ref request body: '{reference}'."
336+ ) ) )
337+ }
334338 ReferenceOr :: Item ( body) => {
335- for ( content_type, media_type) in & body. content {
336-
339+ for ( content_type, media_type) in & body. content {
337340 if content_type. starts_with ( "application/json" ) {
338341 let schema = match & media_type. schema {
339342 None => Err ( Error :: unimplemented ( "JSON content without schema." ) ) ,
340343 Some ( schema) => Ok ( schema) ,
341344 } ;
342345
343- content_type_params. insert ( ContentType ( content_type. clone ( ) ) , vec ! [ Param {
344- original_name: "" . to_string( ) ,
345- name: "value" . to_string( ) ,
346- tpe: ref_or_schema_type( schema?, ref_cache, Some ( content_type. clone( ) ) ) ?,
347- required: body. required,
348- kind: ParamKind :: Body ,
349- } ] ) ;
346+ content_type_params. insert (
347+ ContentType ( content_type. clone ( ) ) ,
348+ vec ! [ Param {
349+ original_name: "" . to_string( ) ,
350+ name: "value" . to_string( ) ,
351+ tpe: ref_or_schema_type(
352+ schema?,
353+ ref_cache,
354+ Some ( content_type. clone( ) ) ,
355+ ) ?,
356+ required: body. required,
357+ kind: ParamKind :: Body ,
358+ } ] ,
359+ ) ;
350360 } else if content_type == "application/octet-stream" {
351- content_type_params. insert ( ContentType ( content_type. clone ( ) ) , vec ! [ Param {
352- original_name: "" . to_string( ) ,
353- name: "value" . to_string( ) ,
354- tpe: DataType :: Binary ,
355- required: body. required,
356- kind: ParamKind :: Body ,
357- } ] ) ;
358-
361+ content_type_params. insert (
362+ ContentType ( content_type. clone ( ) ) ,
363+ vec ! [ Param {
364+ original_name: "" . to_string( ) ,
365+ name: "value" . to_string( ) ,
366+ tpe: DataType :: Binary ,
367+ required: body. required,
368+ kind: ParamKind :: Body ,
369+ } ] ,
370+ ) ;
359371 } else if content_type == "application/x-yaml" {
360372 let schema = match & media_type. schema {
361373 None => Err ( Error :: unimplemented ( "YAML content without schema." ) ) ,
@@ -371,14 +383,17 @@ fn request_body_params(
371383 } ;
372384
373385 content_type_params. insert ( ContentType ( content_type. clone ( ) ) , vec ! [ param] ) ;
374-
375386 } else if content_type == "multipart/form-data" {
376387 match & media_type. schema {
377- None => return Err ( Error :: unimplemented ( "Multipart content without schema." ) ) ,
388+ None => {
389+ return Err ( Error :: unimplemented ( "Multipart content without schema." ) )
390+ }
378391 Some ( schema) => match schema {
379- ReferenceOr :: Reference { reference } => return Err ( Error :: unimplemented ( format ! (
380- "Unexpected ref multipart schema: '{reference}'."
381- ) ) ) ,
392+ ReferenceOr :: Reference { reference } => {
393+ return Err ( Error :: unimplemented ( format ! (
394+ "Unexpected ref multipart schema: '{reference}'."
395+ ) ) )
396+ }
382397 ReferenceOr :: Item ( schema) => match & schema. schema_kind {
383398 SchemaKind :: Type ( Type :: Object ( obj) ) => {
384399 fn multipart_param (
@@ -396,7 +411,8 @@ fn request_body_params(
396411 } )
397412 }
398413
399- let params = obj. properties
414+ let params = obj
415+ . properties
400416 . iter ( )
401417 . map ( |( name, schema) | {
402418 multipart_param (
@@ -408,31 +424,33 @@ fn request_body_params(
408424 } )
409425 . collect :: < Result < Vec < _ > > > ( ) ?;
410426
411- content_type_params. insert ( ContentType ( content_type. clone ( ) ) , params) ;
427+ content_type_params
428+ . insert ( ContentType ( content_type. clone ( ) ) , params) ;
429+ }
430+ _ => {
431+ return Err ( Error :: unimplemented (
432+ "Object schema expected for multipart request body." ,
433+ ) )
412434 }
413- _ => return Err ( Error :: unimplemented (
414- "Object schema expected for multipart request body." ,
415- ) ) ,
416435 } ,
417436 } ,
418437 }
419438 } else {
420- return Err ( Error :: unimplemented ( format ! (
439+ return Err ( Error :: unimplemented ( format ! (
421440 "Request body content type: '{content_type}'."
422- ) ) )
441+ ) ) ) ;
423442 }
424443 }
425444 }
426445 }
427446
428447 Ok ( RequestBodyParams {
429- params : content_type_params
448+ params : content_type_params,
430449 } )
431450}
432451
433452fn parameters ( op : & PathOperation , ref_cache : & mut RefCache ) -> Result < Vec < Param > > {
434- op
435- . op
453+ op. op
436454 . parameters
437455 . iter ( )
438456 . map ( |p| parameter ( p, ref_cache) )
@@ -490,7 +508,11 @@ fn response_type(response: &ReferenceOr<Response>, ref_cache: &mut RefCache) ->
490508 Some ( schema) => Ok ( schema) ,
491509 } ;
492510
493- Ok ( ref_or_schema_type ( schema?, ref_cache, Some ( content_type. clone ( ) ) ) ?)
511+ Ok ( ref_or_schema_type (
512+ schema?,
513+ ref_cache,
514+ Some ( content_type. clone ( ) ) ,
515+ ) ?)
494516 } else if content_type == "application/octet-stream" {
495517 Ok ( DataType :: Binary )
496518 } else {
@@ -580,17 +602,20 @@ fn trait_method(
580602 }
581603
582604 let method_name = format ! ( "{}_json" , name) ;
583- methods. push (
584- Method {
585- name : method_name,
586- path : op. path . clone ( ) ,
587- original_path : op. original_path . clone ( ) ,
588- http_method : op. method . to_string ( ) ,
589- params : new_params. clone ( ) ,
590- result : result_type. clone ( ) ,
591- result_status_code : result_code. clone ( ) ,
592- errors : method_errors ( & op. op . responses . responses , result_code. clone ( ) , ref_cache) ?,
593- } ) ;
605+ methods. push ( Method {
606+ name : method_name,
607+ path : op. path . clone ( ) ,
608+ original_path : op. original_path . clone ( ) ,
609+ http_method : op. method . to_string ( ) ,
610+ params : new_params. clone ( ) ,
611+ result : result_type. clone ( ) ,
612+ result_status_code : result_code. clone ( ) ,
613+ errors : method_errors (
614+ & op. op . responses . responses ,
615+ result_code. clone ( ) ,
616+ ref_cache,
617+ ) ?,
618+ } ) ;
594619 } else if content_type. is_yaml ( ) {
595620 let mut new_params = main_params. clone ( ) ;
596621
@@ -600,17 +625,20 @@ fn trait_method(
600625
601626 let method_name = format ! ( "{}_yaml" , name) ;
602627
603- methods. push (
604- Method {
605- name : method_name,
606- path : op. path . clone ( ) ,
607- original_path : op. original_path . clone ( ) ,
608- http_method : op. method . to_string ( ) ,
609- params : new_params. clone ( ) ,
610- result : result_type. clone ( ) ,
611- result_status_code : result_code. clone ( ) ,
612- errors : method_errors ( & op. op . responses . responses , result_code. clone ( ) , ref_cache) ?,
613- } ) ;
628+ methods. push ( Method {
629+ name : method_name,
630+ path : op. path . clone ( ) ,
631+ original_path : op. original_path . clone ( ) ,
632+ http_method : op. method . to_string ( ) ,
633+ params : new_params. clone ( ) ,
634+ result : result_type. clone ( ) ,
635+ result_status_code : result_code. clone ( ) ,
636+ errors : method_errors (
637+ & op. op . responses . responses ,
638+ result_code. clone ( ) ,
639+ ref_cache,
640+ ) ?,
641+ } ) ;
614642 }
615643 }
616644
@@ -951,10 +979,14 @@ fn render_method_implementation(method: &Method, error_kind: &ErrorKind) -> Rust
951979 )
952980 + NewLine
953981 } else if param. tpe == DataType :: Yaml {
954- line ( unit ( ) + "request = request.body(serde_yaml::to_string(" + & param. name + ").unwrap_or_default().into_bytes());" ) +
955- line (
956- r#"request = request.header(reqwest::header::CONTENT_TYPE, "application/x-yaml");"# ,
957- ) + NewLine
982+ line (
983+ unit ( )
984+ + "request = request.body(serde_yaml::to_string("
985+ + & param. name
986+ + ").unwrap_or_default().into_bytes());" ,
987+ ) + line (
988+ r#"request = request.header(reqwest::header::CONTENT_TYPE, "application/x-yaml");"# ,
989+ ) + NewLine
958990 }
959991 // Not sure why everything else is assumed to be json (previously)
960992 else {
0 commit comments