Skip to content

Commit 838cbc7

Browse files
mschuwalownoise64
andauthored
Fixes for atomic deployment (#34)
* Fixes for atomic deployment * fmt * remove blanked impl for multipart * update * fix * support generating nocontent * add derive Clone for Error * Revert "add derive Clone for Error" This reverts commit 8532419. * fix --------- Co-authored-by: Dávid István Bíró <[email protected]>
1 parent a9f05ec commit 838cbc7

File tree

4 files changed

+13
-33
lines changed

4 files changed

+13
-33
lines changed

src/printer.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ impl<Context: PrintContext> Printer<Context> for String {
7575
}
7676
}
7777

78-
pub struct UnitPrinter;
79-
80-
impl<Context> Printer<Context> for UnitPrinter {
81-
fn print(&self, _ctx: &mut Context) {}
82-
}
83-
8478
pub struct IndentPrinter;
8579

8680
impl<C: IndentContext + PrintContext> Printer<C> for IndentPrinter {
@@ -136,14 +130,6 @@ impl<Context> TreePrinter<Context> {
136130
}
137131
}
138132

139-
pub struct TreePrinterPrinter<Context>(TreePrinter<Context>);
140-
141-
impl<Context> Printer<Context> for TreePrinterPrinter<Context> {
142-
fn print(&self, ctx: &mut Context) {
143-
self.0.print(ctx)
144-
}
145-
}
146-
147133
impl<Context, P> Add<Option<P>> for TreePrinter<Context>
148134
where
149135
TreePrinter<Context>: Add<P, Output = TreePrinter<Context>>,

src/rust/client_gen.rs

Lines changed: 10 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.is_empty() {
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
}
@@ -748,6 +751,7 @@ fn render_path_param(method: &Method, name: &str) -> RustResult {
748751
DataType::String => Ok(unit() + &param.name),
749752
DataType::Uuid => Ok(unit() + "&" + &param.name + ".to_string()"),
750753
DataType::Model(_) => Ok(unit() + "&" + &param.name + ".to_string()"),
754+
DataType::Int(_) => Ok(unit() + "&" + &param.name + ".to_string()"),
751755
_ => Err(Error::unexpected(format!(
752756
"Unexpected param type {name}: {:?}",
753757
param.tpe
@@ -882,6 +886,7 @@ fn status_match(range_results: bool, code: &StatusCode) -> RustPrinter {
882886
fn response_body_parsing(data_type: &DataType) -> RustPrinter {
883887
match data_type {
884888
DataType::Binary => unit() + "response.bytes().await?",
889+
DataType::Unit => unit() + "()",
885890
_ => unit() + "response.json::<" + data_type.render_declaration(false) + ">().await?",
886891
}
887892
}

src/rust/model_gen.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -342,20 +342,7 @@ pub fn multipart_field_module() -> Result<Module> {
342342
+ line("fn to_multipart_field(&self) -> String;")
343343
+ line("fn mime_type(&self) -> &'static str;"),
344344
)
345-
+ line(unit() + "}")
346-
+ NewLine
347-
+ line(unit() + "impl<T: std::fmt::Display> MultipartField for T {")
348-
+ indented(
349-
unit()
350-
+ line("fn to_multipart_field(&self) -> String {")
351-
+ indented(line("self.to_string()"))
352-
+ line("}")
353-
+ NewLine
354-
+ line(unit() + "fn mime_type(&self) -> &'static str {")
355-
+ indented(line(r#""text/plain; charset=utf-8""#))
356-
+ line(unit() + "}"),
357-
)
358-
+ line("}");
345+
+ line(unit() + "}");
359346

360347
Ok(Module {
361348
def: ModuleDef {

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)