Change builder methods for setting a parameter with type T to accept a TryInto<T> (#133)

This makes constrained types a bit more
ergonomic and will allow us to accept fallible builders more easily
This commit is contained in:
Adam Leventhal 2022-07-18 11:55:21 -07:00 committed by GitHub
parent 244972129b
commit bfd194f39c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 7805 additions and 7985 deletions

View File

@ -208,8 +208,13 @@ impl Generator {
#[allow(unused_imports)] #[allow(unused_imports)]
use progenitor_client::{encode_path, RequestBuilderExt}; use progenitor_client::{encode_path, RequestBuilderExt};
pub mod types { pub mod types {
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
// This may be used by some impl Deserialize, but not all.
#[allow(unused_imports)]
use std::convert::TryFrom;
#shared #shared
#(#types)* #(#types)*
} }
@ -307,6 +312,8 @@ impl Generator {
RequestBuilderExt, RequestBuilderExt,
ResponseValue, ResponseValue,
}; };
#[allow(unused_imports)]
use std::convert::TryInto;
#(#builder_struct)* #(#builder_struct)*
} }

View File

@ -743,7 +743,7 @@ impl Generator {
}), }),
( (
OperationParameterKind::Body( OperationParameterKind::Body(
BodyContentType::FormUrlencoded, BodyContentType::FormUrlencoded
), ),
OperationParameterType::Type(_), OperationParameterType::Type(_),
) => Some(quote! { ) => Some(quote! {
@ -1111,27 +1111,36 @@ impl Generator {
} }
} }
/// Create the builder structs along with their impls /// Create the builder structs along with their impl bodies.
/// ///
/// Builder structs are generally of this form: /// Builder structs are generally of this form for a mandatory `param_1`
/// and an optional `param_2`:
/// ```ignore /// ```ignore
/// struct OperationId<'a> { /// struct OperationId<'a> {
/// client: &'a super::Client, /// client: &'a super::Client,
/// param_1: Option<SomeType>, /// param_1: Result<SomeType, String>,
/// param_2: Option<String>, /// param_2: Result<Option<String>, String>,
/// } /// }
/// ``` /// ```
/// ///
/// All parameters are present and all their types are Option<T>. Each /// All parameters are present and all their types are Result<T, String> or
/// parameter also has a corresponding method: /// Result<Option<T>, String> for optional parameters. Each parameter also
/// has a corresponding method:
/// ```ignore /// ```ignore
/// impl<'a> OperationId<'a> { /// impl<'a> OperationId<'a> {
/// pub fn param_1(self, value: SomeType) { /// pub fn param_1<V>(self, value: V)
/// self.param_1 = Some(value); /// where V: TryInto<SomeType>
/// {
/// self.param_1 = value.try_into()
/// .map_err(|_| #err_msg.to_string());
/// self /// self
/// } /// }
/// pub fn param_2<S: ToString>(self, value: S) { /// pub fn param_2<V>(self, value: V)
/// self.param_2 = Some(value.into()); /// where V: TryInto<SomeType>
/// {
/// self.param_2 = value.try_into()
/// .map(Some)
/// .map_err(|_| #err_msg.to_string());
/// self /// self
/// } /// }
/// } /// }
@ -1144,15 +1153,15 @@ impl Generator {
/// pub fn new(client: &'a super::Client) -> Self { /// pub fn new(client: &'a super::Client) -> Self {
/// Self { /// Self {
/// client, /// client,
/// param_1: None, /// param_1: Err("param_1 was not initialized".to_string()),
/// param_2: None, /// param_2: Ok(None),
/// } /// }
/// } /// }
/// } /// }
/// ``` /// ```
/// ///
/// Finally, builders have methods to execute the method, which takes care /// Finally, builders have methods to execute the operation. This simply
/// to check that required parameters are specified: /// resolves ach parameter with the ? (Try operator).
/// ```ignore /// ```ignore
/// impl<'a> OperationId<'a> { /// impl<'a> OperationId<'a> {
/// pub fn send(self) -> Result< /// pub fn send(self) -> Result<
@ -1165,76 +1174,77 @@ impl Generator {
/// param_2, /// param_2,
/// } = self; /// } = self;
/// ///
/// let (param_1, param_2) = match (param_1, param_2) { /// let param_1 = param_1.map_err(Error::InvalidRequest)?;
/// (Some(param_1), Some(param_2)) => (param_1, param_2), /// let param_2 = param_1.map_err(Error::InvalidRequest)?;
/// (param_1, param_2) => { ///
/// let mut missing = Vec::new(); /// // ... execute the body (see `method_sig_body`) ...
/// if param_1.is_none() {
/// missing.push(stringify!(param_1));
/// }
/// if param_2.is_none() {
/// missing.push(stringify!(param_2));
/// }
/// return Err(super::Error::InvalidRequest(format!(
/// "the following parameters are required: {}",
/// missing.join(", "),
/// )));
/// }
/// };
/// } /// }
/// } /// }
/// ``` /// ```
/// ///
/// Finally, paginated interfaces have a `stream()` method which uses the /// Finally, paginated interfaces have a `stream()` method which uses the
/// `send()` method above to fetch each page of results to assemble the /// `send()` method above to fetch each page of results to assemble the
/// items into a single impl Stream. /// items into a single `impl Stream`.
pub(crate) fn builder_struct( pub(crate) fn builder_struct(
&mut self, &mut self,
method: &OperationMethod, method: &OperationMethod,
tag_style: TagStyle, tag_style: TagStyle,
) -> Result<TokenStream> { ) -> Result<TokenStream> {
let mut cloneable = true; let struct_name = sanitize(&method.operation_id, Case::Pascal);
// Generate the builder structure properties, turning each type T into let struct_ident = format_ident!("{}", struct_name);
// an Option<T> (if it isn't already).
let properties = method // Generate an ident for each parameter.
let param_names = method
.params .params
.iter() .iter()
.map(|param| { .map(|param| format_ident!("{}", param.name))
let name = format_ident!("{}", param.name); .collect::<Vec<_>>();
let typ = match &param.typ {
let mut cloneable = true;
// Generate the type for each parameter.
let param_types = method
.params
.iter()
.map(|param| match &param.typ {
OperationParameterType::Type(type_id) => { OperationParameterType::Type(type_id) => {
// TODO currently we explicitly turn optional paramters
// into Option types; we could probably defer this to
// the code generation step to avoid the special
// handling here.
let ty = self.type_space.get_type(type_id)?; let ty = self.type_space.get_type(type_id)?;
let t = ty.ident(); let t = ty.ident();
let details = ty.details(); Ok(quote! { Result<#t, String> })
if let typify::TypeDetails::Option(_) = details {
t
} else {
quote! { Option<#t> }
}
} }
OperationParameterType::RawBody => { OperationParameterType::RawBody => {
cloneable = false; cloneable = false;
quote! { Option<reqwest::Body> } Ok(quote! { Result<reqwest::Body, String> })
} }
};
Ok(quote! {
#name: #typ
})
}) })
.collect::<Result<Vec<_>>>()?; .collect::<Result<Vec<_>>>()?;
let struct_name = sanitize(&method.operation_id, Case::Pascal); // Generate the devalue value for each parameter.
let struct_ident = format_ident!("{}", struct_name); let param_values = method
.params
.iter()
.map(|param| {
let opt = match &param.typ {
OperationParameterType::Type(type_id) => {
let ty = self.type_space.get_type(type_id)?;
let details = ty.details();
matches!(&details, typify::TypeDetails::Option(_))
}
OperationParameterType::RawBody => false,
};
if opt {
Ok(quote! { Ok(None) })
} else {
let err_msg = format!("{} was not initialized", param.name);
Ok(quote! { Err(#err_msg.to_string()) })
}
})
.collect::<Result<Vec<_>>>()?;
// For each parameter, we need an impl for the builder to let consumers // For each parameter, we need an impl for the builder to let consumers
// provide a value for the parameter. // provide a value.
let property_impls = method let param_impls = method
.params .params
.iter() .iter()
.map(|param| { .map(|param| {
@ -1242,21 +1252,23 @@ impl Generator {
match &param.typ { match &param.typ {
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 x = ty.details(); let details = ty.details();
match &x { let err_msg = format!("conversion to `{}` for {} failed", ty.name(), param.name);
typify::TypeDetails::String => { match &details {
Ok(quote! {
pub fn #param_name<S: ToString>(mut self, value: S) -> Self {
self.#param_name = Some(value.to_string());
self
}
})
}
typify::TypeDetails::Option(ref opt_id) => { typify::TypeDetails::Option(ref opt_id) => {
// TODO currently we explicitly turn optional
// parameters into Option types; we could probably
// defer this to the code generation step to avoid the
// special handling here.
let typ = self.type_space.get_type(opt_id)?.ident(); let typ = self.type_space.get_type(opt_id)?.ident();
Ok(quote!{ Ok(quote! {
pub fn #param_name(mut self, value: #typ) -> Self { pub fn #param_name<V>(mut self, value: V)
self.#param_name = Some(value); -> Self
where V: TryInto<#typ>
{
self.#param_name = value.try_into()
.map(Some)
.map_err(|_| #err_msg.to_string());
self self
} }
}) })
@ -1264,8 +1276,11 @@ impl Generator {
_ => { _ => {
let typ = ty.ident(); let typ = ty.ident();
Ok(quote! { Ok(quote! {
pub fn #param_name(mut self, value: #typ) -> Self { pub fn #param_name<V>(mut self, value: V) -> Self
self.#param_name = Some(value); where V: TryInto<#typ>,
{
self.#param_name = value.try_into()
.map_err(|_| #err_msg.to_string());
self self
} }
}) })
@ -1274,9 +1289,15 @@ impl Generator {
} }
OperationParameterType::RawBody => { OperationParameterType::RawBody => {
let err_msg =
format!("conversion to `reqwest::Body` for {} failed", param.name);
Ok(quote! { Ok(quote! {
pub fn #param_name<B: Into<reqwest::Body>>(mut self, value: B) -> Self { pub fn #param_name<B>(mut self, value: B) -> Self
self.#param_name = Some(value.into()); where B: TryInto<reqwest::Body>
{
self.#param_name = value.try_into()
.map_err(|_| #err_msg.to_string());
self self
} }
}) })
@ -1285,67 +1306,6 @@ impl Generator {
}) })
.collect::<Result<Vec<_>>>()?; .collect::<Result<Vec<_>>>()?;
let destructure = method
.params
.iter()
.map(|param| format_ident!("{}", param.name))
.collect::<Vec<_>>();
let req_names = method
.params
.iter()
.filter_map(|param| match param.kind {
OperationParameterKind::Path
| OperationParameterKind::Query(true)
| OperationParameterKind::Body(_) => {
Some(format_ident!("{}", param.name))
}
OperationParameterKind::Query(false) => None,
})
.collect::<Vec<_>>();
let required_extract = (!req_names.is_empty()).then(|| {
quote! {
let ( #( #req_names, )* ) = match ( #( #req_names, )* ) {
( #( Some(#req_names), )* ) => ( #( #req_names, )* ),
( #( #req_names, )* ) => {
let mut missing = Vec::new();
#(
if #req_names.is_none() {
missing.push(stringify!(#req_names));
}
)*
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
}
});
let param_props = method
.params
.iter()
.map(|param| {
let name = format_ident!("{}", param.name);
quote! {
#name: None
}
})
.collect::<Vec<_>>();
let new_impl = quote! {
pub fn new(client: &'a super::Client) -> Self {
Self {
client,
#(#param_props,)*
}
}
};
let MethodSigBody { let MethodSigBody {
success, success,
error, error,
@ -1358,27 +1318,6 @@ impl Generator {
method.path.to_string(), method.path.to_string(),
); );
let send_impl = quote! {
#[doc = #send_doc]
pub async fn send(self) -> Result<
ResponseValue<#success>,
Error<#error>,
> {
// Destructure the builder for convenience.
let Self {
client,
#( #destructure ),*
} = self;
// Extract parameters into variables, returning an error if
// a value has not been provided for all required parameters.
#required_extract
// Do the work.
#body
}
};
let stream_impl = method.dropshot_paginated.as_ref().map(|page_data| { let stream_impl = method.dropshot_paginated.as_ref().map(|page_data| {
// We're now using futures. // We're now using futures.
self.uses_futures = true; self.uses_futures = true;
@ -1387,7 +1326,7 @@ impl Generator {
if let OperationParameterKind::Query(_) = param.kind { if let OperationParameterKind::Query(_) = param.kind {
let name = format_ident!("{}", param.name); let name = format_ident!("{}", param.name);
Some(quote! { Some(quote! {
#name: None #name: Ok(None)
}) })
} else { } else {
None None
@ -1428,7 +1367,7 @@ impl Generator {
.map_ok(move |page| { .map_ok(move |page| {
let page = page.into_inner(); let page = page.into_inner();
// Create a stream from the items of the first page. // Create a stream from the first page of items.
let first = futures::stream::iter( let first = futures::stream::iter(
page.items.into_iter().map(Ok) page.items.into_iter().map(Ok)
); );
@ -1449,7 +1388,7 @@ impl Generator {
// template (with query parameters set // template (with query parameters set
// to None), overriding page_token. // to None), overriding page_token.
Self { Self {
page_token: next_page, page_token: Ok(next_page),
..next.clone() ..next.clone()
} }
.send() .send()
@ -1539,22 +1478,53 @@ impl Generator {
} }
}; };
let ret = quote! { Ok(quote! {
#[doc = #struct_doc] #[doc = #struct_doc]
#maybe_clone #maybe_clone
pub struct #struct_ident<'a> { pub struct #struct_ident<'a> {
client: &'a super::Client, client: &'a super::Client,
#( #properties ),* #( #param_names: #param_types, )*
} }
impl<'a> #struct_ident<'a> { impl<'a> #struct_ident<'a> {
#new_impl pub fn new(client: &'a super::Client) -> Self {
#( #property_impls )* Self {
#send_impl client,
#( #param_names: #param_values, )*
}
}
#( #param_impls )*
#[doc = #send_doc]
pub async fn send(self) -> Result<
ResponseValue<#success>,
Error<#error>,
> {
// Destructure the builder for convenience.
let Self {
client,
#( #param_names, )*
} = self;
// Extract parameters into variables, returning an error if
// a value has not been provided or there was a conversion
// error.
//
// TODO we could do something a bit nicer by collecting all
// errors rather than just reporting the first one.
#(
let #param_names =
#param_names.map_err(Error::InvalidRequest)?;
)*
// Do the work.
#body
}
#stream_impl #stream_impl
} }
}; })
Ok(ret)
} }
fn builder_helper(&self, method: &OperationMethod) -> BuilderImpl { fn builder_helper(&self, method: &OperationMethod) -> BuilderImpl {

View File

@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
pub use progenitor_client::{ByteStream, Error, ResponseValue}; pub use progenitor_client::{ByteStream, Error, ResponseValue};
pub mod types { pub mod types {
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[allow(unused_imports)]
use std::convert::TryFrom;
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Task { pub struct Task {
pub id: String, pub id: String,
@ -428,35 +430,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct TaskGet<'a> { pub struct TaskGet<'a> {
client: &'a super::Client, client: &'a super::Client,
task: Option<String>, task: Result<String, String>,
} }
impl<'a> TaskGet<'a> { impl<'a> TaskGet<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, task: None } Self {
client,
task: Err("task was not initialized".to_string()),
}
} }
pub fn task<S: ToString>(mut self, value: S) -> Self { pub fn task<V>(mut self, value: V) -> Self
self.task = Some(value.to_string()); where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self self
} }
///Sends a `GET` request to `/v1/task/{task}` ///Sends a `GET` request to `/v1/task/{task}`
pub async fn send(self) -> Result<ResponseValue<types::Task>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<types::Task>, Error<()>> {
let Self { client, task } = self; let Self { client, task } = self;
let (task,) = match (task,) { let task = task.map_err(Error::InvalidRequest)?;
(Some(task),) => (task,),
(task,) => {
let mut missing = Vec::new();
if task.is_none() {
missing.push(stringify!(task));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!( let url = format!(
"{}/v1/task/{}", "{}/v1/task/{}",
client.baseurl, client.baseurl,
@ -505,35 +503,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct TaskSubmit<'a> { pub struct TaskSubmit<'a> {
client: &'a super::Client, client: &'a super::Client,
body: Option<types::TaskSubmit>, body: Result<types::TaskSubmit, String>,
} }
impl<'a> TaskSubmit<'a> { impl<'a> TaskSubmit<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, body: None } Self {
client,
body: Err("body was not initialized".to_string()),
}
} }
pub fn body(mut self, value: types::TaskSubmit) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::TaskSubmit>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `TaskSubmit` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/v1/tasks` ///Sends a `POST` request to `/v1/tasks`
pub async fn send(self) -> Result<ResponseValue<types::TaskSubmitResult>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<types::TaskSubmitResult>, Error<()>> {
let Self { client, body } = self; let Self { client, body } = self;
let (body,) = match (body,) { let body = body.map_err(Error::InvalidRequest)?;
(Some(body),) => (body,),
(body,) => {
let mut missing = Vec::new();
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!("{}/v1/tasks", client.baseurl,); let url = format!("{}/v1/tasks", client.baseurl,);
let request = client.client.post(url).json(&body).build()?; let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await; let result = client.client.execute(request).await;
@ -551,26 +545,37 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct TaskEventsGet<'a> { pub struct TaskEventsGet<'a> {
client: &'a super::Client, client: &'a super::Client,
task: Option<String>, task: Result<String, String>,
minseq: Option<u32>, minseq: Result<Option<u32>, String>,
} }
impl<'a> TaskEventsGet<'a> { impl<'a> TaskEventsGet<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { Self {
client, client,
task: None, task: Err("task was not initialized".to_string()),
minseq: None, minseq: Ok(None),
} }
} }
pub fn task<S: ToString>(mut self, value: S) -> Self { pub fn task<V>(mut self, value: V) -> Self
self.task = Some(value.to_string()); where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self self
} }
pub fn minseq(mut self, value: u32) -> Self { pub fn minseq<V>(mut self, value: V) -> Self
self.minseq = Some(value); where
V: TryInto<u32>,
{
self.minseq = value
.try_into()
.map(Some)
.map_err(|_| "conversion to `Option < u32 >` for minseq failed".to_string());
self self
} }
@ -581,19 +586,8 @@ pub mod builder {
task, task,
minseq, minseq,
} = self; } = self;
let (task,) = match (task,) { let task = task.map_err(Error::InvalidRequest)?;
(Some(task),) => (task,), let minseq = minseq.map_err(Error::InvalidRequest)?;
(task,) => {
let mut missing = Vec::new();
if task.is_none() {
missing.push(stringify!(task));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!( let url = format!(
"{}/v1/tasks/{}/events", "{}/v1/tasks/{}/events",
client.baseurl, client.baseurl,
@ -619,35 +613,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct TaskOutputsGet<'a> { pub struct TaskOutputsGet<'a> {
client: &'a super::Client, client: &'a super::Client,
task: Option<String>, task: Result<String, String>,
} }
impl<'a> TaskOutputsGet<'a> { impl<'a> TaskOutputsGet<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, task: None } Self {
client,
task: Err("task was not initialized".to_string()),
}
} }
pub fn task<S: ToString>(mut self, value: S) -> Self { pub fn task<V>(mut self, value: V) -> Self
self.task = Some(value.to_string()); where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self self
} }
///Sends a `GET` request to `/v1/tasks/{task}/outputs` ///Sends a `GET` request to `/v1/tasks/{task}/outputs`
pub async fn send(self) -> Result<ResponseValue<Vec<types::TaskOutput>>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<Vec<types::TaskOutput>>, Error<()>> {
let Self { client, task } = self; let Self { client, task } = self;
let (task,) = match (task,) { let task = task.map_err(Error::InvalidRequest)?;
(Some(task),) => (task,),
(task,) => {
let mut missing = Vec::new();
if task.is_none() {
missing.push(stringify!(task));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!( let url = format!(
"{}/v1/tasks/{}/outputs", "{}/v1/tasks/{}/outputs",
client.baseurl, client.baseurl,
@ -669,26 +659,36 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct TaskOutputDownload<'a> { pub struct TaskOutputDownload<'a> {
client: &'a super::Client, client: &'a super::Client,
task: Option<String>, task: Result<String, String>,
output: Option<String>, output: Result<String, String>,
} }
impl<'a> TaskOutputDownload<'a> { impl<'a> TaskOutputDownload<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { Self {
client, client,
task: None, task: Err("task was not initialized".to_string()),
output: None, output: Err("output was not initialized".to_string()),
} }
} }
pub fn task<S: ToString>(mut self, value: S) -> Self { pub fn task<V>(mut self, value: V) -> Self
self.task = Some(value.to_string()); where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self self
} }
pub fn output<S: ToString>(mut self, value: S) -> Self { pub fn output<V>(mut self, value: V) -> Self
self.output = Some(value.to_string()); where
V: TryInto<String>,
{
self.output = value
.try_into()
.map_err(|_| "conversion to `String` for output failed".to_string());
self self
} }
@ -699,22 +699,8 @@ pub mod builder {
task, task,
output, output,
} = self; } = self;
let (task, output) = match (task, output) { let task = task.map_err(Error::InvalidRequest)?;
(Some(task), Some(output)) => (task, output), let output = output.map_err(Error::InvalidRequest)?;
(task, output) => {
let mut missing = Vec::new();
if task.is_none() {
missing.push(stringify!(task));
}
if output.is_none() {
missing.push(stringify!(output));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!( let url = format!(
"{}/v1/tasks/{}/outputs/{}", "{}/v1/tasks/{}/outputs/{}",
client.baseurl, client.baseurl,
@ -737,35 +723,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct UserCreate<'a> { pub struct UserCreate<'a> {
client: &'a super::Client, client: &'a super::Client,
body: Option<types::UserCreate>, body: Result<types::UserCreate, String>,
} }
impl<'a> UserCreate<'a> { impl<'a> UserCreate<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, body: None } Self {
client,
body: Err("body was not initialized".to_string()),
}
} }
pub fn body(mut self, value: types::UserCreate) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::UserCreate>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `UserCreate` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/v1/users` ///Sends a `POST` request to `/v1/users`
pub async fn send(self) -> Result<ResponseValue<types::UserCreateResult>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<types::UserCreateResult>, Error<()>> {
let Self { client, body } = self; let Self { client, body } = self;
let (body,) = match (body,) { let body = body.map_err(Error::InvalidRequest)?;
(Some(body),) => (body,),
(body,) => {
let mut missing = Vec::new();
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!("{}/v1/users", client.baseurl,); let url = format!("{}/v1/users", client.baseurl,);
let request = client.client.post(url).json(&body).build()?; let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await; let result = client.client.execute(request).await;
@ -810,35 +792,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct WorkerBootstrap<'a> { pub struct WorkerBootstrap<'a> {
client: &'a super::Client, client: &'a super::Client,
body: Option<types::WorkerBootstrap>, body: Result<types::WorkerBootstrap, String>,
} }
impl<'a> WorkerBootstrap<'a> { impl<'a> WorkerBootstrap<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, body: None } Self {
client,
body: Err("body was not initialized".to_string()),
}
} }
pub fn body(mut self, value: types::WorkerBootstrap) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::WorkerBootstrap>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `WorkerBootstrap` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/v1/worker/bootstrap` ///Sends a `POST` request to `/v1/worker/bootstrap`
pub async fn send(self) -> Result<ResponseValue<types::WorkerBootstrapResult>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<types::WorkerBootstrapResult>, Error<()>> {
let Self { client, body } = self; let Self { client, body } = self;
let (body,) = match (body,) { let body = body.map_err(Error::InvalidRequest)?;
(Some(body),) => (body,),
(body,) => {
let mut missing = Vec::new();
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!("{}/v1/worker/bootstrap", client.baseurl,); let url = format!("{}/v1/worker/bootstrap", client.baseurl,);
let request = client.client.post(url).json(&body).build()?; let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await; let result = client.client.execute(request).await;
@ -883,48 +861,44 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct WorkerTaskAppend<'a> { pub struct WorkerTaskAppend<'a> {
client: &'a super::Client, client: &'a super::Client,
task: Option<String>, task: Result<String, String>,
body: Option<types::WorkerAppendTask>, body: Result<types::WorkerAppendTask, String>,
} }
impl<'a> WorkerTaskAppend<'a> { impl<'a> WorkerTaskAppend<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { Self {
client, client,
task: None, task: Err("task was not initialized".to_string()),
body: None, body: Err("body was not initialized".to_string()),
} }
} }
pub fn task<S: ToString>(mut self, value: S) -> Self { pub fn task<V>(mut self, value: V) -> Self
self.task = Some(value.to_string()); where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self self
} }
pub fn body(mut self, value: types::WorkerAppendTask) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::WorkerAppendTask>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `WorkerAppendTask` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/v1/worker/task/{task}/append` ///Sends a `POST` request to `/v1/worker/task/{task}/append`
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self { client, task, body } = self; let Self { client, task, body } = self;
let (task, body) = match (task, body) { let task = task.map_err(Error::InvalidRequest)?;
(Some(task), Some(body)) => (task, body), let body = body.map_err(Error::InvalidRequest)?;
(task, body) => {
let mut missing = Vec::new();
if task.is_none() {
missing.push(stringify!(task));
}
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!( let url = format!(
"{}/v1/worker/task/{}/append", "{}/v1/worker/task/{}/append",
client.baseurl, client.baseurl,
@ -945,48 +919,44 @@ pub mod builder {
///[`Client::worker_task_upload_chunk`]: super::Client::worker_task_upload_chunk ///[`Client::worker_task_upload_chunk`]: super::Client::worker_task_upload_chunk
pub struct WorkerTaskUploadChunk<'a> { pub struct WorkerTaskUploadChunk<'a> {
client: &'a super::Client, client: &'a super::Client,
task: Option<String>, task: Result<String, String>,
body: Option<reqwest::Body>, body: Result<reqwest::Body, String>,
} }
impl<'a> WorkerTaskUploadChunk<'a> { impl<'a> WorkerTaskUploadChunk<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { Self {
client, client,
task: None, task: Err("task was not initialized".to_string()),
body: None, body: Err("body was not initialized".to_string()),
} }
} }
pub fn task<S: ToString>(mut self, value: S) -> Self { pub fn task<V>(mut self, value: V) -> Self
self.task = Some(value.to_string()); where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self self
} }
pub fn body<B: Into<reqwest::Body>>(mut self, value: B) -> Self { pub fn body<B>(mut self, value: B) -> Self
self.body = Some(value.into()); where
B: TryInto<reqwest::Body>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `reqwest::Body` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/v1/worker/task/{task}/chunk` ///Sends a `POST` request to `/v1/worker/task/{task}/chunk`
pub async fn send(self) -> Result<ResponseValue<types::UploadedChunk>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<types::UploadedChunk>, Error<()>> {
let Self { client, task, body } = self; let Self { client, task, body } = self;
let (task, body) = match (task, body) { let task = task.map_err(Error::InvalidRequest)?;
(Some(task), Some(body)) => (task, body), let body = body.map_err(Error::InvalidRequest)?;
(task, body) => {
let mut missing = Vec::new();
if task.is_none() {
missing.push(stringify!(task));
}
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!( let url = format!(
"{}/v1/worker/task/{}/chunk", "{}/v1/worker/task/{}/chunk",
client.baseurl, client.baseurl,
@ -1016,48 +986,44 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct WorkerTaskComplete<'a> { pub struct WorkerTaskComplete<'a> {
client: &'a super::Client, client: &'a super::Client,
task: Option<String>, task: Result<String, String>,
body: Option<types::WorkerCompleteTask>, body: Result<types::WorkerCompleteTask, String>,
} }
impl<'a> WorkerTaskComplete<'a> { impl<'a> WorkerTaskComplete<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { Self {
client, client,
task: None, task: Err("task was not initialized".to_string()),
body: None, body: Err("body was not initialized".to_string()),
} }
} }
pub fn task<S: ToString>(mut self, value: S) -> Self { pub fn task<V>(mut self, value: V) -> Self
self.task = Some(value.to_string()); where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self self
} }
pub fn body(mut self, value: types::WorkerCompleteTask) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::WorkerCompleteTask>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `WorkerCompleteTask` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/v1/worker/task/{task}/complete` ///Sends a `POST` request to `/v1/worker/task/{task}/complete`
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self { client, task, body } = self; let Self { client, task, body } = self;
let (task, body) = match (task, body) { let task = task.map_err(Error::InvalidRequest)?;
(Some(task), Some(body)) => (task, body), let body = body.map_err(Error::InvalidRequest)?;
(task, body) => {
let mut missing = Vec::new();
if task.is_none() {
missing.push(stringify!(task));
}
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!( let url = format!(
"{}/v1/worker/task/{}/complete", "{}/v1/worker/task/{}/complete",
client.baseurl, client.baseurl,
@ -1079,48 +1045,44 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct WorkerTaskAddOutput<'a> { pub struct WorkerTaskAddOutput<'a> {
client: &'a super::Client, client: &'a super::Client,
task: Option<String>, task: Result<String, String>,
body: Option<types::WorkerAddOutput>, body: Result<types::WorkerAddOutput, String>,
} }
impl<'a> WorkerTaskAddOutput<'a> { impl<'a> WorkerTaskAddOutput<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { Self {
client, client,
task: None, task: Err("task was not initialized".to_string()),
body: None, body: Err("body was not initialized".to_string()),
} }
} }
pub fn task<S: ToString>(mut self, value: S) -> Self { pub fn task<V>(mut self, value: V) -> Self
self.task = Some(value.to_string()); where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self self
} }
pub fn body(mut self, value: types::WorkerAddOutput) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::WorkerAddOutput>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `WorkerAddOutput` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/v1/worker/task/{task}/output` ///Sends a `POST` request to `/v1/worker/task/{task}/output`
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self { client, task, body } = self; let Self { client, task, body } = self;
let (task, body) = match (task, body) { let task = task.map_err(Error::InvalidRequest)?;
(Some(task), Some(body)) => (task, body), let body = body.map_err(Error::InvalidRequest)?;
(task, body) => {
let mut missing = Vec::new();
if task.is_none() {
missing.push(stringify!(task));
}
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!( let url = format!(
"{}/v1/worker/task/{}/output", "{}/v1/worker/task/{}/output",
client.baseurl, client.baseurl,

View File

@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
pub use progenitor_client::{ByteStream, Error, ResponseValue}; pub use progenitor_client::{ByteStream, Error, ResponseValue};
pub mod types { pub mod types {
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[allow(unused_imports)]
use std::convert::TryFrom;
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)] #[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct Task { pub struct Task {
pub id: String, pub id: String,
@ -368,6 +370,8 @@ pub mod builder {
use super::types; use super::types;
#[allow(unused_imports)] #[allow(unused_imports)]
use super::{encode_path, ByteStream, Error, RequestBuilderExt, ResponseValue}; use super::{encode_path, ByteStream, Error, RequestBuilderExt, ResponseValue};
#[allow(unused_imports)]
use std::convert::TryInto;
///Builder for [`Client::control_hold`] ///Builder for [`Client::control_hold`]
/// ///
///[`Client::control_hold`]: super::Client::control_hold ///[`Client::control_hold`]: super::Client::control_hold
@ -428,35 +432,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct TaskGet<'a> { pub struct TaskGet<'a> {
client: &'a super::Client, client: &'a super::Client,
task: Option<String>, task: Result<String, String>,
} }
impl<'a> TaskGet<'a> { impl<'a> TaskGet<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, task: None } Self {
client,
task: Err("task was not initialized".to_string()),
}
} }
pub fn task<S: ToString>(mut self, value: S) -> Self { pub fn task<V>(mut self, value: V) -> Self
self.task = Some(value.to_string()); where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self self
} }
///Sends a `GET` request to `/v1/task/{task}` ///Sends a `GET` request to `/v1/task/{task}`
pub async fn send(self) -> Result<ResponseValue<types::Task>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<types::Task>, Error<()>> {
let Self { client, task } = self; let Self { client, task } = self;
let (task,) = match (task,) { let task = task.map_err(Error::InvalidRequest)?;
(Some(task),) => (task,),
(task,) => {
let mut missing = Vec::new();
if task.is_none() {
missing.push(stringify!(task));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!( let url = format!(
"{}/v1/task/{}", "{}/v1/task/{}",
client.baseurl, client.baseurl,
@ -505,35 +505,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct TaskSubmit<'a> { pub struct TaskSubmit<'a> {
client: &'a super::Client, client: &'a super::Client,
body: Option<types::TaskSubmit>, body: Result<types::TaskSubmit, String>,
} }
impl<'a> TaskSubmit<'a> { impl<'a> TaskSubmit<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, body: None } Self {
client,
body: Err("body was not initialized".to_string()),
}
} }
pub fn body(mut self, value: types::TaskSubmit) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::TaskSubmit>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `TaskSubmit` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/v1/tasks` ///Sends a `POST` request to `/v1/tasks`
pub async fn send(self) -> Result<ResponseValue<types::TaskSubmitResult>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<types::TaskSubmitResult>, Error<()>> {
let Self { client, body } = self; let Self { client, body } = self;
let (body,) = match (body,) { let body = body.map_err(Error::InvalidRequest)?;
(Some(body),) => (body,),
(body,) => {
let mut missing = Vec::new();
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!("{}/v1/tasks", client.baseurl,); let url = format!("{}/v1/tasks", client.baseurl,);
let request = client.client.post(url).json(&body).build()?; let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await; let result = client.client.execute(request).await;
@ -551,26 +547,37 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct TaskEventsGet<'a> { pub struct TaskEventsGet<'a> {
client: &'a super::Client, client: &'a super::Client,
task: Option<String>, task: Result<String, String>,
minseq: Option<u32>, minseq: Result<Option<u32>, String>,
} }
impl<'a> TaskEventsGet<'a> { impl<'a> TaskEventsGet<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { Self {
client, client,
task: None, task: Err("task was not initialized".to_string()),
minseq: None, minseq: Ok(None),
} }
} }
pub fn task<S: ToString>(mut self, value: S) -> Self { pub fn task<V>(mut self, value: V) -> Self
self.task = Some(value.to_string()); where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self self
} }
pub fn minseq(mut self, value: u32) -> Self { pub fn minseq<V>(mut self, value: V) -> Self
self.minseq = Some(value); where
V: TryInto<u32>,
{
self.minseq = value
.try_into()
.map(Some)
.map_err(|_| "conversion to `Option < u32 >` for minseq failed".to_string());
self self
} }
@ -581,19 +588,8 @@ pub mod builder {
task, task,
minseq, minseq,
} = self; } = self;
let (task,) = match (task,) { let task = task.map_err(Error::InvalidRequest)?;
(Some(task),) => (task,), let minseq = minseq.map_err(Error::InvalidRequest)?;
(task,) => {
let mut missing = Vec::new();
if task.is_none() {
missing.push(stringify!(task));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!( let url = format!(
"{}/v1/tasks/{}/events", "{}/v1/tasks/{}/events",
client.baseurl, client.baseurl,
@ -619,35 +615,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct TaskOutputsGet<'a> { pub struct TaskOutputsGet<'a> {
client: &'a super::Client, client: &'a super::Client,
task: Option<String>, task: Result<String, String>,
} }
impl<'a> TaskOutputsGet<'a> { impl<'a> TaskOutputsGet<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, task: None } Self {
client,
task: Err("task was not initialized".to_string()),
}
} }
pub fn task<S: ToString>(mut self, value: S) -> Self { pub fn task<V>(mut self, value: V) -> Self
self.task = Some(value.to_string()); where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self self
} }
///Sends a `GET` request to `/v1/tasks/{task}/outputs` ///Sends a `GET` request to `/v1/tasks/{task}/outputs`
pub async fn send(self) -> Result<ResponseValue<Vec<types::TaskOutput>>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<Vec<types::TaskOutput>>, Error<()>> {
let Self { client, task } = self; let Self { client, task } = self;
let (task,) = match (task,) { let task = task.map_err(Error::InvalidRequest)?;
(Some(task),) => (task,),
(task,) => {
let mut missing = Vec::new();
if task.is_none() {
missing.push(stringify!(task));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!( let url = format!(
"{}/v1/tasks/{}/outputs", "{}/v1/tasks/{}/outputs",
client.baseurl, client.baseurl,
@ -669,26 +661,36 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct TaskOutputDownload<'a> { pub struct TaskOutputDownload<'a> {
client: &'a super::Client, client: &'a super::Client,
task: Option<String>, task: Result<String, String>,
output: Option<String>, output: Result<String, String>,
} }
impl<'a> TaskOutputDownload<'a> { impl<'a> TaskOutputDownload<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { Self {
client, client,
task: None, task: Err("task was not initialized".to_string()),
output: None, output: Err("output was not initialized".to_string()),
} }
} }
pub fn task<S: ToString>(mut self, value: S) -> Self { pub fn task<V>(mut self, value: V) -> Self
self.task = Some(value.to_string()); where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self self
} }
pub fn output<S: ToString>(mut self, value: S) -> Self { pub fn output<V>(mut self, value: V) -> Self
self.output = Some(value.to_string()); where
V: TryInto<String>,
{
self.output = value
.try_into()
.map_err(|_| "conversion to `String` for output failed".to_string());
self self
} }
@ -699,22 +701,8 @@ pub mod builder {
task, task,
output, output,
} = self; } = self;
let (task, output) = match (task, output) { let task = task.map_err(Error::InvalidRequest)?;
(Some(task), Some(output)) => (task, output), let output = output.map_err(Error::InvalidRequest)?;
(task, output) => {
let mut missing = Vec::new();
if task.is_none() {
missing.push(stringify!(task));
}
if output.is_none() {
missing.push(stringify!(output));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!( let url = format!(
"{}/v1/tasks/{}/outputs/{}", "{}/v1/tasks/{}/outputs/{}",
client.baseurl, client.baseurl,
@ -737,35 +725,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct UserCreate<'a> { pub struct UserCreate<'a> {
client: &'a super::Client, client: &'a super::Client,
body: Option<types::UserCreate>, body: Result<types::UserCreate, String>,
} }
impl<'a> UserCreate<'a> { impl<'a> UserCreate<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, body: None } Self {
client,
body: Err("body was not initialized".to_string()),
}
} }
pub fn body(mut self, value: types::UserCreate) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::UserCreate>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `UserCreate` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/v1/users` ///Sends a `POST` request to `/v1/users`
pub async fn send(self) -> Result<ResponseValue<types::UserCreateResult>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<types::UserCreateResult>, Error<()>> {
let Self { client, body } = self; let Self { client, body } = self;
let (body,) = match (body,) { let body = body.map_err(Error::InvalidRequest)?;
(Some(body),) => (body,),
(body,) => {
let mut missing = Vec::new();
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!("{}/v1/users", client.baseurl,); let url = format!("{}/v1/users", client.baseurl,);
let request = client.client.post(url).json(&body).build()?; let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await; let result = client.client.execute(request).await;
@ -810,35 +794,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct WorkerBootstrap<'a> { pub struct WorkerBootstrap<'a> {
client: &'a super::Client, client: &'a super::Client,
body: Option<types::WorkerBootstrap>, body: Result<types::WorkerBootstrap, String>,
} }
impl<'a> WorkerBootstrap<'a> { impl<'a> WorkerBootstrap<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, body: None } Self {
client,
body: Err("body was not initialized".to_string()),
}
} }
pub fn body(mut self, value: types::WorkerBootstrap) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::WorkerBootstrap>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `WorkerBootstrap` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/v1/worker/bootstrap` ///Sends a `POST` request to `/v1/worker/bootstrap`
pub async fn send(self) -> Result<ResponseValue<types::WorkerBootstrapResult>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<types::WorkerBootstrapResult>, Error<()>> {
let Self { client, body } = self; let Self { client, body } = self;
let (body,) = match (body,) { let body = body.map_err(Error::InvalidRequest)?;
(Some(body),) => (body,),
(body,) => {
let mut missing = Vec::new();
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!("{}/v1/worker/bootstrap", client.baseurl,); let url = format!("{}/v1/worker/bootstrap", client.baseurl,);
let request = client.client.post(url).json(&body).build()?; let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await; let result = client.client.execute(request).await;
@ -883,48 +863,44 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct WorkerTaskAppend<'a> { pub struct WorkerTaskAppend<'a> {
client: &'a super::Client, client: &'a super::Client,
task: Option<String>, task: Result<String, String>,
body: Option<types::WorkerAppendTask>, body: Result<types::WorkerAppendTask, String>,
} }
impl<'a> WorkerTaskAppend<'a> { impl<'a> WorkerTaskAppend<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { Self {
client, client,
task: None, task: Err("task was not initialized".to_string()),
body: None, body: Err("body was not initialized".to_string()),
} }
} }
pub fn task<S: ToString>(mut self, value: S) -> Self { pub fn task<V>(mut self, value: V) -> Self
self.task = Some(value.to_string()); where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self self
} }
pub fn body(mut self, value: types::WorkerAppendTask) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::WorkerAppendTask>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `WorkerAppendTask` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/v1/worker/task/{task}/append` ///Sends a `POST` request to `/v1/worker/task/{task}/append`
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self { client, task, body } = self; let Self { client, task, body } = self;
let (task, body) = match (task, body) { let task = task.map_err(Error::InvalidRequest)?;
(Some(task), Some(body)) => (task, body), let body = body.map_err(Error::InvalidRequest)?;
(task, body) => {
let mut missing = Vec::new();
if task.is_none() {
missing.push(stringify!(task));
}
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!( let url = format!(
"{}/v1/worker/task/{}/append", "{}/v1/worker/task/{}/append",
client.baseurl, client.baseurl,
@ -945,48 +921,44 @@ pub mod builder {
///[`Client::worker_task_upload_chunk`]: super::Client::worker_task_upload_chunk ///[`Client::worker_task_upload_chunk`]: super::Client::worker_task_upload_chunk
pub struct WorkerTaskUploadChunk<'a> { pub struct WorkerTaskUploadChunk<'a> {
client: &'a super::Client, client: &'a super::Client,
task: Option<String>, task: Result<String, String>,
body: Option<reqwest::Body>, body: Result<reqwest::Body, String>,
} }
impl<'a> WorkerTaskUploadChunk<'a> { impl<'a> WorkerTaskUploadChunk<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { Self {
client, client,
task: None, task: Err("task was not initialized".to_string()),
body: None, body: Err("body was not initialized".to_string()),
} }
} }
pub fn task<S: ToString>(mut self, value: S) -> Self { pub fn task<V>(mut self, value: V) -> Self
self.task = Some(value.to_string()); where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self self
} }
pub fn body<B: Into<reqwest::Body>>(mut self, value: B) -> Self { pub fn body<B>(mut self, value: B) -> Self
self.body = Some(value.into()); where
B: TryInto<reqwest::Body>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `reqwest::Body` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/v1/worker/task/{task}/chunk` ///Sends a `POST` request to `/v1/worker/task/{task}/chunk`
pub async fn send(self) -> Result<ResponseValue<types::UploadedChunk>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<types::UploadedChunk>, Error<()>> {
let Self { client, task, body } = self; let Self { client, task, body } = self;
let (task, body) = match (task, body) { let task = task.map_err(Error::InvalidRequest)?;
(Some(task), Some(body)) => (task, body), let body = body.map_err(Error::InvalidRequest)?;
(task, body) => {
let mut missing = Vec::new();
if task.is_none() {
missing.push(stringify!(task));
}
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!( let url = format!(
"{}/v1/worker/task/{}/chunk", "{}/v1/worker/task/{}/chunk",
client.baseurl, client.baseurl,
@ -1016,48 +988,44 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct WorkerTaskComplete<'a> { pub struct WorkerTaskComplete<'a> {
client: &'a super::Client, client: &'a super::Client,
task: Option<String>, task: Result<String, String>,
body: Option<types::WorkerCompleteTask>, body: Result<types::WorkerCompleteTask, String>,
} }
impl<'a> WorkerTaskComplete<'a> { impl<'a> WorkerTaskComplete<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { Self {
client, client,
task: None, task: Err("task was not initialized".to_string()),
body: None, body: Err("body was not initialized".to_string()),
} }
} }
pub fn task<S: ToString>(mut self, value: S) -> Self { pub fn task<V>(mut self, value: V) -> Self
self.task = Some(value.to_string()); where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self self
} }
pub fn body(mut self, value: types::WorkerCompleteTask) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::WorkerCompleteTask>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `WorkerCompleteTask` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/v1/worker/task/{task}/complete` ///Sends a `POST` request to `/v1/worker/task/{task}/complete`
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self { client, task, body } = self; let Self { client, task, body } = self;
let (task, body) = match (task, body) { let task = task.map_err(Error::InvalidRequest)?;
(Some(task), Some(body)) => (task, body), let body = body.map_err(Error::InvalidRequest)?;
(task, body) => {
let mut missing = Vec::new();
if task.is_none() {
missing.push(stringify!(task));
}
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!( let url = format!(
"{}/v1/worker/task/{}/complete", "{}/v1/worker/task/{}/complete",
client.baseurl, client.baseurl,
@ -1079,48 +1047,44 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct WorkerTaskAddOutput<'a> { pub struct WorkerTaskAddOutput<'a> {
client: &'a super::Client, client: &'a super::Client,
task: Option<String>, task: Result<String, String>,
body: Option<types::WorkerAddOutput>, body: Result<types::WorkerAddOutput, String>,
} }
impl<'a> WorkerTaskAddOutput<'a> { impl<'a> WorkerTaskAddOutput<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { Self {
client, client,
task: None, task: Err("task was not initialized".to_string()),
body: None, body: Err("body was not initialized".to_string()),
} }
} }
pub fn task<S: ToString>(mut self, value: S) -> Self { pub fn task<V>(mut self, value: V) -> Self
self.task = Some(value.to_string()); where
V: TryInto<String>,
{
self.task = value
.try_into()
.map_err(|_| "conversion to `String` for task failed".to_string());
self self
} }
pub fn body(mut self, value: types::WorkerAddOutput) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::WorkerAddOutput>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `WorkerAddOutput` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/v1/worker/task/{task}/output` ///Sends a `POST` request to `/v1/worker/task/{task}/output`
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self { client, task, body } = self; let Self { client, task, body } = self;
let (task, body) = match (task, body) { let task = task.map_err(Error::InvalidRequest)?;
(Some(task), Some(body)) => (task, body), let body = body.map_err(Error::InvalidRequest)?;
(task, body) => {
let mut missing = Vec::new();
if task.is_none() {
missing.push(stringify!(task));
}
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!( let url = format!(
"{}/v1/worker/task/{}/output", "{}/v1/worker/task/{}/output",
client.baseurl, client.baseurl,

View File

@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
pub use progenitor_client::{ByteStream, Error, ResponseValue}; pub use progenitor_client::{ByteStream, Error, ResponseValue};
pub mod types { pub mod types {
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[allow(unused_imports)]
use std::convert::TryFrom;
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Task { pub struct Task {
pub id: String, pub id: String,

View File

@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
pub use progenitor_client::{ByteStream, Error, ResponseValue}; pub use progenitor_client::{ByteStream, Error, ResponseValue};
pub mod types { pub mod types {
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[allow(unused_imports)]
use std::convert::TryFrom;
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct EnrolBody { pub struct EnrolBody {
pub host: String, pub host: String,
@ -182,35 +184,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct Enrol<'a> { pub struct Enrol<'a> {
client: &'a super::Client, client: &'a super::Client,
body: Option<types::EnrolBody>, body: Result<types::EnrolBody, String>,
} }
impl<'a> Enrol<'a> { impl<'a> Enrol<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, body: None } Self {
client,
body: Err("body was not initialized".to_string()),
}
} }
pub fn body(mut self, value: types::EnrolBody) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::EnrolBody>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `EnrolBody` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/enrol` ///Sends a `POST` request to `/enrol`
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self { client, body } = self; let Self { client, body } = self;
let (body,) = match (body,) { let body = body.map_err(Error::InvalidRequest)?;
(Some(body),) => (body,),
(body,) => {
let mut missing = Vec::new();
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!("{}/enrol", client.baseurl,); let url = format!("{}/enrol", client.baseurl,);
let request = client.client.post(url).json(&body).build()?; let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await; let result = client.client.execute(request).await;
@ -282,35 +280,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct ReportFinish<'a> { pub struct ReportFinish<'a> {
client: &'a super::Client, client: &'a super::Client,
body: Option<types::ReportFinishBody>, body: Result<types::ReportFinishBody, String>,
} }
impl<'a> ReportFinish<'a> { impl<'a> ReportFinish<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, body: None } Self {
client,
body: Err("body was not initialized".to_string()),
}
} }
pub fn body(mut self, value: types::ReportFinishBody) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::ReportFinishBody>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `ReportFinishBody` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/report/finish` ///Sends a `POST` request to `/report/finish`
pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> {
let Self { client, body } = self; let Self { client, body } = self;
let (body,) = match (body,) { let body = body.map_err(Error::InvalidRequest)?;
(Some(body),) => (body,),
(body,) => {
let mut missing = Vec::new();
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!("{}/report/finish", client.baseurl,); let url = format!("{}/report/finish", client.baseurl,);
let request = client.client.post(url).json(&body).build()?; let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await; let result = client.client.execute(request).await;
@ -328,35 +322,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct ReportOutput<'a> { pub struct ReportOutput<'a> {
client: &'a super::Client, client: &'a super::Client,
body: Option<types::ReportOutputBody>, body: Result<types::ReportOutputBody, String>,
} }
impl<'a> ReportOutput<'a> { impl<'a> ReportOutput<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, body: None } Self {
client,
body: Err("body was not initialized".to_string()),
}
} }
pub fn body(mut self, value: types::ReportOutputBody) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::ReportOutputBody>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `ReportOutputBody` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/report/output` ///Sends a `POST` request to `/report/output`
pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> {
let Self { client, body } = self; let Self { client, body } = self;
let (body,) = match (body,) { let body = body.map_err(Error::InvalidRequest)?;
(Some(body),) => (body,),
(body,) => {
let mut missing = Vec::new();
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!("{}/report/output", client.baseurl,); let url = format!("{}/report/output", client.baseurl,);
let request = client.client.post(url).json(&body).build()?; let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await; let result = client.client.execute(request).await;
@ -374,35 +364,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct ReportStart<'a> { pub struct ReportStart<'a> {
client: &'a super::Client, client: &'a super::Client,
body: Option<types::ReportStartBody>, body: Result<types::ReportStartBody, String>,
} }
impl<'a> ReportStart<'a> { impl<'a> ReportStart<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, body: None } Self {
client,
body: Err("body was not initialized".to_string()),
}
} }
pub fn body(mut self, value: types::ReportStartBody) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::ReportStartBody>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `ReportStartBody` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/report/start` ///Sends a `POST` request to `/report/start`
pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> {
let Self { client, body } = self; let Self { client, body } = self;
let (body,) = match (body,) { let body = body.map_err(Error::InvalidRequest)?;
(Some(body),) => (body,),
(body,) => {
let mut missing = Vec::new();
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!("{}/report/start", client.baseurl,); let url = format!("{}/report/start", client.baseurl,);
let request = client.client.post(url).json(&body).build()?; let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await; let result = client.client.execute(request).await;

View File

@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
pub use progenitor_client::{ByteStream, Error, ResponseValue}; pub use progenitor_client::{ByteStream, Error, ResponseValue};
pub mod types { pub mod types {
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[allow(unused_imports)]
use std::convert::TryFrom;
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)] #[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct EnrolBody { pub struct EnrolBody {
pub host: String, pub host: String,
@ -176,41 +178,39 @@ pub mod builder {
use super::types; use super::types;
#[allow(unused_imports)] #[allow(unused_imports)]
use super::{encode_path, ByteStream, Error, RequestBuilderExt, ResponseValue}; use super::{encode_path, ByteStream, Error, RequestBuilderExt, ResponseValue};
#[allow(unused_imports)]
use std::convert::TryInto;
///Builder for [`Client::enrol`] ///Builder for [`Client::enrol`]
/// ///
///[`Client::enrol`]: super::Client::enrol ///[`Client::enrol`]: super::Client::enrol
#[derive(Clone)] #[derive(Clone)]
pub struct Enrol<'a> { pub struct Enrol<'a> {
client: &'a super::Client, client: &'a super::Client,
body: Option<types::EnrolBody>, body: Result<types::EnrolBody, String>,
} }
impl<'a> Enrol<'a> { impl<'a> Enrol<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, body: None } Self {
client,
body: Err("body was not initialized".to_string()),
}
} }
pub fn body(mut self, value: types::EnrolBody) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::EnrolBody>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `EnrolBody` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/enrol` ///Sends a `POST` request to `/enrol`
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self { client, body } = self; let Self { client, body } = self;
let (body,) = match (body,) { let body = body.map_err(Error::InvalidRequest)?;
(Some(body),) => (body,),
(body,) => {
let mut missing = Vec::new();
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!("{}/enrol", client.baseurl,); let url = format!("{}/enrol", client.baseurl,);
let request = client.client.post(url).json(&body).build()?; let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await; let result = client.client.execute(request).await;
@ -282,35 +282,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct ReportFinish<'a> { pub struct ReportFinish<'a> {
client: &'a super::Client, client: &'a super::Client,
body: Option<types::ReportFinishBody>, body: Result<types::ReportFinishBody, String>,
} }
impl<'a> ReportFinish<'a> { impl<'a> ReportFinish<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, body: None } Self {
client,
body: Err("body was not initialized".to_string()),
}
} }
pub fn body(mut self, value: types::ReportFinishBody) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::ReportFinishBody>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `ReportFinishBody` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/report/finish` ///Sends a `POST` request to `/report/finish`
pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> {
let Self { client, body } = self; let Self { client, body } = self;
let (body,) = match (body,) { let body = body.map_err(Error::InvalidRequest)?;
(Some(body),) => (body,),
(body,) => {
let mut missing = Vec::new();
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!("{}/report/finish", client.baseurl,); let url = format!("{}/report/finish", client.baseurl,);
let request = client.client.post(url).json(&body).build()?; let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await; let result = client.client.execute(request).await;
@ -328,35 +324,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct ReportOutput<'a> { pub struct ReportOutput<'a> {
client: &'a super::Client, client: &'a super::Client,
body: Option<types::ReportOutputBody>, body: Result<types::ReportOutputBody, String>,
} }
impl<'a> ReportOutput<'a> { impl<'a> ReportOutput<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, body: None } Self {
client,
body: Err("body was not initialized".to_string()),
}
} }
pub fn body(mut self, value: types::ReportOutputBody) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::ReportOutputBody>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `ReportOutputBody` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/report/output` ///Sends a `POST` request to `/report/output`
pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> {
let Self { client, body } = self; let Self { client, body } = self;
let (body,) = match (body,) { let body = body.map_err(Error::InvalidRequest)?;
(Some(body),) => (body,),
(body,) => {
let mut missing = Vec::new();
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!("{}/report/output", client.baseurl,); let url = format!("{}/report/output", client.baseurl,);
let request = client.client.post(url).json(&body).build()?; let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await; let result = client.client.execute(request).await;
@ -374,35 +366,31 @@ pub mod builder {
#[derive(Clone)] #[derive(Clone)]
pub struct ReportStart<'a> { pub struct ReportStart<'a> {
client: &'a super::Client, client: &'a super::Client,
body: Option<types::ReportStartBody>, body: Result<types::ReportStartBody, String>,
} }
impl<'a> ReportStart<'a> { impl<'a> ReportStart<'a> {
pub fn new(client: &'a super::Client) -> Self { pub fn new(client: &'a super::Client) -> Self {
Self { client, body: None } Self {
client,
body: Err("body was not initialized".to_string()),
}
} }
pub fn body(mut self, value: types::ReportStartBody) -> Self { pub fn body<V>(mut self, value: V) -> Self
self.body = Some(value); where
V: TryInto<types::ReportStartBody>,
{
self.body = value
.try_into()
.map_err(|_| "conversion to `ReportStartBody` for body failed".to_string());
self self
} }
///Sends a `POST` request to `/report/start` ///Sends a `POST` request to `/report/start`
pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> { pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> {
let Self { client, body } = self; let Self { client, body } = self;
let (body,) = match (body,) { let body = body.map_err(Error::InvalidRequest)?;
(Some(body),) => (body,),
(body,) => {
let mut missing = Vec::new();
if body.is_none() {
missing.push(stringify!(body));
}
return Err(super::Error::InvalidRequest(format!(
"the following parameters are required: {}",
missing.join(", "),
)));
}
};
let url = format!("{}/report/start", client.baseurl,); let url = format!("{}/report/start", client.baseurl,);
let request = client.client.post(url).json(&body).build()?; let request = client.client.post(url).json(&body).build()?;
let result = client.client.execute(request).await; let result = client.client.execute(request).await;

View File

@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
pub use progenitor_client::{ByteStream, Error, ResponseValue}; pub use progenitor_client::{ByteStream, Error, ResponseValue};
pub mod types { pub mod types {
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[allow(unused_imports)]
use std::convert::TryFrom;
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct EnrolBody { pub struct EnrolBody {
pub host: String, pub host: String,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
pub use progenitor_client::{ByteStream, Error, ResponseValue}; pub use progenitor_client::{ByteStream, Error, ResponseValue};
pub mod types { pub mod types {
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[allow(unused_imports)]
use std::convert::TryFrom;
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BlockSize(i64); pub struct BlockSize(i64);
impl std::ops::Deref for BlockSize { impl std::ops::Deref for BlockSize {

View File

@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
pub use progenitor_client::{ByteStream, Error, ResponseValue}; pub use progenitor_client::{ByteStream, Error, ResponseValue};
pub mod types { pub mod types {
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[allow(unused_imports)]
use std::convert::TryFrom;
mod defaults { mod defaults {
pub(super) fn default_u64<T, const V: u64>() -> T pub(super) fn default_u64<T, const V: u64>() -> T
where where

View File

@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
pub use progenitor_client::{ByteStream, Error, ResponseValue}; pub use progenitor_client::{ByteStream, Error, ResponseValue};
pub mod types { pub mod types {
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[allow(unused_imports)]
use std::convert::TryFrom;
///Error information from a response. ///Error information from a response.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Error { pub struct Error {

View File

@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
pub use progenitor_client::{ByteStream, Error, ResponseValue}; pub use progenitor_client::{ByteStream, Error, ResponseValue};
pub mod types { pub mod types {
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[allow(unused_imports)]
use std::convert::TryFrom;
///Error information from a response. ///Error information from a response.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Error { pub struct Error {

View File

@ -34,15 +34,15 @@ mod builder_untagged {
); );
} }
use nexus_client::{types, Client}; use nexus_client::Client;
pub fn _ignore() { pub fn _ignore() {
let client = Client::new(""); let client = Client::new("");
let stream = client let stream = client
.instance_disk_list() .instance_disk_list()
.organization_name(types::Name::try_from("org").unwrap()) .organization_name("org")
.project_name(types::Name::try_from("project").unwrap()) .project_name("project")
.instance_name(types::Name::try_from("instance").unwrap()) .instance_name("instance")
.stream(); .stream();
let _ = stream.collect::<Vec<_>>(); let _ = stream.collect::<Vec<_>>();
} }
@ -59,15 +59,15 @@ mod builder_tagged {
); );
} }
use nexus_client::{types, Client, ClientInstancesExt}; use nexus_client::{Client, ClientInstancesExt};
fn _ignore() { fn _ignore() {
let client = Client::new(""); let client = Client::new("");
let stream = client let stream = client
.instance_disk_list() .instance_disk_list()
.organization_name(types::Name::try_from("org").unwrap()) .organization_name("org")
.project_name(types::Name::try_from("project").unwrap()) .project_name("project")
.instance_name(types::Name::try_from("instance").unwrap()) .instance_name("instance")
.stream(); .stream();
let _ = stream.collect::<Vec<_>>(); let _ = stream.collect::<Vec<_>>();
} }

View File

@ -7830,7 +7830,8 @@
"user_data": { "user_data": {
"description": "User data for instance initialization systems (such as cloud-init). Must be a Base64-encoded string, as specified in RFC 4648 § 4 (+ and / characters with padding). Maximum 32 KiB unencoded data.", "description": "User data for instance initialization systems (such as cloud-init). Must be a Base64-encoded string, as specified in RFC 4648 § 4 (+ and / characters with padding). Maximum 32 KiB unencoded data.",
"default": "", "default": "",
"type": "string" "type": "string",
"format": "byte"
} }
}, },
"required": [ "required": [