33
44use async_trait::async_trait;
55use futures::Stream;
6+ #[cfg(feature = "mock")]
7+ use mockall::automock;
68use std::error::Error;
79use std::collections::BTreeSet;
810use std::task::{ Poll, Context} ;
@@ -33,6 +35,7 @@ pub use auth::{AuthenticationApi, Claims};
3335 { { /apis} }
3436{ { /apiInfo} }
3537/// API
38+ #[cfg_attr(feature = "mock", automock)]
3639#[async_trait]
3740#[allow(clippy::too_many_arguments, clippy::ptr_arg)]
3841pub trait Api<C: Send + Sync> {
@@ -43,10 +46,10 @@ pub trait Api<C: Send + Sync> {
4346{ { #summary} }
4447 /// { { { .} } }
4548{ { /summary} }
46- async fn { { #exts} } { { { x-operation-id} } } { { /exts} } (
49+ async fn { { #exts} } { { { x-operation-id} } } { { /exts} } { { #exts.x-has-borrowed-params } } < ' a> { { /exts.x-has-borrowed-params } } (
4750 &self,
4851{ { #allParams} }
49- { { { paramName} } } : { { ^required} } Option< { { /required} } { { #isArray} } &{ { /isArray} } { { { dataType} } } { { ^required} } > { { /required} } ,
52+ { { { paramName} } } : { { ^required} } Option<{ { /required} } { { #isArray} } &{ { #exts.x-param-needs-lifetime } } ' a { { /exts.x-param-needs-lifetime } } { { /isArray} } { { { dataType} } } { { ^required} } > { { /required} } ,
5053{ { /allParams} }
5154 context: &C) -> Result< { { { operationId} } } Response, ApiError> ;
5255
@@ -57,9 +60,14 @@ pub trait Api<C: Send + Sync> {
5760}
5861
5962/// API where `Context` isn' t passed on every API call
63+ #[cfg_attr(feature = " mock" , automock)]
6064#[async_trait]
6165#[allow(clippy::too_many_arguments, clippy::ptr_arg)]
6266pub trait ApiNoContext <C: Send + Sync > {
67+ // The std::task::Context struct houses a reference to std::task::Waker with the lifetime < ' a>.
68+ // Adding an anonymous lifetime `' a` to allow mockall to create a mock object with the right lifetimes.
69+ // This is needed because the compiler is unable to determine the lifetimes on F' s trait bound
70+ // where F is the closure created by mockall. We use higher-rank trait bounds here to get around this.
6371
6472 fn context(&self) -> &C;
6573
@@ -70,10 +78,10 @@ pub trait ApiNoContext<C: Send + Sync> {
7078{{#summary}}
7179 /// {{{.}}}
7280{{/summary}}
73- async fn { {#exts} }{ {{x-operation-id} }}{ {/exts} }(
81+ async fn {{#exts}}{{{x-operation-id}}}{{/exts}}{{#exts.x-has-borrowed-params}}< ' a > {{/exts.x-has-borrowed-params } } (
7482 &self,
7583{ {#allParams} }
76- { {{paramName} }}: { {^required} }Option<{ {/required} }{ {#isArray} }& { {/isArray} }{ {{dataType} }}{ {^required} }>{ {/required} },
84+ { {{paramName} }}: { {^required} }Option<{ {/required} }{ {#isArray} }& { {/isArray} }{ {#exts.x-param-needs-lifetime } }'a { {/exts.x-param-needs-lifetime } } { { {dataType} }}{ {^required} }>{ {/required} },
7785{ {/allParams} }
7886 ) -> Result<{ {{operationId} }}Response, ApiError>;
7987
@@ -109,10 +117,10 @@ impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ApiNoContext<C> for Contex
109117{ {#summary} }
110118 /// { {{.} }}
111119{ {/summary} }
112- async fn { {#exts} }{ {{x-operation-id} }}{ {/exts} }(
120+ async fn { {#exts} }{ {{x-operation-id} }}{ {/exts} }{ {#exts.x-has-borrowed-params } }<'a> { {/exts.x-has-borrowed-params } } (
113121 &self,
114122{ {#allParams} }
115- { {{paramName} }}: { {^required} }Option<{ {/required} }{ {#isArray} }& { {/isArray} }{ {{dataType} }}{ {^required} }>{ {/required} },
123+ { {{paramName} }}: { {^required} }Option<{ {/required} }{ {#isArray} }& { {/isArray} }{ {#exts.x-param-needs-lifetime } }'a { {/exts.x-param-needs-lifetime } } { { {dataType} }}{ {^required} }>{ {/required} },
116124{ {/allParams} }
117125 ) -> Result<{ {{operationId} }}Response, ApiError>
118126 {
@@ -146,6 +154,7 @@ impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ApiNoContext<C> for Contex
146154{ {/apiInfo} }
147155
148156/// Callback API
157+ #[cfg_attr(feature = "mock", automock)]
149158#[async_trait]
150159pub trait CallbackApi<C: Send + Sync > {
151160
@@ -159,15 +168,15 @@ pub trait CallbackApi<C: Send + Sync> {
159168{ {#summary} }
160169 /// { {{.} }}
161170{ {/summary} }
162- async fn { {#exts} }{ {{x-operation-id} }}{ {/exts} }(
171+ async fn { {#exts} }{ {{x-operation-id} }}{ {/exts} }{ {#exts.x-has-borrowed-params } }<'a> { {/exts.x-has-borrowed-params } } (
163172 &self,
164173{ {#exts} }
165174 { {#x-callback-params} }
166175 callback_{ {.} }: String,
167176 { {/x-callback-params} }
168177{ {/exts} }
169178{ {#allParams} }
170- { {{paramName} }}: { {^required} }Option<{ {/required} }{ {#isArray} }& { {/isArray} }{ {{dataType} }}{ {^required} }>{ {/required} },
179+ { {{paramName} }}: { {^required} }Option<{ {/required} }{ {#isArray} }& { {/isArray} }{ {#exts.x-param-needs-lifetime } }'a { {/exts.x-param-needs-lifetime } } { { {dataType} }}{ {^required} }>{ {/required} },
171180{ {/allParams} }
172181 context: &C) -> Result<{ {{operationId} }}Response, ApiError>;
173182
@@ -181,6 +190,7 @@ pub trait CallbackApi<C: Send + Sync> {
181190}
182191
183192/// Callback API without a `Context`
193+ #[cfg_attr(feature = "mock", automock)]
184194#[async_trait]
185195pub trait CallbackApiNoContext<C: Send + Sync > {
186196
@@ -196,15 +206,15 @@ pub trait CallbackApiNoContext<C: Send + Sync> {
196206{ {#summary} }
197207 /// { {{.} }}
198208{ {/summary} }
199- async fn { {#exts} }{ {{x-operation-id} }}{ {/exts} }(
209+ async fn { {#exts} }{ {{x-operation-id} }}{ {/exts} }{ {#exts.x-has-borrowed-params } }<'a> { {/exts.x-has-borrowed-params } } (
200210 &self,
201211{ {#exts} }
202212 { {#x-callback-params} }
203213 callback_{ {.} }: String,
204214 { {/x-callback-params} }
205215{ {/exts} }
206216{ {#allParams} }
207- { {{paramName} }}: { {^required} }Option<{ {/required} }{ {#isArray} }& { {/isArray} }{ {{dataType} }}{ {^required} }>{ {/required} },
217+ { {{paramName} }}: { {^required} }Option<{ {/required} }{ {#isArray} }& { {/isArray} }{ {#exts.x-param-needs-lifetime } }'a { {/exts.x-param-needs-lifetime } } { { {dataType} }}{ {^required} }>{ {/required} },
208218{ {/allParams} }
209219 ) -> Result<{ {{operationId} }}Response, ApiError>;
210220
@@ -246,15 +256,15 @@ impl<T: CallbackApi<C> + Send + Sync, C: Clone + Send + Sync> CallbackApiNoConte
246256 { {#summary} }
247257 /// { {{.} }}
248258 { {/summary} }
249- async fn { {#exts} }{ {{x-operation-id} }}{ {/exts} }(
259+ async fn { {#exts} }{ {{x-operation-id} }}{ {/exts} }{ {#exts.x-has-borrowed-params } }<'a> { {/exts.x-has-borrowed-params } } (
250260 &self,
251261{ {#exts} }
252262 { {#x-callback-params} }
253263 callback_{ {.} }: String,
254264 { {/x-callback-params} }
255265{ {/exts} }
256266{ {#allParams} }
257- { {{paramName} }}: { {^required} }Option<{ {/required} }{ {#isArray} }& { {/isArray} }{ {{dataType} }}{ {^required} }>{ {/required} },
267+ { {{paramName} }}: { {^required} }Option<{ {/required} }{ {#isArray} }& { {/isArray} }{ {#exts.x-param-needs-lifetime } }'a { {/exts.x-param-needs-lifetime } } { { {dataType} }}{ {^required} }>{ {/required} },
258268{ {/allParams} }
259269 ) -> Result<{ {{operationId} }}Response, ApiError>
260270 {
0 commit comments