fix warnings
This commit is contained in:
		
							parent
							
								
									787adac1a4
								
							
						
					
					
						commit
						4ccdce0395
					
				
					 3 changed files with 24 additions and 30 deletions
				
			
		| 
						 | 
				
			
			@ -98,7 +98,7 @@ fn schema_type_name(
 | 
			
		|||
                };
 | 
			
		||||
                Ok(name.to_owned())
 | 
			
		||||
            }
 | 
			
		||||
            SchemaType::List(list) => todo!(),
 | 
			
		||||
            SchemaType::List(_) => todo!(),
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        Ok("()".into())
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -137,8 +137,7 @@ fn fn_signature_from_op(spec: &OpenApiV2, op: &Operation) -> eyre::Result<String
 | 
			
		|||
fn fn_args_from_op(spec: &OpenApiV2, op: &Operation) -> eyre::Result<String> {
 | 
			
		||||
    let mut args = "&self".to_string();
 | 
			
		||||
    let mut has_query = false;
 | 
			
		||||
    let mut has_headers = false;
 | 
			
		||||
    let mut has_form = false;
 | 
			
		||||
    // let mut has_headers = false;
 | 
			
		||||
    if let Some(params) = &op.parameters {
 | 
			
		||||
        for param in params {
 | 
			
		||||
            let full_param = match ¶m {
 | 
			
		||||
| 
						 | 
				
			
			@ -153,8 +152,8 @@ fn fn_args_from_op(spec: &OpenApiV2, op: &Operation) -> eyre::Result<String> {
 | 
			
		|||
                    args.push_str(": ");
 | 
			
		||||
                    args.push_str(&type_name);
 | 
			
		||||
                }
 | 
			
		||||
                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 } => {
 | 
			
		||||
                    let ty = crate::schema_ref_type_name(spec, schema)?;
 | 
			
		||||
                    args.push_str(", ");
 | 
			
		||||
| 
						 | 
				
			
			@ -162,7 +161,7 @@ fn fn_args_from_op(spec: &OpenApiV2, op: &Operation) -> eyre::Result<String> {
 | 
			
		|||
                    args.push_str(": ");
 | 
			
		||||
                    args.push_str(&ty);
 | 
			
		||||
                }
 | 
			
		||||
                ParameterIn::FormData { param } => {
 | 
			
		||||
                ParameterIn::FormData { param: _ } => {
 | 
			
		||||
                    args.push_str(", ");
 | 
			
		||||
                    args.push_str(&crate::sanitize_ident(&full_param.name));
 | 
			
		||||
                    args.push_str(": Vec<u8>");
 | 
			
		||||
| 
						 | 
				
			
			@ -303,7 +302,7 @@ fn create_method_body(
 | 
			
		|||
    op: &Operation,
 | 
			
		||||
) -> eyre::Result<String> {
 | 
			
		||||
    let request = create_method_request(spec, method, path, op)?;
 | 
			
		||||
    let response = create_method_response(spec, method, path, op)?;
 | 
			
		||||
    let response = create_method_response(spec, op)?;
 | 
			
		||||
    Ok(format!("{request}\n    {response}"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -314,7 +313,7 @@ fn create_method_request(
 | 
			
		|||
    op: &Operation,
 | 
			
		||||
) -> eyre::Result<String> {
 | 
			
		||||
    let mut has_query = false;
 | 
			
		||||
    let mut has_headers = false;
 | 
			
		||||
    // let mut has_headers = false;
 | 
			
		||||
    let mut body_method = String::new();
 | 
			
		||||
    if let Some(params) = &op.parameters {
 | 
			
		||||
        for param in params {
 | 
			
		||||
| 
						 | 
				
			
			@ -324,10 +323,10 @@ 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::Body { schema } => {
 | 
			
		||||
                ParameterIn::Path { param: _ } => (/* do nothing */),
 | 
			
		||||
                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");
 | 
			
		||||
                    }
 | 
			
		||||
| 
						 | 
				
			
			@ -337,7 +336,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");
 | 
			
		||||
                    }
 | 
			
		||||
| 
						 | 
				
			
			@ -347,12 +346,11 @@ fn create_method_request(
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
    let mut fmt_str = sanitize_path_arg(path)?;
 | 
			
		||||
    let mut fmt_args = String::new();
 | 
			
		||||
    if has_query {
 | 
			
		||||
        fmt_str.push_str("?{query}");
 | 
			
		||||
    }
 | 
			
		||||
    let path_arg = if fmt_str.contains("{") {
 | 
			
		||||
        format!("&format!(\"{fmt_str}\"{fmt_args})")
 | 
			
		||||
        format!("&format!(\"{fmt_str}\")")
 | 
			
		||||
    } else {
 | 
			
		||||
        format!("\"{fmt_str}\"")
 | 
			
		||||
    };
 | 
			
		||||
| 
						 | 
				
			
			@ -407,8 +405,6 @@ fn sanitize_path_arg(mut path: &str) -> eyre::Result<String> {
 | 
			
		|||
 | 
			
		||||
fn create_method_response(
 | 
			
		||||
    spec: &OpenApiV2,
 | 
			
		||||
    method: &str,
 | 
			
		||||
    path: &str,
 | 
			
		||||
    op: &Operation,
 | 
			
		||||
) -> eyre::Result<String> {
 | 
			
		||||
    let mut has_empty = false;
 | 
			
		||||
| 
						 | 
				
			
			@ -523,7 +519,7 @@ impl ResponseType {
 | 
			
		|||
            (Some(a), Some(b)) if a != b => eyre::bail!("incompatible header types in response"),
 | 
			
		||||
            (Some(a), Some("()") | None) => new.body = Some(format!("Option<{a}>")),
 | 
			
		||||
            (Some("()") | None, Some(b)) => new.body = Some(format!("Option<{b}>")),
 | 
			
		||||
            (a, b) => new.body = self.body.or(other.body),
 | 
			
		||||
            (_, _) => new.body = self.body.or(other.body),
 | 
			
		||||
        };
 | 
			
		||||
        Ok(new)
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,8 +13,8 @@ pub fn create_structs(spec: &OpenApiV2) -> eyre::Result<String> {
 | 
			
		|||
            s.push_str(&strukt);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    for (path, item) in &spec.paths {
 | 
			
		||||
        let strukt = create_query_structs_for_path(&spec, path, item)?;
 | 
			
		||||
    for (_, item) in &spec.paths {
 | 
			
		||||
        let strukt = create_query_structs_for_path(item)?;
 | 
			
		||||
        s.push_str(&strukt);
 | 
			
		||||
    }
 | 
			
		||||
    s.push_str("\n}");
 | 
			
		||||
| 
						 | 
				
			
			@ -98,31 +98,29 @@ fn create_struct_docs(schema: &Schema) -> eyre::Result<String> {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
pub fn create_query_structs_for_path(
 | 
			
		||||
    spec: &OpenApiV2,
 | 
			
		||||
    path: &str,
 | 
			
		||||
    item: &PathItem,
 | 
			
		||||
) -> eyre::Result<String> {
 | 
			
		||||
    let mut s = String::new();
 | 
			
		||||
    if let Some(op) = &item.get {
 | 
			
		||||
        s.push_str(&create_query_struct(spec, path, op).wrap_err("GET")?);
 | 
			
		||||
        s.push_str(&create_query_struct(op).wrap_err("GET")?);
 | 
			
		||||
    }
 | 
			
		||||
    if let Some(op) = &item.put {
 | 
			
		||||
        s.push_str(&create_query_struct(spec, path, op).wrap_err("PUT")?);
 | 
			
		||||
        s.push_str(&create_query_struct(op).wrap_err("PUT")?);
 | 
			
		||||
    }
 | 
			
		||||
    if let Some(op) = &item.post {
 | 
			
		||||
        s.push_str(&create_query_struct(spec, path, op).wrap_err("POST")?);
 | 
			
		||||
        s.push_str(&create_query_struct(op).wrap_err("POST")?);
 | 
			
		||||
    }
 | 
			
		||||
    if let Some(op) = &item.delete {
 | 
			
		||||
        s.push_str(&create_query_struct(spec, path, op).wrap_err("DELETE")?);
 | 
			
		||||
        s.push_str(&create_query_struct(op).wrap_err("DELETE")?);
 | 
			
		||||
    }
 | 
			
		||||
    if let Some(op) = &item.options {
 | 
			
		||||
        s.push_str(&create_query_struct(spec, path, op).wrap_err("OPTIONS")?);
 | 
			
		||||
        s.push_str(&create_query_struct(op).wrap_err("OPTIONS")?);
 | 
			
		||||
    }
 | 
			
		||||
    if let Some(op) = &item.head {
 | 
			
		||||
        s.push_str(&create_query_struct(spec, path, op).wrap_err("HEAD")?);
 | 
			
		||||
        s.push_str(&create_query_struct(op).wrap_err("HEAD")?);
 | 
			
		||||
    }
 | 
			
		||||
    if let Some(op) = &item.patch {
 | 
			
		||||
        s.push_str(&create_query_struct(spec, path, op).wrap_err("PATCH")?);
 | 
			
		||||
        s.push_str(&create_query_struct(op).wrap_err("PATCH")?);
 | 
			
		||||
    }
 | 
			
		||||
    Ok(s)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -138,7 +136,7 @@ pub fn query_struct_name(op: &Operation) -> eyre::Result<String> {
 | 
			
		|||
    Ok(ty)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn create_query_struct(spec: &OpenApiV2, path: &str, op: &Operation) -> eyre::Result<String> {
 | 
			
		||||
fn create_query_struct(op: &Operation) -> eyre::Result<String> {
 | 
			
		||||
    let params = match &op.parameters {
 | 
			
		||||
        Some(params) => params,
 | 
			
		||||
        None => return Ok(String::new()),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue