diff --git a/generator/src/methods.rs b/generator/src/methods.rs index 3e23853..ad29e05 100644 --- a/generator/src/methods.rs +++ b/generator/src/methods.rs @@ -106,7 +106,9 @@ fn method_docs(op: &Operation) -> eyre::Result { MaybeRef::Ref { _ref } => eyre::bail!("pipis"), }; match param._in { - ParameterIn::Path { param: _ } | ParameterIn::Body { schema: _ } | ParameterIn::FormData { param: _ } => { + ParameterIn::Path { param: _ } + | ParameterIn::Body { schema: _ } + | ParameterIn::FormData { param: _ } => { write!(&mut out, "/// - `{}`", param.name)?; if let Some(description) = ¶m.description { write!(&mut out, ": {}", description)?; @@ -153,7 +155,7 @@ fn fn_args_from_op(spec: &OpenApiV2, op: &Operation) -> eyre::Result { args.push_str(&type_name); } ParameterIn::Query { param: _ } => has_query = true, - ParameterIn::Header { param: _ }=> (), // has_headers = true, + ParameterIn::Header { param: _ } => (), // has_headers = true, ParameterIn::Body { schema } => { let ty = crate::schema_ref_type_name(spec, schema)?; args.push_str(", "); @@ -178,7 +180,12 @@ fn fn_args_from_op(spec: &OpenApiV2, op: &Operation) -> eyre::Result { } pub fn param_type(param: &NonBodyParameter, owned: bool) -> eyre::Result { - param_type_inner(¶m._type, param.format.as_deref(), param.items.as_ref(), owned) + param_type_inner( + ¶m._type, + param.format.as_deref(), + param.items.as_ref(), + owned, + ) } fn param_type_inner( @@ -324,8 +331,8 @@ fn create_method_request( let name = crate::sanitize_ident(¶m.name); match ¶m._in { ParameterIn::Path { param: _ } => (/* do nothing */), - ParameterIn::Query { param: _ } => has_query = true, - ParameterIn::Header { param: _ } => (), // _has_headers = true, + ParameterIn::Query { param: _ } => has_query = true, + ParameterIn::Header { param: _ } => (), // _has_headers = true, ParameterIn::Body { schema: _ } => { if !body_method.is_empty() { eyre::bail!("cannot have more than one body parameter"); @@ -336,7 +343,7 @@ fn create_method_request( body_method = format!(".json(&{name})"); } } - ParameterIn::FormData { param: _ } => { + ParameterIn::FormData { param: _ } => { if !body_method.is_empty() { eyre::bail!("cannot have more than one body parameter"); } @@ -361,10 +368,11 @@ fn create_method_request( fn param_is_string(spec: &OpenApiV2, param: &Parameter) -> eyre::Result { match ¶m._in { - ParameterIn::Body { schema } => { - crate::schema_is_string(spec, schema) - } - ParameterIn::Path { param } | ParameterIn::Query { param } | ParameterIn::Header { param } | ParameterIn::FormData { param } => { + ParameterIn::Body { schema } => crate::schema_is_string(spec, schema), + ParameterIn::Path { param } + | ParameterIn::Query { param } + | ParameterIn::Header { param } + | ParameterIn::FormData { param } => { let is_str = match param._type { ParameterType::String => true, _ => false, @@ -403,10 +411,7 @@ fn sanitize_path_arg(mut path: &str) -> eyre::Result { Ok(out) } -fn create_method_response( - spec: &OpenApiV2, - op: &Operation, -) -> eyre::Result { +fn create_method_response(spec: &OpenApiV2, op: &Operation) -> eyre::Result { let mut has_empty = false; let mut only_empty = true; for (code, res) in &op.responses.http_codes { diff --git a/generator/src/openapi.rs b/generator/src/openapi.rs index 292ca5f..867220c 100644 --- a/generator/src/openapi.rs +++ b/generator/src/openapi.rs @@ -247,20 +247,19 @@ pub enum ParameterIn { impl ParameterIn { fn validate(&self) -> eyre::Result<()> { match self { - ParameterIn::Path { param } => { - eyre::ensure!( - param.required, - "path parameters must be required" - ); + ParameterIn::Path { param } => { + eyre::ensure!(param.required, "path parameters must be required"); param.validate().wrap_err("path param") - }, + } ParameterIn::Query { param } => param.validate().wrap_err("query param"), ParameterIn::Header { param } => param.validate().wrap_err("header param"), - ParameterIn::Body { schema } => if let MaybeRef::Value { value } = schema { + ParameterIn::Body { schema } => { + if let MaybeRef::Value { value } = schema { value.validate().wrap_err("body param") } else { Ok(()) - }, + } + } ParameterIn::FormData { param } => param.validate().wrap_err("form param"), } } diff --git a/generator/src/structs.rs b/generator/src/structs.rs index 04c54fe..556b913 100644 --- a/generator/src/structs.rs +++ b/generator/src/structs.rs @@ -97,9 +97,7 @@ fn create_struct_docs(schema: &Schema) -> eyre::Result { Ok(doc) } -pub fn create_query_structs_for_path( - item: &PathItem, -) -> eyre::Result { +pub fn create_query_structs_for_path(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")?); @@ -149,7 +147,7 @@ fn create_query_struct(op: &Operation) -> eyre::Result { MaybeRef::Value { value } => value, MaybeRef::Ref { _ref } => eyre::bail!("todo: add deref parameters"), }; - if let ParameterIn::Query { param: query_param} = ¶m._in { + if let ParameterIn::Query { param: query_param } = ¶m._in { let ty = crate::methods::param_type(query_param, true)?; let field_name = crate::sanitize_ident(¶m.name); fields.push_str("pub "); @@ -199,7 +197,9 @@ fn create_query_struct(op: &Operation) -> eyre::Result { )?; } ParameterType::Array => { - let format = query_param.collection_format.unwrap_or(CollectionFormat::Csv); + let format = query_param + .collection_format + .unwrap_or(CollectionFormat::Csv); let item = query_param .items .as_ref()