Skip to content

Commit c094e57

Browse files
committed
Coverage improvements and CI fixes
1 parent 13471de commit c094e57

9 files changed

Lines changed: 240 additions & 107 deletions

File tree

cli/src/from_openapi.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,33 @@ pub enum FromOpenApiCommands {
5656
pub struct GenerateArgs {
5757
/// Path or URL to the OpenAPI specification.
5858
#[clap(short, long, required_unless_present = "input_dir", env = "CDD_INPUT")]
59+
/// The input file path
5960
pub input: Option<PathBuf>,
6061

6162
/// Directory containing OpenAPI specifications.
6263
#[clap(long, required_unless_present = "input", env = "CDD_INPUT_DIR")]
64+
/// The input directory path
6365
pub input_dir: Option<PathBuf>,
6466

6567
/// Output file or directory path.
6668
#[clap(short, long = "output", env = "CDD_OUTPUT")]
69+
/// The output directory path
6770
pub output_dir: Option<PathBuf>,
6871

6972
/// Do not generate GitHub Actions scaffolding.
7073
#[clap(long, env = "CDD_NO_GITHUB_ACTIONS")]
74+
/// Whether to skip github actions generation
7175
pub no_github_actions: bool,
7276

7377
/// Do not generate installable package scaffolding.
7478
#[clap(long, env = "CDD_NO_INSTALLABLE_PACKAGE")]
79+
/// Whether to skip package generation
7580
pub no_installable_package: bool,
7681

7782
/// Generate integration tests and mocks.
7883
#[clap(long, env = "CDD_TESTS")]
7984
#[clap(long, env = "CDD_TESTS")]
85+
/// Whether to generate tests
8086
pub tests: bool,
8187

8288
/// Generate Model Context Protocol (MCP) server and adapter.
@@ -651,17 +657,25 @@ components:
651657
/// Configuration for `from_openapi` programmatic API
652658
#[derive(Debug, Default)]
653659
pub struct FromOpenApiConfig {
660+
/// The parsed subcommand
654661
pub subcommand: String,
662+
/// The input file path
655663
pub input: Option<PathBuf>,
664+
/// The input directory path
656665
pub input_dir: Option<PathBuf>,
666+
/// The output directory path
657667
pub output_dir: Option<PathBuf>,
668+
/// Whether to skip github actions generation
658669
pub no_github_actions: bool,
670+
/// Whether to skip package generation
659671
pub no_installable_package: bool,
660672

673+
/// Whether to generate tests
661674
pub tests: bool,
662675

663676
/// Generate Model Context Protocol (MCP) server and adapter.
664677
pub mcp: bool,
678+
/// The server framework to use
665679
pub framework: ServerFramework,
666680
}
667681

cli/src/mcp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,9 @@ invalid json
540540
let mut stdin = input.as_bytes();
541541
let mut stdout = Vec::new();
542542

543-
serve_mcp_inner(&mut stdin, &mut stdout).unwrap();
543+
serve_mcp_inner(&mut stdin, &mut stdout).expect("must succeed");
544544

545-
let output = String::from_utf8(stdout).unwrap();
545+
let output = String::from_utf8(stdout).expect("must succeed");
546546
let lines: Vec<&str> = output.trim().split('\n').collect();
547547

548548
assert_eq!(lines.len(), 36);
@@ -601,7 +601,7 @@ invalid json
601601
fn test_serve_mcp_inner_read_error() {
602602
let mut stdin = ErrorReader;
603603
let mut stdout = Vec::new();
604-
serve_mcp_inner(&mut stdin, &mut stdout).unwrap();
604+
serve_mcp_inner(&mut stdin, &mut stdout).expect("must succeed");
605605
assert!(stdout.is_empty());
606606
}
607607
}

cli/src/serve_json_rpc.rs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ use std::path::PathBuf;
1515
pub struct ServeJsonRpcArgs {
1616
/// Port to listen on.
1717
#[clap(short, long, default_value = "8080", env = "CDD_PORT")]
18+
/// The port to listen on
1819
pub port: u16,
1920

2021
/// Interface to listen on.
2122
#[clap(short, long, default_value = "127.0.0.1", env = "CDD_LISTEN")]
23+
/// The address to listen on
2224
pub listen: String,
2325
}
2426

@@ -369,7 +371,9 @@ mod tests {
369371
/// Configuration for `serve_json_rpc` programmatic API
370372
#[derive(Debug)]
371373
pub struct ServeJsonRpcConfig {
374+
/// The port to listen on
372375
pub port: u16,
376+
/// The address to listen on
373377
pub listen: String,
374378
}
375379

@@ -428,7 +432,7 @@ mod extra_rpc_tests {
428432
id: None,
429433
};
430434
let res = send_rpc(&req).await;
431-
assert_eq!(res.error.unwrap().code, -32602);
435+
assert_eq!(res.error.expect("must succeed").code, -32602);
432436

433437
// Invalid params
434438
let req = RpcRequest {
@@ -438,7 +442,7 @@ mod extra_rpc_tests {
438442
id: None,
439443
};
440444
let res = send_rpc(&req).await;
441-
assert_eq!(res.error.unwrap().code, -32602);
445+
assert_eq!(res.error.expect("must succeed").code, -32602);
442446

443447
// Success execution - pointing to something that will error inside generate
444448
let req = RpcRequest {
@@ -448,7 +452,7 @@ mod extra_rpc_tests {
448452
id: None,
449453
};
450454
let res = send_rpc(&req).await;
451-
assert_eq!(res.error.unwrap().code, -32000);
455+
assert_eq!(res.error.expect("must succeed").code, -32000);
452456
}
453457

454458
#[actix_rt::test]
@@ -461,7 +465,7 @@ mod extra_rpc_tests {
461465
id: None,
462466
};
463467
let res = send_rpc(&req).await;
464-
assert_eq!(res.error.unwrap().code, -32602);
468+
assert_eq!(res.error.expect("must succeed").code, -32602);
465469

466470
// Invalid params
467471
let req = RpcRequest {
@@ -471,7 +475,7 @@ mod extra_rpc_tests {
471475
id: None,
472476
};
473477
let res = send_rpc(&req).await;
474-
assert_eq!(res.error.unwrap().code, -32602);
478+
assert_eq!(res.error.expect("must succeed").code, -32602);
475479

476480
// Fail inside generate
477481
let req = RpcRequest {
@@ -481,7 +485,7 @@ mod extra_rpc_tests {
481485
id: None,
482486
};
483487
let res = send_rpc(&req).await;
484-
assert_eq!(res.error.unwrap().code, -32000);
488+
assert_eq!(res.error.expect("must succeed").code, -32000);
485489
}
486490

487491
#[actix_rt::test]
@@ -494,7 +498,7 @@ mod extra_rpc_tests {
494498
id: None,
495499
};
496500
let res = send_rpc(&req).await;
497-
assert_eq!(res.error.unwrap().code, -32602);
501+
assert_eq!(res.error.expect("must succeed").code, -32602);
498502

499503
// Success inside, but it will error
500504
let req = RpcRequest {
@@ -504,7 +508,7 @@ mod extra_rpc_tests {
504508
id: None,
505509
};
506510
let res = send_rpc(&req).await;
507-
assert_eq!(res.error.unwrap().code, -32000);
511+
assert_eq!(res.error.expect("must succeed").code, -32000);
508512

509513
let req = RpcRequest {
510514
jsonrpc: "2.0".to_string(),
@@ -558,21 +562,21 @@ mod extra_rpc_success_tests {
558562
#[actix_rt::test]
559563
async fn test_to_openapi_rpc_success() {
560564
use tempfile::tempdir;
561-
let dir = tempdir().unwrap();
565+
let dir = tempdir().expect("must succeed");
562566
let src_dir = dir.path().join("src");
563-
std::fs::create_dir_all(&src_dir).unwrap();
567+
std::fs::create_dir_all(&src_dir).expect("must succeed");
564568
let input = src_dir.join("input.rs");
565569
let output = dir.path().join("out.yaml");
566570
let schema =
567571
"pub struct User { pub id: i32 } \n #[get(\"/users\")] pub async fn get_users() {}";
568-
std::fs::write(&input, schema).unwrap();
572+
std::fs::write(&input, schema).expect("must succeed");
569573

570574
let req = RpcRequest {
571575
jsonrpc: "2.0".to_string(),
572576
method: "to_openapi".to_string(),
573577
params: Some(serde_json::json!({
574-
"input": src_dir.to_str().unwrap(),
575-
"output": output.to_str().unwrap()
578+
"input": src_dir.to_str().expect("must succeed"),
579+
"output": output.to_str().expect("must succeed")
576580
})),
577581
id: None,
578582
};
@@ -583,18 +587,18 @@ mod extra_rpc_success_tests {
583587
#[actix_rt::test]
584588
async fn test_to_docs_json_rpc_success() {
585589
use tempfile::tempdir;
586-
let dir = tempdir().unwrap();
590+
let dir = tempdir().expect("must succeed");
587591
let input = dir.path().join("input.rs");
588592
let output = dir.path().join("out.yaml");
589593
let schema = "openapi: 3.0.0\ninfo:\n title: API\n version: 1.0.0\npaths: {}";
590-
std::fs::write(&input, schema).unwrap();
594+
std::fs::write(&input, schema).expect("must succeed");
591595

592596
let req = RpcRequest {
593597
jsonrpc: "2.0".to_string(),
594598
method: "to_docs_json".to_string(),
595599
params: Some(serde_json::json!({
596-
"input": input.to_str().unwrap(),
597-
"output": output.to_str().unwrap()
600+
"input": input.to_str().expect("must succeed"),
601+
"output": output.to_str().expect("must succeed")
598602
})),
599603
id: None,
600604
};
@@ -605,7 +609,7 @@ mod extra_rpc_success_tests {
605609
#[actix_rt::test]
606610
async fn test_from_openapi_rpc_success() {
607611
use tempfile::tempdir;
608-
let dir = tempdir().unwrap();
612+
let dir = tempdir().expect("must succeed");
609613
let input = dir.path().join("openapi.yaml");
610614
let output = dir.path().join("out");
611615

@@ -616,14 +620,14 @@ info:
616620
version: 1.0.0
617621
paths: {}
618622
"#;
619-
std::fs::write(&input, schema).unwrap();
623+
std::fs::write(&input, schema).expect("must succeed");
620624

621625
let req = RpcRequest {
622626
jsonrpc: "2.0".to_string(),
623627
method: "from_openapi_to_sdk".to_string(),
624628
params: Some(serde_json::json!({
625-
"input": input.to_str().unwrap(),
626-
"output": output.to_str().unwrap()
629+
"input": input.to_str().expect("must succeed"),
630+
"output": output.to_str().expect("must succeed")
627631
})),
628632
id: None,
629633
};

cli/src/to_docs_json.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,22 @@ use std::fs;
1212
pub struct ToDocsJsonArgs {
1313
/// Path or URL to the OpenAPI specification.
1414
#[clap(short, long, env = "CDD_INPUT")]
15+
/// The input file path
1516
pub input: String,
1617

1718
/// If provided, omit the imports field in the code object.
1819
#[clap(long, env = "CDD_NO_IMPORTS")]
20+
/// Whether to exclude imports
1921
pub no_imports: bool,
2022

2123
/// If provided, omit the wrapper_start and wrapper_end fields in the code object.
2224
#[clap(long, env = "CDD_NO_WRAPPING")]
25+
/// Whether to disable wrapping
2326
pub no_wrapping: bool,
2427

2528
/// Output file or directory path.
2629
#[clap(short, long, env = "CDD_OUTPUT")]
30+
/// The output file path
2731
pub output: Option<String>,
2832
}
2933

@@ -366,9 +370,13 @@ paths: {}
366370
/// Configuration for `to_docs_json` programmatic API
367371
#[derive(Debug, Default)]
368372
pub struct ToDocsJsonConfig {
373+
/// The input file path
369374
pub input: String,
375+
/// The output file path
370376
pub output: Option<String>,
377+
/// Whether to exclude imports
371378
pub no_imports: bool,
379+
/// Whether to disable wrapping
372380
pub no_wrapping: bool,
373381
}
374382

cli/src/to_openapi.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ use walkdir::WalkDir;
1414
pub struct ToOpenApiArgs {
1515
/// Path to source code directory or file.
1616
#[clap(short = 'i', long, env = "CDD_INPUT")]
17+
/// The input directory path
1718
pub input: PathBuf,
1819

1920
/// Output file or directory path.
2021
#[clap(short = 'o', long, env = "CDD_OUTPUT", default_value = "spec.json")]
22+
/// The output directory path
2123
pub output: PathBuf,
2224
}
2325

@@ -190,25 +192,25 @@ mod tests {
190192
fn test_to_openapi_execute_failures() {
191193
let dir = tempdir().expect("Failed to create temporary directory");
192194
let src_dir = dir.path().join("src");
193-
std::fs::create_dir_all(&src_dir).unwrap();
195+
std::fs::create_dir_all(&src_dir).expect("must succeed");
194196

195197
let out_file = dir.path().join("out.yaml");
196198

197199
// 1. Directory named .rs so read_to_string fails
198200
let dir_rs = src_dir.join("dir.rs");
199-
std::fs::create_dir(&dir_rs).unwrap();
201+
std::fs::create_dir(&dir_rs).expect("must succeed");
200202

201203
// 2. File where extract_struct_names fails
202204
let syntax_err_rs = src_dir.join("syntax.rs");
203-
std::fs::write(&syntax_err_rs, "impl Model {").unwrap();
205+
std::fs::write(&syntax_err_rs, "impl Model {").expect("must succeed");
204206

205207
// 3. File where extract_model fails
206208
let model_err_rs = src_dir.join("model_err.rs");
207-
std::fs::write(&model_err_rs, "pub struct Partial").unwrap();
209+
std::fs::write(&model_err_rs, "pub struct Partial").expect("must succeed");
208210

209211
// 4. File where parse routes fail
210212
let route_err_rs = src_dir.join("route_err.rs");
211-
std::fs::write(&route_err_rs, "pub fn my_route() {}").unwrap();
213+
std::fs::write(&route_err_rs, "pub fn my_route() {}").expect("must succeed");
212214

213215
let args = ToOpenApiArgs {
214216
input: src_dir,
@@ -297,7 +299,9 @@ mod tests {
297299
/// Configuration for `to_openapi` programmatic API
298300
#[derive(Debug, Default)]
299301
pub struct ToOpenApiConfig {
302+
/// The input directory path
300303
pub input: PathBuf,
304+
/// The output directory path
301305
pub output: PathBuf,
302306
}
303307

@@ -317,10 +321,10 @@ mod extra_coverage_tests {
317321

318322
#[test]
319323
fn test_generate_to_openapi() {
320-
let dir = tempdir().unwrap();
324+
let dir = tempdir().expect("must succeed");
321325
let input_file = dir.path().join("input.rs");
322326
let output_file = dir.path().join("output.yaml");
323-
std::fs::write(&input_file, "pub struct MyStruct { pub id: i32 }").unwrap();
327+
std::fs::write(&input_file, "pub struct MyStruct { pub id: i32 }").expect("must succeed");
324328

325329
let config = ToOpenApiConfig {
326330
input: input_file,

0 commit comments

Comments
 (0)