From 8cf3213267de01d67b716267f6ca7c06535455ea Mon Sep 17 00:00:00 2001 From: Cyborus Date: Fri, 9 Feb 2024 19:22:26 -0500 Subject: deref more params --- generator/src/structs.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'generator/src/structs.rs') diff --git a/generator/src/structs.rs b/generator/src/structs.rs index aa6bf0c..ef61a8f 100644 --- a/generator/src/structs.rs +++ b/generator/src/structs.rs @@ -23,7 +23,7 @@ pub fn create_structs(spec: &OpenApiV2) -> eyre::Result { } } for (_, item) in &spec.paths { - let strukt = create_query_structs_for_path(item)?; + let strukt = create_query_structs_for_path(spec, item)?; s.push_str(&strukt); } s.push_str("\n}"); @@ -223,28 +223,28 @@ fn create_struct_docs_str(description: Option<&str>) -> eyre::Result { Ok(doc) } -pub fn create_query_structs_for_path(item: &PathItem) -> eyre::Result { +pub fn create_query_structs_for_path(spec: &OpenApiV2, item: &PathItem) -> eyre::Result { let mut s = String::new(); if let Some(op) = &item.get { - s.push_str(&create_query_struct(op).wrap_err("GET")?); + s.push_str(&create_query_struct(spec, op).wrap_err("GET")?); } if let Some(op) = &item.put { - s.push_str(&create_query_struct(op).wrap_err("PUT")?); + s.push_str(&create_query_struct(spec, op).wrap_err("PUT")?); } if let Some(op) = &item.post { - s.push_str(&create_query_struct(op).wrap_err("POST")?); + s.push_str(&create_query_struct(spec, op).wrap_err("POST")?); } if let Some(op) = &item.delete { - s.push_str(&create_query_struct(op).wrap_err("DELETE")?); + s.push_str(&create_query_struct(spec, op).wrap_err("DELETE")?); } if let Some(op) = &item.options { - s.push_str(&create_query_struct(op).wrap_err("OPTIONS")?); + s.push_str(&create_query_struct(spec, op).wrap_err("OPTIONS")?); } if let Some(op) = &item.head { - s.push_str(&create_query_struct(op).wrap_err("HEAD")?); + s.push_str(&create_query_struct(spec, op).wrap_err("HEAD")?); } if let Some(op) = &item.patch { - s.push_str(&create_query_struct(op).wrap_err("PATCH")?); + s.push_str(&create_query_struct(spec, op).wrap_err("PATCH")?); } Ok(s) } @@ -260,7 +260,7 @@ pub fn query_struct_name(op: &Operation) -> eyre::Result { Ok(ty) } -fn create_query_struct(op: &Operation) -> eyre::Result { +fn create_query_struct(spec: &OpenApiV2, op: &Operation) -> eyre::Result { let params = match &op.parameters { Some(params) => params, None => return Ok(String::new()), @@ -271,10 +271,7 @@ fn create_query_struct(op: &Operation) -> eyre::Result { let mut fields = String::new(); let mut imp = String::new(); for param in params { - let param = match ¶m { - MaybeRef::Value { value } => value, - MaybeRef::Ref { _ref } => eyre::bail!("todo: add deref parameters"), - }; + let param = param.deref(spec)?; if let ParameterIn::Query { param: query_param } = ¶m._in { let field_name = crate::sanitize_ident(¶m.name); let ty = match &query_param { -- cgit v1.2.3