diff --git a/src/printer.rs b/src/printer.rs index 043eabc..311a826 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -75,12 +75,6 @@ impl Printer for String { } } -pub struct UnitPrinter; - -impl Printer for UnitPrinter { - fn print(&self, _ctx: &mut Context) {} -} - pub struct IndentPrinter; impl Printer for IndentPrinter { @@ -136,14 +130,6 @@ impl TreePrinter { } } -pub struct TreePrinterPrinter(TreePrinter); - -impl Printer for TreePrinterPrinter { - fn print(&self, ctx: &mut Context) { - self.0.print(ctx) - } -} - impl Add> for TreePrinter where TreePrinter: Add>, diff --git a/src/rust/client_gen.rs b/src/rust/client_gen.rs index 236468f..8ee300d 100644 --- a/src/rust/client_gen.rs +++ b/src/rust/client_gen.rs @@ -493,11 +493,10 @@ fn response_type(response: &ReferenceOr, ref_cache: &mut RefCache) -> "Reference in response top level: {reference}" ))), ReferenceOr::Item(resp) => { - if resp.content.len() != 1 { - Err(Error::unimplemented( - "Response content with not exactly 1 option.", - )) - } else { + if resp.content.is_empty() { + // No content case + Ok(DataType::Unit) + } else if resp.content.len() == 1 { let (content_type, media_type) = resp.content.first().unwrap(); if content_type.starts_with("application/json") { @@ -520,6 +519,10 @@ fn response_type(response: &ReferenceOr, ref_cache: &mut RefCache) -> "Response content type: {content_type}" ))) } + } else { + Err(Error::unimplemented( + "Response content with not exactly 1 option.", + )) } } } @@ -748,6 +751,7 @@ fn render_path_param(method: &Method, name: &str) -> RustResult { DataType::String => Ok(unit() + ¶m.name), DataType::Uuid => Ok(unit() + "&" + ¶m.name + ".to_string()"), DataType::Model(_) => Ok(unit() + "&" + ¶m.name + ".to_string()"), + DataType::Int(_) => Ok(unit() + "&" + ¶m.name + ".to_string()"), _ => Err(Error::unexpected(format!( "Unexpected param type {name}: {:?}", param.tpe @@ -882,6 +886,7 @@ fn status_match(range_results: bool, code: &StatusCode) -> RustPrinter { fn response_body_parsing(data_type: &DataType) -> RustPrinter { match data_type { DataType::Binary => unit() + "response.bytes().await?", + DataType::Unit => unit() + "()", _ => unit() + "response.json::<" + data_type.render_declaration(false) + ">().await?", } } diff --git a/src/rust/model_gen.rs b/src/rust/model_gen.rs index 05f65cc..8b05a87 100644 --- a/src/rust/model_gen.rs +++ b/src/rust/model_gen.rs @@ -342,20 +342,7 @@ pub fn multipart_field_module() -> Result { + line("fn to_multipart_field(&self) -> String;") + line("fn mime_type(&self) -> &'static str;"), ) - + line(unit() + "}") - + NewLine - + line(unit() + "impl MultipartField for T {") - + indented( - unit() - + line("fn to_multipart_field(&self) -> String {") - + indented(line("self.to_string()")) - + line("}") - + NewLine - + line(unit() + "fn mime_type(&self) -> &'static str {") - + indented(line(r#""text/plain; charset=utf-8""#)) - + line(unit() + "}"), - ) - + line("}"); + + line(unit() + "}"); Ok(Module { def: ModuleDef { diff --git a/src/rust/types.rs b/src/rust/types.rs index d0d0c8a..53a506f 100644 --- a/src/rust/types.rs +++ b/src/rust/types.rs @@ -74,6 +74,7 @@ pub enum DataType { MapOf(Box), Json, Yaml, + Unit, } pub fn escape_keywords(name: &str) -> String { @@ -95,6 +96,7 @@ impl DataType { } match self { + DataType::Unit => unit() + "()", DataType::String => { if top_param { unit() + "&str"