Skip to content

Commit dfc5a46

Browse files
daniel.eadesdanieleades
authored andcommitted
fix: support httpmock generation for array types
1 parent 4c06c8c commit dfc5a46

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2025 Oxide Computer Company
2+
3+
use openapiv3::OpenAPI;
4+
use progenitor_impl::{space_out_items, Generator};
5+
6+
fn format_httpmock(generator: &mut Generator, spec: &OpenAPI) -> String {
7+
let code = generator.httpmock(spec, "crate::types").unwrap();
8+
let output = rustfmt_wrapper::rustfmt_config(
9+
rustfmt_wrapper::config::Config {
10+
format_strings: Some(true),
11+
..Default::default()
12+
},
13+
code,
14+
)
15+
.unwrap();
16+
space_out_items(output).unwrap()
17+
}
18+
19+
#[test]
20+
fn test_httpmock_query_array_param() {
21+
let spec = serde_yaml::from_str::<OpenAPI>(
22+
r#"
23+
openapi: 3.0.0
24+
info:
25+
title: httpmock-query-array
26+
version: "0.0.0"
27+
paths:
28+
/widgets:
29+
get:
30+
operationId: listWidgets
31+
parameters:
32+
- name: tags
33+
in: query
34+
required: true
35+
schema:
36+
type: array
37+
items:
38+
type: string
39+
responses:
40+
"204":
41+
description: no-content
42+
"#,
43+
)
44+
.unwrap();
45+
46+
let mut generator = Generator::default();
47+
let output = format_httpmock(&mut generator, &spec);
48+
49+
assert!(
50+
output.contains("matches_query_param(req, \"tags\", &value)"),
51+
"expected array query params to use serialized query matching"
52+
);
53+
assert!(
54+
!output.contains("query_param(\"tags\", value.to_string())"),
55+
"expected array query params to avoid Display-based matching"
56+
);
57+
}

0 commit comments

Comments
 (0)