Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions progenitor-impl/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,19 +555,25 @@ impl Generator {
) -> Result<TokenStream> {
let operation_id = format_ident!("{}", method.operation_id);

let mut needs_lifetime = false;
let mut needs_body = false;

// Render each parameter as it will appear in the method signature.
let params = method
.params
.iter()
.map(|param| {
let name = format_ident!("{}", param.name);
let typ = match (&param.typ, param.kind.is_optional()) {
(OperationParameterType::Type(type_id), false) => self
.type_space
.get_type(type_id)
.unwrap()
.parameter_ident_with_lifetime("a"),
(OperationParameterType::Type(type_id), false) => {
needs_lifetime = true;
self.type_space
.get_type(type_id)
.unwrap()
.parameter_ident_with_lifetime("a")
}
(OperationParameterType::Type(type_id), true) => {
needs_lifetime = true;
let t = self
.type_space
.get_type(type_id)
Expand All @@ -577,6 +583,7 @@ impl Generator {
}
(OperationParameterType::RawBody, false) => match &param.kind {
OperationParameterKind::Body(BodyContentType::OctetStream) => {
needs_body = true;
quote! { B }
}
OperationParameterKind::Body(BodyContentType::Text(_)) => {
Expand All @@ -592,16 +599,17 @@ impl Generator {
})
.collect::<Vec<_>>();

let raw_body_param = method.params.iter().any(|param| {
param.typ == OperationParameterType::RawBody
&& param.kind == OperationParameterKind::Body(BodyContentType::OctetStream)
let bounds = [
needs_lifetime.then(|| quote! { 'a }),
needs_body.then(|| quote! { B: Into<reqwest::Body> }),
]
.into_iter()
.flatten()
.collect::<Vec<_>>();
let bounds = (!bounds.is_empty()).then(|| {
quote! { < #(#bounds),* > }
});

let bounds = if raw_body_param {
quote! { <'a, B: Into<reqwest::Body> > }
} else {
quote! { <'a> }
};
let self_bounds = needs_lifetime.then(|| quote! { 'a });

let doc_comment = make_doc_comment(method);

Expand All @@ -614,7 +622,7 @@ impl Generator {
let method_impl = quote! {
#[doc = #doc_comment]
pub async fn #operation_id #bounds (
&'a self,
& #self_bounds self,
#(#params),*
) -> Result<
ResponseValue<#success_type>,
Expand Down Expand Up @@ -690,7 +698,7 @@ impl Generator {
quote! {
#[doc = #doc_comment]
pub fn #stream_id #bounds (
&'a self,
& #self_bounds self,
#(#stream_params),*
) -> impl futures::Stream<Item = Result<
#item_type,
Expand Down
25 changes: 9 additions & 16 deletions progenitor-impl/tests/output/src/buildomat_positional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ impl ClientHooks<()> for &Client {}
#[allow(clippy::all)]
impl Client {
///Sends a `POST` request to `/v1/control/hold`
pub async fn control_hold<'a>(&'a self) -> Result<ResponseValue<()>, Error<()>> {
pub async fn control_hold(&self) -> Result<ResponseValue<()>, Error<()>> {
let url = format!("{}/v1/control/hold", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
Expand Down Expand Up @@ -1054,7 +1054,7 @@ impl Client {
}

///Sends a `POST` request to `/v1/control/resume`
pub async fn control_resume<'a>(&'a self) -> Result<ResponseValue<()>, Error<()>> {
pub async fn control_resume(&self) -> Result<ResponseValue<()>, Error<()>> {
let url = format!("{}/v1/control/resume", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
Expand Down Expand Up @@ -1115,8 +1115,8 @@ impl Client {
}

///Sends a `GET` request to `/v1/tasks`
pub async fn tasks_get<'a>(
&'a self,
pub async fn tasks_get(
&self,
) -> Result<ResponseValue<::std::vec::Vec<types::Task>>, Error<()>> {
let url = format!("{}/v1/tasks", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
Expand Down Expand Up @@ -1328,7 +1328,7 @@ impl Client {
}

///Sends a `GET` request to `/v1/whoami`
pub async fn whoami<'a>(&'a self) -> Result<ResponseValue<types::WhoamiResult>, Error<()>> {
pub async fn whoami(&self) -> Result<ResponseValue<types::WhoamiResult>, Error<()>> {
let url = format!("{}/v1/whoami", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
Expand Down Expand Up @@ -1359,10 +1359,7 @@ impl Client {
}

///Sends a `PUT` request to `/v1/whoami/name`
pub async fn whoami_put_name<'a>(
&'a self,
body: String,
) -> Result<ResponseValue<()>, Error<()>> {
pub async fn whoami_put_name(&self, body: String) -> Result<ResponseValue<()>, Error<()>> {
let url = format!("{}/v1/whoami/name", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
Expand Down Expand Up @@ -1429,9 +1426,7 @@ impl Client {
}

///Sends a `GET` request to `/v1/worker/ping`
pub async fn worker_ping<'a>(
&'a self,
) -> Result<ResponseValue<types::WorkerPingResult>, Error<()>> {
pub async fn worker_ping(&self) -> Result<ResponseValue<types::WorkerPingResult>, Error<()>> {
let url = format!("{}/v1/worker/ping", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
Expand Down Expand Up @@ -1614,9 +1609,7 @@ impl Client {
}

///Sends a `GET` request to `/v1/workers`
pub async fn workers_list<'a>(
&'a self,
) -> Result<ResponseValue<types::WorkersResult>, Error<()>> {
pub async fn workers_list(&self) -> Result<ResponseValue<types::WorkersResult>, Error<()>> {
let url = format!("{}/v1/workers", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
Expand Down Expand Up @@ -1647,7 +1640,7 @@ impl Client {
}

///Sends a `POST` request to `/v1/workers/recycle`
pub async fn workers_recycle<'a>(&'a self) -> Result<ResponseValue<()>, Error<()>> {
pub async fn workers_recycle(&self) -> Result<ResponseValue<()>, Error<()>> {
let url = format!("{}/v1/workers/recycle", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
Expand Down
30 changes: 12 additions & 18 deletions progenitor-impl/tests/output/src/nexus_positional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15015,7 +15015,7 @@ impl Client {
}

///Sends a `POST` request to `/logout`
pub async fn logout<'a>(&'a self) -> Result<ResponseValue<()>, Error<types::Error>> {
pub async fn logout(&self) -> Result<ResponseValue<()>, Error<types::Error>> {
let url = format!("{}/logout", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
Expand Down Expand Up @@ -19830,8 +19830,8 @@ impl Client {
///Fetch the current silo's IAM policy
///
///Sends a `GET` request to `/policy`
pub async fn policy_view<'a>(
&'a self,
pub async fn policy_view(
&self,
) -> Result<ResponseValue<types::SiloRolePolicy>, Error<types::Error>> {
let url = format!("{}/policy", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
Expand Down Expand Up @@ -20053,9 +20053,7 @@ impl Client {
///Fetch the user associated with the current session
///
///Sends a `GET` request to `/session/me`
pub async fn session_me<'a>(
&'a self,
) -> Result<ResponseValue<types::User>, Error<types::Error>> {
pub async fn session_me(&self) -> Result<ResponseValue<types::User>, Error<types::Error>> {
let url = format!("{}/session/me", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
Expand Down Expand Up @@ -22029,8 +22027,8 @@ impl Client {
///Fetch the IP pool used for Oxide services
///
///Sends a `GET` request to `/system/ip-pools-service`
pub async fn ip_pool_service_view<'a>(
&'a self,
pub async fn ip_pool_service_view(
&self,
) -> Result<ResponseValue<types::IpPool>, Error<types::Error>> {
let url = format!("{}/system/ip-pools-service", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
Expand Down Expand Up @@ -22322,8 +22320,8 @@ impl Client {
///Fetch the top-level IAM policy
///
///Sends a `GET` request to `/system/policy`
pub async fn system_policy_view<'a>(
&'a self,
pub async fn system_policy_view(
&self,
) -> Result<ResponseValue<types::FleetRolePolicy>, Error<types::Error>> {
let url = format!("{}/system/policy", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
Expand Down Expand Up @@ -25892,9 +25890,7 @@ impl Client {
///Refresh update data
///
///Sends a `POST` request to `/v1/system/update/refresh`
pub async fn system_update_refresh<'a>(
&'a self,
) -> Result<ResponseValue<()>, Error<types::Error>> {
pub async fn system_update_refresh(&self) -> Result<ResponseValue<()>, Error<types::Error>> {
let url = format!("{}/v1/system/update/refresh", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
Expand Down Expand Up @@ -25978,9 +25974,7 @@ impl Client {
///If there is no update in progress, do nothing.
///
///Sends a `POST` request to `/v1/system/update/stop`
pub async fn system_update_stop<'a>(
&'a self,
) -> Result<ResponseValue<()>, Error<types::Error>> {
pub async fn system_update_stop(&self) -> Result<ResponseValue<()>, Error<types::Error>> {
let url = format!("{}/v1/system/update/stop", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
Expand Down Expand Up @@ -26208,8 +26202,8 @@ impl Client {
///View system version and update status
///
///Sends a `GET` request to `/v1/system/update/version`
pub async fn system_version<'a>(
&'a self,
pub async fn system_version(
&self,
) -> Result<ResponseValue<types::SystemVersion>, Error<types::Error>> {
let url = format!("{}/v1/system/update/version", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
Expand Down
30 changes: 12 additions & 18 deletions progenitor-impl/tests/output/src/nexus_with_timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15015,7 +15015,7 @@ impl Client {
}

///Sends a `POST` request to `/logout`
pub async fn logout<'a>(&'a self) -> Result<ResponseValue<()>, Error<types::Error>> {
pub async fn logout(&self) -> Result<ResponseValue<()>, Error<types::Error>> {
let url = format!("{}/logout", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
Expand Down Expand Up @@ -19830,8 +19830,8 @@ impl Client {
///Fetch the current silo's IAM policy
///
///Sends a `GET` request to `/policy`
pub async fn policy_view<'a>(
&'a self,
pub async fn policy_view(
&self,
) -> Result<ResponseValue<types::SiloRolePolicy>, Error<types::Error>> {
let url = format!("{}/policy", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
Expand Down Expand Up @@ -20053,9 +20053,7 @@ impl Client {
///Fetch the user associated with the current session
///
///Sends a `GET` request to `/session/me`
pub async fn session_me<'a>(
&'a self,
) -> Result<ResponseValue<types::User>, Error<types::Error>> {
pub async fn session_me(&self) -> Result<ResponseValue<types::User>, Error<types::Error>> {
let url = format!("{}/session/me", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
Expand Down Expand Up @@ -22029,8 +22027,8 @@ impl Client {
///Fetch the IP pool used for Oxide services
///
///Sends a `GET` request to `/system/ip-pools-service`
pub async fn ip_pool_service_view<'a>(
&'a self,
pub async fn ip_pool_service_view(
&self,
) -> Result<ResponseValue<types::IpPool>, Error<types::Error>> {
let url = format!("{}/system/ip-pools-service", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
Expand Down Expand Up @@ -22322,8 +22320,8 @@ impl Client {
///Fetch the top-level IAM policy
///
///Sends a `GET` request to `/system/policy`
pub async fn system_policy_view<'a>(
&'a self,
pub async fn system_policy_view(
&self,
) -> Result<ResponseValue<types::FleetRolePolicy>, Error<types::Error>> {
let url = format!("{}/system/policy", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
Expand Down Expand Up @@ -25892,9 +25890,7 @@ impl Client {
///Refresh update data
///
///Sends a `POST` request to `/v1/system/update/refresh`
pub async fn system_update_refresh<'a>(
&'a self,
) -> Result<ResponseValue<()>, Error<types::Error>> {
pub async fn system_update_refresh(&self) -> Result<ResponseValue<()>, Error<types::Error>> {
let url = format!("{}/v1/system/update/refresh", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
Expand Down Expand Up @@ -25978,9 +25974,7 @@ impl Client {
///If there is no update in progress, do nothing.
///
///Sends a `POST` request to `/v1/system/update/stop`
pub async fn system_update_stop<'a>(
&'a self,
) -> Result<ResponseValue<()>, Error<types::Error>> {
pub async fn system_update_stop(&self) -> Result<ResponseValue<()>, Error<types::Error>> {
let url = format!("{}/v1/system/update/stop", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
Expand Down Expand Up @@ -26208,8 +26202,8 @@ impl Client {
///View system version and update status
///
///Sends a `GET` request to `/v1/system/update/version`
pub async fn system_version<'a>(
&'a self,
pub async fn system_version(
&self,
) -> Result<ResponseValue<types::SystemVersion>, Error<types::Error>> {
let url = format!("{}/v1/system/update/version", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1562,8 +1562,8 @@ impl ClientHooks<()> for &Client {}
#[allow(clippy::all)]
impl Client {
///Sends a `GET` request to `/instance`
pub async fn instance_get<'a>(
&'a self,
pub async fn instance_get(
&self,
) -> Result<ResponseValue<types::InstanceGetResponse>, Error<types::Error>> {
let url = format!("{}/instance", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
Expand Down Expand Up @@ -1731,8 +1731,8 @@ impl Client {
}

///Sends a `GET` request to `/instance/serial`
pub async fn instance_serial<'a>(
&'a self,
pub async fn instance_serial(
&self,
) -> Result<ResponseValue<reqwest::Upgraded>, Error<reqwest::Upgraded>> {
let url = format!("{}/instance/serial", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
Expand Down
4 changes: 1 addition & 3 deletions progenitor-impl/tests/output/src/test_freeform_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ impl ClientHooks<()> for &Client {}
#[allow(clippy::all)]
impl Client {
///Sends a `GET` request to `/`
pub async fn freeform_response<'a>(
&'a self,
) -> Result<ResponseValue<ByteStream>, Error<ByteStream>> {
pub async fn freeform_response(&self) -> Result<ResponseValue<ByteStream>, Error<ByteStream>> {
let url = format!("{}/", self.baseurl,);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
Expand Down