diff --git a/progenitor-impl/src/method.rs b/progenitor-impl/src/method.rs index 8bf1d0fe..a9dcc937 100644 --- a/progenitor-impl/src/method.rs +++ b/progenitor-impl/src/method.rs @@ -555,6 +555,9 @@ impl Generator { ) -> Result { 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 @@ -562,12 +565,15 @@ impl Generator { .map(|param| { let name = format_ident!("{}", param.name); let typ = match (¶m.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) @@ -577,6 +583,7 @@ impl Generator { } (OperationParameterType::RawBody, false) => match ¶m.kind { OperationParameterKind::Body(BodyContentType::OctetStream) => { + needs_body = true; quote! { B } } OperationParameterKind::Body(BodyContentType::Text(_)) => { @@ -592,16 +599,17 @@ impl Generator { }) .collect::>(); - 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 }), + ] + .into_iter() + .flatten() + .collect::>(); + let bounds = (!bounds.is_empty()).then(|| { + quote! { < #(#bounds),* > } }); - - let bounds = if raw_body_param { - quote! { <'a, B: Into > } - } else { - quote! { <'a> } - }; + let self_bounds = needs_lifetime.then(|| quote! { 'a }); let doc_comment = make_doc_comment(method); @@ -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>, @@ -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 for &Client {} #[allow(clippy::all)] impl Client { ///Sends a `POST` request to `/v1/control/hold` - pub async fn control_hold<'a>(&'a self) -> Result, Error<()>> { + pub async fn control_hold(&self) -> Result, Error<()>> { let url = format!("{}/v1/control/hold", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); header_map.append( @@ -1054,7 +1054,7 @@ impl Client { } ///Sends a `POST` request to `/v1/control/resume` - pub async fn control_resume<'a>(&'a self) -> Result, Error<()>> { + pub async fn control_resume(&self) -> Result, Error<()>> { let url = format!("{}/v1/control/resume", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); header_map.append( @@ -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>, Error<()>> { let url = format!("{}/v1/tasks", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); @@ -1328,7 +1328,7 @@ impl Client { } ///Sends a `GET` request to `/v1/whoami` - pub async fn whoami<'a>(&'a self) -> Result, Error<()>> { + pub async fn whoami(&self) -> Result, Error<()>> { let url = format!("{}/v1/whoami", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); header_map.append( @@ -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, Error<()>> { + pub async fn whoami_put_name(&self, body: String) -> Result, Error<()>> { let url = format!("{}/v1/whoami/name", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); header_map.append( @@ -1429,9 +1426,7 @@ impl Client { } ///Sends a `GET` request to `/v1/worker/ping` - pub async fn worker_ping<'a>( - &'a self, - ) -> Result, Error<()>> { + pub async fn worker_ping(&self) -> Result, Error<()>> { let url = format!("{}/v1/worker/ping", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); header_map.append( @@ -1614,9 +1609,7 @@ impl Client { } ///Sends a `GET` request to `/v1/workers` - pub async fn workers_list<'a>( - &'a self, - ) -> Result, Error<()>> { + pub async fn workers_list(&self) -> Result, Error<()>> { let url = format!("{}/v1/workers", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); header_map.append( @@ -1647,7 +1640,7 @@ impl Client { } ///Sends a `POST` request to `/v1/workers/recycle` - pub async fn workers_recycle<'a>(&'a self) -> Result, Error<()>> { + pub async fn workers_recycle(&self) -> Result, Error<()>> { let url = format!("{}/v1/workers/recycle", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); header_map.append( diff --git a/progenitor-impl/tests/output/src/nexus_positional.rs b/progenitor-impl/tests/output/src/nexus_positional.rs index 829ee854..35973da2 100644 --- a/progenitor-impl/tests/output/src/nexus_positional.rs +++ b/progenitor-impl/tests/output/src/nexus_positional.rs @@ -15015,7 +15015,7 @@ impl Client { } ///Sends a `POST` request to `/logout` - pub async fn logout<'a>(&'a self) -> Result, Error> { + pub async fn logout(&self) -> Result, Error> { let url = format!("{}/logout", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); header_map.append( @@ -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, Error> { let url = format!("{}/policy", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); @@ -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, Error> { + pub async fn session_me(&self) -> Result, Error> { let url = format!("{}/session/me", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); header_map.append( @@ -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, Error> { let url = format!("{}/system/ip-pools-service", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); @@ -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, Error> { let url = format!("{}/system/policy", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); @@ -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, Error> { + pub async fn system_update_refresh(&self) -> Result, Error> { let url = format!("{}/v1/system/update/refresh", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); header_map.append( @@ -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, Error> { + pub async fn system_update_stop(&self) -> Result, Error> { let url = format!("{}/v1/system/update/stop", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); header_map.append( @@ -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, Error> { let url = format!("{}/v1/system/update/version", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); diff --git a/progenitor-impl/tests/output/src/nexus_with_timeout.rs b/progenitor-impl/tests/output/src/nexus_with_timeout.rs index 0bea2f16..de7f31a4 100644 --- a/progenitor-impl/tests/output/src/nexus_with_timeout.rs +++ b/progenitor-impl/tests/output/src/nexus_with_timeout.rs @@ -15015,7 +15015,7 @@ impl Client { } ///Sends a `POST` request to `/logout` - pub async fn logout<'a>(&'a self) -> Result, Error> { + pub async fn logout(&self) -> Result, Error> { let url = format!("{}/logout", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); header_map.append( @@ -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, Error> { let url = format!("{}/policy", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); @@ -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, Error> { + pub async fn session_me(&self) -> Result, Error> { let url = format!("{}/session/me", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); header_map.append( @@ -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, Error> { let url = format!("{}/system/ip-pools-service", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); @@ -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, Error> { let url = format!("{}/system/policy", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); @@ -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, Error> { + pub async fn system_update_refresh(&self) -> Result, Error> { let url = format!("{}/v1/system/update/refresh", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); header_map.append( @@ -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, Error> { + pub async fn system_update_stop(&self) -> Result, Error> { let url = format!("{}/v1/system/update/stop", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); header_map.append( @@ -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, Error> { let url = format!("{}/v1/system/update/version", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); diff --git a/progenitor-impl/tests/output/src/propolis_server_positional.rs b/progenitor-impl/tests/output/src/propolis_server_positional.rs index 2836091c..a6fc7ab9 100644 --- a/progenitor-impl/tests/output/src/propolis_server_positional.rs +++ b/progenitor-impl/tests/output/src/propolis_server_positional.rs @@ -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, Error> { let url = format!("{}/instance", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); @@ -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, Error> { let url = format!("{}/instance/serial", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); diff --git a/progenitor-impl/tests/output/src/test_freeform_response.rs b/progenitor-impl/tests/output/src/test_freeform_response.rs index 3fac53b2..65cfd07d 100644 --- a/progenitor-impl/tests/output/src/test_freeform_response.rs +++ b/progenitor-impl/tests/output/src/test_freeform_response.rs @@ -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, Error> { + pub async fn freeform_response(&self) -> Result, Error> { let url = format!("{}/", self.baseurl,); let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize); header_map.append(