Skip to content

Commit

Permalink
add optional
Browse files Browse the repository at this point in the history
  • Loading branch information
cataggar committed Sep 24, 2023
1 parent 9b5306a commit 149e7a9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions services/autorust/codegen/src/codegen_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use camino::Utf8Path;
use heck::{ToPascalCase, ToShoutySnakeCase, ToSnakeCase};
use indexmap::IndexMap;
use proc_macro2::{Ident, TokenStream};
use quote::{quote, ToTokens};
use quote::quote;
use regex::Replacer;

/// Create a route call from the function name and to routes
Expand Down Expand Up @@ -340,11 +340,13 @@ fn create_function_params(parameters: &[&WebParameter]) -> crate::Result<TokenSt
for param in parameters.iter() {
let name = param.name().to_snake_case_ident()?;
if param.in_body() {
let tp = TypeNameCode::new(&param.type_name()?)?.into_token_stream();
let mut tp = TypeNameCode::new(&param.type_name()?)?;
tp = tp.optional(!param.required());
let body_tp = quote! { Json<#tp> };
params.push(quote! { #name: #body_tp });
} else {
let tp = TypeNameCode::new_ref(&param.type_name()?)?;
let mut tp = TypeNameCode::new_ref(&param.type_name()?)?;
tp = tp.optional(!param.required());
params.push(quote! { #name: #tp });
}
}
Expand Down

0 comments on commit 149e7a9

Please sign in to comment.