Skip to content

Commit 64018ca

Browse files
committed
support generating nocontent
1 parent e6d55a7 commit 64018ca

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/rust/client_gen.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,10 @@ fn response_type(response: &ReferenceOr<Response>, ref_cache: &mut RefCache) ->
493493
"Reference in response top level: {reference}"
494494
))),
495495
ReferenceOr::Item(resp) => {
496-
if resp.content.len() != 1 {
497-
Err(Error::unimplemented(
498-
"Response content with not exactly 1 option.",
499-
))
500-
} else {
496+
if resp.content.len() == 0 {
497+
// No content case
498+
Ok(DataType::Unit)
499+
} else if resp.content.len() == 1 {
501500
let (content_type, media_type) = resp.content.first().unwrap();
502501

503502
if content_type.starts_with("application/json") {
@@ -520,6 +519,10 @@ fn response_type(response: &ReferenceOr<Response>, ref_cache: &mut RefCache) ->
520519
"Response content type: {content_type}"
521520
)))
522521
}
522+
} else {
523+
Err(Error::unimplemented(
524+
"Response content with not exactly 1 option.",
525+
))
523526
}
524527
}
525528
}
@@ -883,6 +886,7 @@ fn status_match(range_results: bool, code: &StatusCode) -> RustPrinter {
883886
fn response_body_parsing(data_type: &DataType) -> RustPrinter {
884887
match data_type {
885888
DataType::Binary => unit() + "response.bytes().await?",
889+
DataType::Unit => unit() + "()",
886890
_ => unit() + "response.json::<" + data_type.render_declaration(false) + ">().await?",
887891
}
888892
}

src/rust/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub enum DataType {
7474
MapOf(Box<DataType>),
7575
Json,
7676
Yaml,
77+
Unit,
7778
}
7879

7980
pub fn escape_keywords(name: &str) -> String {
@@ -95,6 +96,7 @@ impl DataType {
9596
}
9697

9798
match self {
99+
DataType::Unit => unit() + "()",
98100
DataType::String => {
99101
if top_param {
100102
unit() + "&str"

0 commit comments

Comments
 (0)