Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ impl<Context: PrintContext> Printer<Context> for String {
}
}

pub struct UnitPrinter;

impl<Context> Printer<Context> for UnitPrinter {
fn print(&self, _ctx: &mut Context) {}
}

pub struct IndentPrinter;

impl<C: IndentContext + PrintContext> Printer<C> for IndentPrinter {
Expand Down Expand Up @@ -136,14 +130,6 @@ impl<Context> TreePrinter<Context> {
}
}

pub struct TreePrinterPrinter<Context>(TreePrinter<Context>);

impl<Context> Printer<Context> for TreePrinterPrinter<Context> {
fn print(&self, ctx: &mut Context) {
self.0.print(ctx)
}
}

impl<Context, P> Add<Option<P>> for TreePrinter<Context>
where
TreePrinter<Context>: Add<P, Output = TreePrinter<Context>>,
Expand Down
15 changes: 10 additions & 5 deletions src/rust/client_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,10 @@ fn response_type(response: &ReferenceOr<Response>, 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.len() == 0 {
// 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") {
Expand All @@ -520,6 +519,10 @@ fn response_type(response: &ReferenceOr<Response>, ref_cache: &mut RefCache) ->
"Response content type: {content_type}"
)))
}
} else {
Err(Error::unimplemented(
"Response content with not exactly 1 option.",
))
}
}
}
Expand Down Expand Up @@ -748,6 +751,7 @@ fn render_path_param(method: &Method, name: &str) -> RustResult {
DataType::String => Ok(unit() + &param.name),
DataType::Uuid => Ok(unit() + "&" + &param.name + ".to_string()"),
DataType::Model(_) => Ok(unit() + "&" + &param.name + ".to_string()"),
DataType::Int(_) => Ok(unit() + "&" + &param.name + ".to_string()"),
_ => Err(Error::unexpected(format!(
"Unexpected param type {name}: {:?}",
param.tpe
Expand Down Expand Up @@ -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?",
}
}
Expand Down
15 changes: 1 addition & 14 deletions src/rust/model_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,20 +342,7 @@ pub fn multipart_field_module() -> Result<Module> {
+ line("fn to_multipart_field(&self) -> String;")
+ line("fn mime_type(&self) -> &'static str;"),
)
+ line(unit() + "}")
+ NewLine
+ line(unit() + "impl<T: std::fmt::Display> 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 {
Expand Down
2 changes: 2 additions & 0 deletions src/rust/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub enum DataType {
MapOf(Box<DataType>),
Json,
Yaml,
Unit,
}

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

match self {
DataType::Unit => unit() + "()",
DataType::String => {
if top_param {
unit() + "&str"
Expand Down
Loading