Add form args
This commit is contained in:
		
							parent
							
								
									cc9aeaf6db
								
							
						
					
					
						commit
						5705f29f1a
					
				@ -57,9 +57,14 @@ struct MethodGenerator<'a> {
 | 
			
		||||
 | 
			
		||||
impl<'a> MethodGenerator<'a> {
 | 
			
		||||
    fn generate_method_without_builder(&self) -> MethodsAndExtra {
 | 
			
		||||
        let form_builder = self.parameters.mandatory.form_builder();
 | 
			
		||||
        let form_attributes =
 | 
			
		||||
            quote! { .multipart(reqwest::multipart::Form::new()#(#form_builder)*) };
 | 
			
		||||
 | 
			
		||||
        let builder = SendMethodBuilder::new(self.method_name, self.url, quote! { self.auth })
 | 
			
		||||
            .description(&self.method.description)
 | 
			
		||||
            .with_args(&self.parameters.mandatory.generate_params());
 | 
			
		||||
            .with_args(&self.parameters.mandatory.generate_params())
 | 
			
		||||
            .with_extra_form_args(&[form_attributes]);
 | 
			
		||||
 | 
			
		||||
        match create_return_type(self.group, self.method) {
 | 
			
		||||
            Some((return_type_name, return_type)) => {
 | 
			
		||||
@ -169,8 +174,7 @@ impl<'a> SendImplGenerator<'a> {
 | 
			
		||||
        quote! {
 | 
			
		||||
            impl<'a> #param_type<'a> {
 | 
			
		||||
                fn new(group: &'a #group_name, #(#mandatory_param_args),*) -> Self {
 | 
			
		||||
                    let form = reqwest::multipart::Form::new();
 | 
			
		||||
                    #(#mandatory_param_form_build)*
 | 
			
		||||
                    let form = reqwest::multipart::Form::new()#(#mandatory_param_form_build)*;
 | 
			
		||||
                    Self { group, form }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@ -226,7 +230,7 @@ impl<'a> MandatoryParams<'a> {
 | 
			
		||||
            .map(|param| {
 | 
			
		||||
                let name_ident = param.name_ident();
 | 
			
		||||
                let name = param.name();
 | 
			
		||||
                quote! { let form = form.text(#name, #name_ident.to_string()); }
 | 
			
		||||
                quote! { .text(#name, #name_ident.to_string()) }
 | 
			
		||||
            })
 | 
			
		||||
            .collect()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,7 @@ pub struct SendMethodBuilder {
 | 
			
		||||
    return_type: Option<proc_macro2::TokenStream>,
 | 
			
		||||
    description: Option<String>,
 | 
			
		||||
    args: Vec<proc_macro2::TokenStream>,
 | 
			
		||||
    extra_form_args: Vec<proc_macro2::TokenStream>,
 | 
			
		||||
    form: bool,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -26,6 +27,7 @@ impl SendMethodBuilder {
 | 
			
		||||
            description: None,
 | 
			
		||||
            form: false,
 | 
			
		||||
            args: vec![],
 | 
			
		||||
            extra_form_args: vec![],
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -45,10 +47,12 @@ impl SendMethodBuilder {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn with_args(mut self, value: &[proc_macro2::TokenStream]) -> Self {
 | 
			
		||||
        for v in value {
 | 
			
		||||
            self.args.push(v.clone());
 | 
			
		||||
        self.args = value.to_vec();
 | 
			
		||||
        self
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn with_extra_form_args(mut self, value: &[proc_macro2::TokenStream]) -> Self {
 | 
			
		||||
        self.extra_form_args = value.to_vec();
 | 
			
		||||
        self
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -71,6 +75,7 @@ impl SendMethodBuilder {
 | 
			
		||||
        } else {
 | 
			
		||||
            quote! {}
 | 
			
		||||
        };
 | 
			
		||||
        let extra_form_args = &self.extra_form_args;
 | 
			
		||||
 | 
			
		||||
        util::add_docs(
 | 
			
		||||
            &self.description,
 | 
			
		||||
@ -79,6 +84,7 @@ impl SendMethodBuilder {
 | 
			
		||||
                    let res = #auth_module_path
 | 
			
		||||
                        .authenticated_client(#url)
 | 
			
		||||
                        #form
 | 
			
		||||
                        #(#extra_form_args)*
 | 
			
		||||
                        .send()
 | 
			
		||||
                        .await?
 | 
			
		||||
                        #parse_type
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user