Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,16 @@ private void postProcessOperationWithModels(CodegenOperation op, List<ModelMap>
op.vendorExtensions.put("x-has-request-body", true);
}

if (op.allParams.stream()
.anyMatch(p -> p.isArray && !p.isPrimitiveType)) {
op.vendorExtensions.put("x-has-borrowed-params", Boolean.TRUE);
for (CodegenParameter param : op.allParams) {
if (param.isArray) {
param.vendorExtensions.put("x-param-needs-lifetime", Boolean.TRUE);
}
}
}

// The CLI generates a structopt structure for each operation. This can only have a single
// use of a short option, which comes from the parameter name, so we need to police
// against duplicates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ cli = [
]
conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-enum-derive"]

mock = ["mockall"]

[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
native-tls = { version = "0.2", optional = true }
hyper-tls = { version = "0.6", optional = true }
Expand All @@ -87,6 +89,7 @@ swagger = { version = "7.0.0-rc2", features = ["serdejson", "server", "client",
headers = "0.4.0"
log = "0.4.27"
mime = "0.3"
mockall = { version = "0.13.1", optional = true }

serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#[allow(clippy::vec_init_then_push)]
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}{{#exts.x-has-borrowed-params}}<'a>{{/exts.x-has-borrowed-params}}(
&self,
{{#exts}}
{{#x-callback-params}}
callback_{{.}}: String,
{{/x-callback-params}}
{{/exts}}
{{#allParams}}
param_{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
param_{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{#exts.x-param-needs-lifetime}}'a {{/exts.x-param-needs-lifetime}}{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
{{/allParams}}
context: &C) -> Result<{{{operationId}}}Response, ApiError>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{{#summary}}
/// {{{.}}}
{{/summary}}
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}{{#exts.x-has-borrowed-params}}<'a>{{/exts.x-has-borrowed-params}}(
&self,
{{#exts}}
{{#x-callback-params}}
callback_{{.}}: String,
{{/x-callback-params}}
{{/exts}}
{{#allParams}}
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{#exts.x-param-needs-lifetime}}'a {{/exts.x-param-needs-lifetime}}{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
{{/allParams}}
context: &C) -> Result<{{{operationId}}}Response, ApiError>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use async_trait::async_trait;
use futures::Stream;
#[cfg(feature = "mock")]
use mockall::automock;
use std::error::Error;
use std::collections::BTreeSet;
use std::task::{Poll, Context};
Expand Down Expand Up @@ -33,6 +35,7 @@ pub use auth::{AuthenticationApi, Claims};
{{/apis}}
{{/apiInfo}}
/// API
#[cfg_attr(feature = "mock", automock)]
#[async_trait]
#[allow(clippy::too_many_arguments, clippy::ptr_arg)]
pub trait Api<C: Send + Sync> {
Expand All @@ -43,10 +46,10 @@ pub trait Api<C: Send + Sync> {
{{#summary}}
/// {{{.}}}
{{/summary}}
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}{{#exts.x-has-borrowed-params}}<'a>{{/exts.x-has-borrowed-params}}(
&self,
{{#allParams}}
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{#exts.x-param-needs-lifetime}}'a {{/exts.x-param-needs-lifetime}}{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
{{/allParams}}
context: &C) -> Result<{{{operationId}}}Response, ApiError>;

Expand All @@ -57,9 +60,14 @@ pub trait Api<C: Send + Sync> {
}

/// API where `Context` isn't passed on every API call
#[cfg_attr(feature = "mock", automock)]
#[async_trait]
#[allow(clippy::too_many_arguments, clippy::ptr_arg)]
pub trait ApiNoContext<C: Send + Sync> {
// The std::task::Context struct houses a reference to std::task::Waker with the lifetime <'a>.
// Adding an anonymous lifetime `'a` to allow mockall to create a mock object with the right lifetimes.
// This is needed because the compiler is unable to determine the lifetimes on F's trait bound
// where F is the closure created by mockall. We use higher-rank trait bounds here to get around this.

fn context(&self) -> &C;

Expand All @@ -70,10 +78,10 @@ pub trait ApiNoContext<C: Send + Sync> {
{{#summary}}
/// {{{.}}}
{{/summary}}
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}{{#exts.x-has-borrowed-params}}<'a>{{/exts.x-has-borrowed-params}}(
&self,
{{#allParams}}
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{#exts.x-param-needs-lifetime}}'a {{/exts.x-param-needs-lifetime}}{{{dataType}}}{{^required}}>{{/required}},
{{/allParams}}
) -> Result<{{{operationId}}}Response, ApiError>;

Expand Down Expand Up @@ -109,10 +117,10 @@ impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ApiNoContext<C> for Contex
{{#summary}}
/// {{{.}}}
{{/summary}}
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}{{#exts.x-has-borrowed-params}}<'a>{{/exts.x-has-borrowed-params}}(
&self,
{{#allParams}}
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{#exts.x-param-needs-lifetime}}'a {{/exts.x-param-needs-lifetime}}{{{dataType}}}{{^required}}>{{/required}},
{{/allParams}}
) -> Result<{{{operationId}}}Response, ApiError>
{
Expand Down Expand Up @@ -146,6 +154,7 @@ impl<T: Api<C> + Send + Sync, C: Clone + Send + Sync> ApiNoContext<C> for Contex
{{/apiInfo}}

/// Callback API
#[cfg_attr(feature = "mock", automock)]
#[async_trait]
pub trait CallbackApi<C: Send + Sync> {

Expand All @@ -159,15 +168,15 @@ pub trait CallbackApi<C: Send + Sync> {
{{#summary}}
/// {{{.}}}
{{/summary}}
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}{{#exts.x-has-borrowed-params}}<'a>{{/exts.x-has-borrowed-params}}(
&self,
{{#exts}}
{{#x-callback-params}}
callback_{{.}}: String,
{{/x-callback-params}}
{{/exts}}
{{#allParams}}
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{#exts.x-param-needs-lifetime}}'a {{/exts.x-param-needs-lifetime}}{{{dataType}}}{{^required}}>{{/required}},
{{/allParams}}
context: &C) -> Result<{{{operationId}}}Response, ApiError>;

Expand All @@ -181,6 +190,7 @@ pub trait CallbackApi<C: Send + Sync> {
}

/// Callback API without a `Context`
#[cfg_attr(feature = "mock", automock)]
#[async_trait]
pub trait CallbackApiNoContext<C: Send + Sync> {

Expand All @@ -196,15 +206,15 @@ pub trait CallbackApiNoContext<C: Send + Sync> {
{{#summary}}
/// {{{.}}}
{{/summary}}
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}{{#exts.x-has-borrowed-params}}<'a>{{/exts.x-has-borrowed-params}}(
&self,
{{#exts}}
{{#x-callback-params}}
callback_{{.}}: String,
{{/x-callback-params}}
{{/exts}}
{{#allParams}}
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{#exts.x-param-needs-lifetime}}'a {{/exts.x-param-needs-lifetime}}{{{dataType}}}{{^required}}>{{/required}},
{{/allParams}}
) -> Result<{{{operationId}}}Response, ApiError>;

Expand Down Expand Up @@ -246,15 +256,15 @@ impl<T: CallbackApi<C> + Send + Sync, C: Clone + Send + Sync> CallbackApiNoConte
{{#summary}}
/// {{{.}}}
{{/summary}}
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}(
async fn {{#exts}}{{{x-operation-id}}}{{/exts}}{{#exts.x-has-borrowed-params}}<'a>{{/exts.x-has-borrowed-params}}(
&self,
{{#exts}}
{{#x-callback-params}}
callback_{{.}}: String,
{{/x-callback-params}}
{{/exts}}
{{#allParams}}
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{{dataType}}}{{^required}}>{{/required}},
{{{paramName}}}: {{^required}}Option<{{/required}}{{#isArray}}&{{/isArray}}{{#exts.x-param-needs-lifetime}}'a {{/exts.x-param-needs-lifetime}}{{{dataType}}}{{^required}}>{{/required}},
{{/allParams}}
) -> Result<{{{operationId}}}Response, ApiError>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ cli = [
]
conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-enum-derive"]

mock = ["mockall"]

[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
native-tls = { version = "0.2", optional = true }
hyper-tls = { version = "0.6", optional = true }
Expand All @@ -41,6 +43,7 @@ swagger = { version = "7.0.0-rc2", features = ["serdejson", "server", "client",
headers = "0.4.0"
log = "0.4.27"
mime = "0.3"
mockall = { version = "0.13.1", optional = true }

serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use async_trait::async_trait;
use futures::Stream;
#[cfg(feature = "mock")]
use mockall::automock;
use std::error::Error;
use std::collections::BTreeSet;
use std::task::{Poll, Context};
Expand Down Expand Up @@ -39,6 +41,7 @@ pub enum MultipleIdenticalMimeTypesPostResponse {
}

/// API
#[cfg_attr(feature = "mock", automock)]
#[async_trait]
#[allow(clippy::too_many_arguments, clippy::ptr_arg)]
pub trait Api<C: Send + Sync> {
Expand Down Expand Up @@ -66,9 +69,14 @@ pub trait Api<C: Send + Sync> {
}

/// API where `Context` isn't passed on every API call
#[cfg_attr(feature = "mock", automock)]
#[async_trait]
#[allow(clippy::too_many_arguments, clippy::ptr_arg)]
pub trait ApiNoContext<C: Send + Sync> {
// The std::task::Context struct houses a reference to std::task::Waker with the lifetime <'a>.
// Adding an anonymous lifetime `'a` to allow mockall to create a mock object with the right lifetimes.
// This is needed because the compiler is unable to determine the lifetimes on F's trait bound
// where F is the closure created by mockall. We use higher-rank trait bounds here to get around this.

fn context(&self) -> &C;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ cli = [
]
conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-enum-derive"]

mock = ["mockall"]

[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
native-tls = { version = "0.2", optional = true }
hyper-tls = { version = "0.6", optional = true }
Expand All @@ -37,6 +39,7 @@ swagger = { version = "7.0.0-rc2", features = ["serdejson", "server", "client",
headers = "0.4.0"
log = "0.4.27"
mime = "0.3"
mockall = { version = "0.13.1", optional = true }

serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use async_trait::async_trait;
use futures::Stream;
#[cfg(feature = "mock")]
use mockall::automock;
use std::error::Error;
use std::collections::BTreeSet;
use std::task::{Poll, Context};
Expand All @@ -27,6 +29,7 @@ pub enum OpGetResponse {
}

/// API
#[cfg_attr(feature = "mock", automock)]
#[async_trait]
#[allow(clippy::too_many_arguments, clippy::ptr_arg)]
pub trait Api<C: Send + Sync> {
Expand All @@ -38,9 +41,14 @@ pub trait Api<C: Send + Sync> {
}

/// API where `Context` isn't passed on every API call
#[cfg_attr(feature = "mock", automock)]
#[async_trait]
#[allow(clippy::too_many_arguments, clippy::ptr_arg)]
pub trait ApiNoContext<C: Send + Sync> {
// The std::task::Context struct houses a reference to std::task::Waker with the lifetime <'a>.
// Adding an anonymous lifetime `'a` to allow mockall to create a mock object with the right lifetimes.
// This is needed because the compiler is unable to determine the lifetimes on F's trait bound
// where F is the closure created by mockall. We use higher-rank trait bounds here to get around this.

fn context(&self) -> &C;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ cli = [
]
conversion = ["frunk", "frunk_derives", "frunk_core", "frunk-enum-core", "frunk-enum-derive"]

mock = ["mockall"]

[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))'.dependencies]
native-tls = { version = "0.2", optional = true }
hyper-tls = { version = "0.6", optional = true }
Expand All @@ -40,6 +42,7 @@ swagger = { version = "7.0.0-rc2", features = ["serdejson", "server", "client",
headers = "0.4.0"
log = "0.4.27"
mime = "0.3"
mockall = { version = "0.13.1", optional = true }

serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ use swagger::ApiError;
#[async_trait]
impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
{
async fn any_of_get(
async fn any_of_get<'a>(
&self,
any_of: Option<&Vec<models::AnyOfObject>>,
any_of: Option<&'a Vec<models::AnyOfObject>>,
context: &C) -> Result<AnyOfGetResponse, ApiError>
{
info!("any_of_get({:?}) - X-Span-ID: {:?}", any_of, context.get().0.clone());
Expand All @@ -194,29 +194,29 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
Err(ApiError("Api-Error: Operation is NOT implemented".into()))
}

async fn complex_query_param_get(
async fn complex_query_param_get<'a>(
&self,
list_of_strings: Option<&Vec<models::StringObject>>,
list_of_strings: Option<&'a Vec<models::StringObject>>,
context: &C) -> Result<ComplexQueryParamGetResponse, ApiError>
{
info!("complex_query_param_get({:?}) - X-Span-ID: {:?}", list_of_strings, context.get().0.clone());
Err(ApiError("Api-Error: Operation is NOT implemented".into()))
}

/// Test examples
async fn examples_test(
async fn examples_test<'a>(
&self,
ids: Option<&Vec<String>>,
ids: Option<&'a Vec<String>>,
context: &C) -> Result<ExamplesTestResponse, ApiError>
{
info!("examples_test({:?}) - X-Span-ID: {:?}", ids, context.get().0.clone());
Err(ApiError("Api-Error: Operation is NOT implemented".into()))
}

/// Test a Form Post
async fn form_test(
async fn form_test<'a>(
&self,
required_array: &Vec<String>,
required_array: &'a Vec<String>,
enum_field: models::FormTestRequestEnumField,
context: &C) -> Result<FormTestResponse, ApiError>
{
Expand All @@ -233,9 +233,9 @@ impl<C> Api<C> for Server<C> where C: Has<XSpanIdString> + Send + Sync
Err(ApiError("Api-Error: Operation is NOT implemented".into()))
}

async fn json_complex_query_param_get(
async fn json_complex_query_param_get<'a>(
&self,
list_of_strings: Option<&Vec<models::StringObject>>,
list_of_strings: Option<&'a Vec<models::StringObject>>,
context: &C) -> Result<JsonComplexQueryParamGetResponse, ApiError>
{
info!("json_complex_query_param_get({:?}) - X-Span-ID: {:?}", list_of_strings, context.get().0.clone());
Expand Down
Loading
Loading