@@ -223,6 +223,10 @@ struct Operation {
223
223
/// Name of the request body type, if any.
224
224
#[ serde( skip_serializing_if = "Option::is_none" ) ]
225
225
request_body_schema_name : Option < String > ,
226
+ /// Some request bodies are required, but all the fields are optional (i.e. the CLI can omit
227
+ /// this from the argument list).
228
+ /// Only useful when `request_body_schema_name` is `Some`.
229
+ request_body_all_optional : bool ,
226
230
/// Name of the response body type, if any.
227
231
#[ serde( skip_serializing_if = "Option::is_none" ) ]
228
232
response_body_schema_name : Option < String > ,
@@ -343,7 +347,7 @@ impl Operation {
343
347
}
344
348
}
345
349
346
- let request_body_schema_name = op. request_body . and_then ( |b| match b {
350
+ let request_body_schema_name = op. request_body . clone ( ) . and_then ( |b| match b {
347
351
ReferenceOr :: Item ( mut req_body) => {
348
352
assert ! ( req_body. required) ;
349
353
assert ! ( req_body. extensions. is_empty( ) ) ;
@@ -372,6 +376,38 @@ impl Operation {
372
376
}
373
377
} ) ;
374
378
379
+ let request_body_all_optional = op
380
+ . request_body
381
+ . map ( |r| {
382
+ match r {
383
+ ReferenceOr :: Reference { .. } => {
384
+ todo ! ( "reference" )
385
+ }
386
+ ReferenceOr :: Item ( body) => {
387
+ if let Some ( mt) = body. content . get ( "application/json" ) {
388
+ match mt. schema . as_ref ( ) . map ( |so| & so. json_schema ) {
389
+ Some ( Schema :: Object ( schemars:: schema:: SchemaObject {
390
+ object : Some ( ov) ,
391
+ ..
392
+ } ) ) => {
393
+ dbg ! ( ( & op_id, ov. required. is_empty( ) ) ) ;
394
+ return ov. required . is_empty ( ) ;
395
+ }
396
+ Some ( Schema :: Object ( schemars:: schema:: SchemaObject {
397
+ reference : Some ( s) ,
398
+ ..
399
+ } ) ) => {
400
+ todo ! ( "lookup {s}" ) ;
401
+ }
402
+ _ => { }
403
+ }
404
+ }
405
+ }
406
+ }
407
+ false
408
+ } )
409
+ . unwrap_or_default ( ) ;
410
+
375
411
let response_body_schema_name = op. responses . and_then ( |r| {
376
412
assert_eq ! ( r. default , None ) ;
377
413
assert ! ( r. extensions. is_empty( ) ) ;
@@ -415,6 +451,7 @@ impl Operation {
415
451
header_params,
416
452
query_params,
417
453
request_body_schema_name,
454
+ request_body_all_optional,
418
455
response_body_schema_name,
419
456
} ;
420
457
Some ( ( res_path, op) )
0 commit comments