correct builder error message for Option types (#327)
This commit is contained in:
parent
c26af3bd95
commit
1b942d1146
|
@ -1401,18 +1401,26 @@ impl Generator {
|
||||||
OperationParameterType::Type(type_id) => {
|
OperationParameterType::Type(type_id) => {
|
||||||
let ty = self.type_space.get_type(type_id)?;
|
let ty = self.type_space.get_type(type_id)?;
|
||||||
let details = ty.details();
|
let details = ty.details();
|
||||||
let err_msg = format!("conversion to `{}` for {} failed", ty.name(), param.name);
|
|
||||||
match &details {
|
match &details {
|
||||||
typify::TypeDetails::Option(ref opt_id) => {
|
typify::TypeDetails::Option(opt_id) => {
|
||||||
// TODO currently we explicitly turn optional
|
// TODO currently we explicitly turn optional
|
||||||
// parameters into Option types; we could probably
|
// parameters into Option types; we could
|
||||||
// defer this to the code generation step to avoid the
|
// probably defer this to the code generation
|
||||||
// special handling here.
|
// step to avoid the special handling here.
|
||||||
let typ = self.type_space.get_type(opt_id)?.ident();
|
let inner_type =
|
||||||
|
self.type_space.get_type(opt_id)?;
|
||||||
|
let typ = inner_type.ident();
|
||||||
|
let err_msg = format!(
|
||||||
|
"conversion to `{}` for {} failed",
|
||||||
|
inner_type.name(),
|
||||||
|
param.name,
|
||||||
|
);
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
pub fn #param_name<V>(mut self, value: V)
|
pub fn #param_name<V>(
|
||||||
-> Self
|
mut self,
|
||||||
where V: std::convert::TryInto<#typ>
|
value: V,
|
||||||
|
) -> Self
|
||||||
|
where V: std::convert::TryInto<#typ>,
|
||||||
{
|
{
|
||||||
self.#param_name = value.try_into()
|
self.#param_name = value.try_into()
|
||||||
.map(Some)
|
.map(Some)
|
||||||
|
@ -1423,8 +1431,16 @@ impl Generator {
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let typ = ty.ident();
|
let typ = ty.ident();
|
||||||
|
let err_msg = format!(
|
||||||
|
"conversion to `{}` for {} failed",
|
||||||
|
ty.name(),
|
||||||
|
param.name,
|
||||||
|
);
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
pub fn #param_name<V>(mut self, value: V) -> Self
|
pub fn #param_name<V>(
|
||||||
|
mut self,
|
||||||
|
value: V,
|
||||||
|
) -> Self
|
||||||
where V: std::convert::TryInto<#typ>,
|
where V: std::convert::TryInto<#typ>,
|
||||||
{
|
{
|
||||||
self.#param_name = value.try_into()
|
self.#param_name = value.try_into()
|
||||||
|
@ -1437,8 +1453,10 @@ impl Generator {
|
||||||
}
|
}
|
||||||
|
|
||||||
OperationParameterType::RawBody => {
|
OperationParameterType::RawBody => {
|
||||||
let err_msg =
|
let err_msg = format!(
|
||||||
format!("conversion to `reqwest::Body` for {} failed", param.name);
|
"conversion to `reqwest::Body` for {} failed",
|
||||||
|
param.name,
|
||||||
|
);
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
pub fn #param_name<B>(mut self, value: B) -> Self
|
pub fn #param_name<B>(mut self, value: B) -> Self
|
||||||
|
|
|
@ -1856,7 +1856,7 @@ pub mod builder {
|
||||||
self.minseq = value
|
self.minseq = value
|
||||||
.try_into()
|
.try_into()
|
||||||
.map(Some)
|
.map(Some)
|
||||||
.map_err(|_| "conversion to `Option < u32 >` for minseq failed".to_string());
|
.map_err(|_| "conversion to `u32` for minseq failed".to_string());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1856,7 +1856,7 @@ pub mod builder {
|
||||||
self.minseq = value
|
self.minseq = value
|
||||||
.try_into()
|
.try_into()
|
||||||
.map(Some)
|
.map(Some)
|
||||||
.map_err(|_| "conversion to `Option < u32 >` for minseq failed".to_string());
|
.map_err(|_| "conversion to `u32` for minseq failed".to_string());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -112,7 +112,7 @@ pub mod builder {
|
||||||
self.key = value
|
self.key = value
|
||||||
.try_into()
|
.try_into()
|
||||||
.map(Some)
|
.map(Some)
|
||||||
.map_err(|_| "conversion to `Option < bool >` for key failed".to_string());
|
.map_err(|_| "conversion to `bool` for key failed".to_string());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ pub mod builder {
|
||||||
self.unique_key = value
|
self.unique_key = value
|
||||||
.try_into()
|
.try_into()
|
||||||
.map(Some)
|
.map(Some)
|
||||||
.map_err(|_| "conversion to `Option < String >` for unique_key failed".to_string());
|
.map_err(|_| "conversion to `String` for unique_key failed".to_string());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ pub mod builder {
|
||||||
self.key = value
|
self.key = value
|
||||||
.try_into()
|
.try_into()
|
||||||
.map(Some)
|
.map(Some)
|
||||||
.map_err(|_| "conversion to `Option < bool >` for key failed".to_string());
|
.map_err(|_| "conversion to `bool` for key failed".to_string());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ pub mod builder {
|
||||||
self.unique_key = value
|
self.unique_key = value
|
||||||
.try_into()
|
.try_into()
|
||||||
.map(Some)
|
.map(Some)
|
||||||
.map_err(|_| "conversion to `Option < String >` for unique_key failed".to_string());
|
.map_err(|_| "conversion to `String` for unique_key failed".to_string());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue