From 8f639ee7d0e5133741804b441798cf77a5911302 Mon Sep 17 00:00:00 2001 From: Kalvin Pearce Date: Thu, 9 May 2024 13:26:08 +1000 Subject: [PATCH 1/6] [rust-axum] Feat: split up api trait per tag --- .../languages/RustAxumServerCodegen.java | 12 ++- .../resources/rust-axum/apis-mod.mustache | 6 ++ .../main/resources/rust-axum/apis.mustache | 71 ++++++++++++++++ .../src/main/resources/rust-axum/lib.mustache | 83 +------------------ .../rust-axum/server-imports.mustache | 2 +- .../resources/rust-axum/server-mod.mustache | 3 - .../rust-axum/server-operation.mustache | 4 +- .../resources/rust-axum/server-route.mustache | 2 +- 8 files changed, 92 insertions(+), 91 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/rust-axum/apis-mod.mustache create mode 100644 modules/openapi-generator/src/main/resources/rust-axum/apis.mustache diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java index 7767de8b6234..6409834c1cd3 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java @@ -134,7 +134,7 @@ public RustAxumServerCodegen() { importMapping = new HashMap<>(); modelTemplateFiles.clear(); - apiTemplateFiles.clear(); + apiTemplateFiles.put("apis.mustache", ".rs"); // types defaultIncludes = new HashSet<>( @@ -240,6 +240,7 @@ public RustAxumServerCodegen() { supportingFiles.add(new SupportingFile("types.mustache", "src", "types.rs")); supportingFiles.add(new SupportingFile("header.mustache", "src", "header.rs")); supportingFiles.add(new SupportingFile("server-mod.mustache", "src/server", "mod.rs")); + supportingFiles.add(new SupportingFile("apis-mod.mustache", apiPackage().replace('.', File.separatorChar), "mod.rs")); supportingFiles.add(new SupportingFile("README.mustache", "", "README.md") .doNotOverwrite()); } @@ -320,7 +321,7 @@ private void setPackageVersion(String packageVersion) { @Override public String apiPackage() { - return apiPath; + return "src" + File.separator + "apis"; } @Override @@ -349,6 +350,11 @@ public String toApiName(String name) { sanitizeIdentifier(name, CasingType.SNAKE_CASE, "api", "API", true); } + @Override + public String toApiFilename(String name) { + return toApiName(name); + } + /** * Location to write api files. You can use the apiPackage() as defined when the class is * instantiated @@ -565,6 +571,8 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation @Override public OperationsMap postProcessOperationsWithModels(OperationsMap operationsMap, List allModels) { OperationMap operations = operationsMap.getOperations(); + String classname = operations.getClassname(); + operations.put("classnamePascalCase", camelize(classname)); List operationList = operations.getOperation(); for (CodegenOperation op : operationList) { diff --git a/modules/openapi-generator/src/main/resources/rust-axum/apis-mod.mustache b/modules/openapi-generator/src/main/resources/rust-axum/apis-mod.mustache new file mode 100644 index 000000000000..c8d342c25283 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/rust-axum/apis-mod.mustache @@ -0,0 +1,6 @@ +{{#apiInfo}} +{{#apis}} +pub mod {{classFilename}}; +{{/apis}} +{{/apiInfo}} + diff --git a/modules/openapi-generator/src/main/resources/rust-axum/apis.mustache b/modules/openapi-generator/src/main/resources/rust-axum/apis.mustache new file mode 100644 index 000000000000..5226a6b5c8d2 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/rust-axum/apis.mustache @@ -0,0 +1,71 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types}; + +{{#operations}} +{{#operation}} +{{>response}} +{{/operation}} +{{/operations}} + +{{#operations}} +/// {{classnamePascalCase}} +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait {{classnamePascalCase}} { +{{#operation}} + {{#summary}} + /// {{{.}}}. + /// + {{/summary}} + {{#vendorExtensions}} + /// {{{operationId}}} - {{{httpMethod}}} {{{basePathWithoutHost}}}{{{path}}} + async fn {{{x-operation-id}}}( + &self, + method: Method, + host: Host, + cookies: CookieJar, + {{#headerParams.size}} + header_params: models::{{{operationIdCamelCase}}}HeaderParams, + {{/headerParams.size}} + {{#pathParams.size}} + path_params: models::{{{operationIdCamelCase}}}PathParams, + {{/pathParams.size}} + {{#queryParams.size}} + query_params: models::{{{operationIdCamelCase}}}QueryParams, + {{/queryParams.size}} + {{^x-consumes-multipart-related}} + {{^x-consumes-multipart}} + {{#bodyParam}} + {{#vendorExtensions}} + {{^x-consumes-plain-text}} + body: {{^required}}Option<{{/required}}{{{dataType}}}{{^required}}>{{/required}}, + {{/x-consumes-plain-text}} + {{#x-consumes-plain-text}} + {{#isString}} + body: String, + {{/isString}} + {{^isString}} + body: Bytes, + {{/isString}} + {{/x-consumes-plain-text}} + {{/vendorExtensions}} + {{/bodyParam}} + {{/x-consumes-multipart}} + {{/x-consumes-multipart-related}} + {{#x-consumes-multipart}} + body: Multipart, + {{/x-consumes-multipart}} + {{#x-consumes-multipart-related}} + body: axum::body::Body, + {{/x-consumes-multipart-related}} + ) -> Result<{{{operationId}}}Response, String>; + {{/vendorExtensions}} +{{/operation}} +} +{{/operations}} diff --git a/modules/openapi-generator/src/main/resources/rust-axum/lib.mustache b/modules/openapi-generator/src/main/resources/rust-axum/lib.mustache index b0b755b131f2..7f197ef5f0ff 100644 --- a/modules/openapi-generator/src/main/resources/rust-axum/lib.mustache +++ b/modules/openapi-generator/src/main/resources/rust-axum/lib.mustache @@ -14,98 +14,17 @@ clippy::too_many_arguments )] -use async_trait::async_trait; -use axum::extract::*; -use axum_extra::extract::{CookieJar, Multipart}; -use bytes::Bytes; -use http::Method; -use serde::{Deserialize, Serialize}; - -use types::*; - pub const BASE_PATH: &str = "{{{basePathWithoutHost}}}"; {{#appVersion}} pub const API_VERSION: &str = "{{{.}}}"; {{/appVersion}} -{{#apiInfo}} - {{#apis}} - {{#operations}} - {{#operation}} - {{>response}} - {{/operation}} - {{/operations}} - {{/apis}} -{{/apiInfo}} - -/// API -#[async_trait] -#[allow(clippy::ptr_arg)] -pub trait Api { -{{#apiInfo}} - {{#apis}} - {{#operations}} - {{#operation}} - - {{#summary}} - /// {{{.}}}. - /// - {{/summary}} - {{#vendorExtensions}} - /// {{{operationId}}} - {{{httpMethod}}} {{{basePathWithoutHost}}}{{{path}}} - async fn {{{x-operation-id}}}( - &self, - method: Method, - host: Host, - cookies: CookieJar, - {{#headerParams.size}} - header_params: models::{{{operationIdCamelCase}}}HeaderParams, - {{/headerParams.size}} - {{#pathParams.size}} - path_params: models::{{{operationIdCamelCase}}}PathParams, - {{/pathParams.size}} - {{#queryParams.size}} - query_params: models::{{{operationIdCamelCase}}}QueryParams, - {{/queryParams.size}} - {{^x-consumes-multipart-related}} - {{^x-consumes-multipart}} - {{#bodyParam}} - {{#vendorExtensions}} - {{^x-consumes-plain-text}} - body: {{^required}}Option<{{/required}}{{{dataType}}}{{^required}}>{{/required}}, - {{/x-consumes-plain-text}} - {{#x-consumes-plain-text}} - {{#isString}} - body: String, - {{/isString}} - {{^isString}} - body: Bytes, - {{/isString}} - {{/x-consumes-plain-text}} - {{/vendorExtensions}} - {{/bodyParam}} - {{/x-consumes-multipart}} - {{/x-consumes-multipart-related}} - {{#x-consumes-multipart}} - body: Multipart, - {{/x-consumes-multipart}} - {{#x-consumes-multipart-related}} - body: axum::body::Body, - {{/x-consumes-multipart-related}} - ) -> Result<{{{operationId}}}Response, String>; - {{/vendorExtensions}} - - {{/operation}} - {{/operations}} - {{/apis}} -{{/apiInfo}} -} - #[cfg(feature = "server")] pub mod server; pub mod models; pub mod types; +pub mod apis; #[cfg(feature = "server")] pub(crate) mod header; diff --git a/modules/openapi-generator/src/main/resources/rust-axum/server-imports.mustache b/modules/openapi-generator/src/main/resources/rust-axum/server-imports.mustache index a460237f55d6..28e323564d51 100644 --- a/modules/openapi-generator/src/main/resources/rust-axum/server-imports.mustache +++ b/modules/openapi-generator/src/main/resources/rust-axum/server-imports.mustache @@ -10,4 +10,4 @@ use validator::{Validate, ValidationErrors}; use crate::{header, types::*}; #[allow(unused_imports)] -use crate::models; +use crate::{apis, models}; diff --git a/modules/openapi-generator/src/main/resources/rust-axum/server-mod.mustache b/modules/openapi-generator/src/main/resources/rust-axum/server-mod.mustache index cf43a8dd11e1..90662711827a 100644 --- a/modules/openapi-generator/src/main/resources/rust-axum/server-mod.mustache +++ b/modules/openapi-generator/src/main/resources/rust-axum/server-mod.mustache @@ -1,7 +1,4 @@ {{>server-imports}} -use crate::{Api{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}, - {{{operationId}}}Response{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} -}; {{>server-route}} {{#apiInfo}} diff --git a/modules/openapi-generator/src/main/resources/rust-axum/server-operation.mustache b/modules/openapi-generator/src/main/resources/rust-axum/server-operation.mustache index 5ed29495424a..c33a490b163d 100644 --- a/modules/openapi-generator/src/main/resources/rust-axum/server-operation.mustache +++ b/modules/openapi-generator/src/main/resources/rust-axum/server-operation.mustache @@ -47,7 +47,7 @@ async fn {{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::{{classFilename}}::{{classnamePascalCase}}, { {{#headerParams}} {{#-first}} @@ -187,7 +187,7 @@ where let resp = match result { Ok(rsp) => match rsp { {{#responses}} - {{{operationId}}}Response::{{#vendorExtensions}}{{x-response-id}}{{/vendorExtensions}} + apis::{{classFilename}}::{{{operationId}}}Response::{{#vendorExtensions}}{{x-response-id}}{{/vendorExtensions}} {{#dataType}} {{^headers}} (body) diff --git a/modules/openapi-generator/src/main/resources/rust-axum/server-route.mustache b/modules/openapi-generator/src/main/resources/rust-axum/server-route.mustache index 2a17022c2c02..ab5204cc4ffa 100644 --- a/modules/openapi-generator/src/main/resources/rust-axum/server-route.mustache +++ b/modules/openapi-generator/src/main/resources/rust-axum/server-route.mustache @@ -2,7 +2,7 @@ pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: Api + 'static, + A: {{#apiInfo}}{{#apis}}{{#operations}}apis::{{classFilename}}::{{classnamePascalCase}} + {{/operations}}{{/apis}}{{/apiInfo}}'static, { // build our application with a route Router::new() From 7d6dbfc346704eeb9238d7d77f31372d1d5c5975 Mon Sep 17 00:00:00 2001 From: Kalvin Pearce Date: Thu, 9 May 2024 15:06:16 +1000 Subject: [PATCH 2/6] [rust-axum] Fix: missing types in api files --- .../src/main/resources/rust-axum/apis.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/rust-axum/apis.mustache b/modules/openapi-generator/src/main/resources/rust-axum/apis.mustache index 5226a6b5c8d2..86f58f7ce380 100644 --- a/modules/openapi-generator/src/main/resources/rust-axum/apis.mustache +++ b/modules/openapi-generator/src/main/resources/rust-axum/apis.mustache @@ -5,7 +5,7 @@ use bytes::Bytes; use http::Method; use serde::{Deserialize, Serialize}; -use crate::{models, types}; +use crate::{models, types::*}; {{#operations}} {{#operation}} From 08b2d0482cc0e6af183a5ae6f63733e5f217616a Mon Sep 17 00:00:00 2001 From: Kalvin Pearce Date: Thu, 9 May 2024 15:06:54 +1000 Subject: [PATCH 3/6] [rust-axum] Fix: add samples output --- .../multipart-v3/.openapi-generator/FILES | 2 + .../output/multipart-v3/src/apis/default.rs | 62 ++ .../output/multipart-v3/src/apis/mod.rs | 1 + .../rust-axum/output/multipart-v3/src/lib.rs | 72 +- .../output/multipart-v3/src/server/mod.rs | 21 +- .../openapi-v3/.openapi-generator/FILES | 3 + .../output/openapi-v3/src/apis/default.rs | 435 +++++++++++ .../output/openapi-v3/src/apis/mod.rs | 2 + .../output/openapi-v3/src/apis/repo.rs | 46 ++ .../rust-axum/output/openapi-v3/src/lib.rs | 500 +----------- .../output/openapi-v3/src/server/mod.rs | 175 ++--- .../output/ops-v3/.openapi-generator/FILES | 2 + .../output/ops-v3/src/apis/default.rs | 569 ++++++++++++++ .../rust-axum/output/ops-v3/src/apis/mod.rs | 1 + .../rust-axum/output/ops-v3/src/lib.rs | 613 +-------------- .../rust-axum/output/ops-v3/src/server/mod.rs | 163 ++-- .../.openapi-generator/FILES | 7 + .../src/apis/another_fake.rs | 32 + .../src/apis/fake.rs | 237 ++++++ .../src/apis/fake_classname_tags123.rs | 32 + .../src/apis/mod.rs | 6 + .../src/apis/pet.rs | 173 +++++ .../src/apis/store.rs | 93 +++ .../src/apis/user.rs | 172 +++++ .../src/lib.rs | 711 +----------------- .../src/server/mod.rs | 200 +++-- .../output/petstore/.openapi-generator/FILES | 4 + .../rust-axum/output/petstore/src/apis/mod.rs | 3 + .../rust-axum/output/petstore/src/apis/pet.rs | 177 +++++ .../output/petstore/src/apis/store.rs | 93 +++ .../output/petstore/src/apis/user.rs | 173 +++++ .../rust-axum/output/petstore/src/lib.rs | 442 +---------- .../output/petstore/src/server/mod.rs | 127 ++-- .../ping-bearer-auth/.openapi-generator/FILES | 2 + .../ping-bearer-auth/src/apis/default.rs | 29 + .../output/ping-bearer-auth/src/apis/mod.rs | 1 + .../output/ping-bearer-auth/src/lib.rs | 37 +- .../output/ping-bearer-auth/src/server/mod.rs | 10 +- .../.openapi-generator/FILES | 3 +- .../rust-axum-header-uuid/src/apis/default.rs | 30 + .../rust-axum-header-uuid/src/apis/mod.rs | 1 + .../output/rust-axum-header-uuid/src/lib.rs | 42 +- .../rust-axum-header-uuid/src/server/mod.rs | 10 +- .../rust-axum-test/.openapi-generator/FILES | 2 + .../output/rust-axum-test/src/apis/default.rs | 163 ++++ .../output/rust-axum-test/src/apis/mod.rs | 1 + .../output/rust-axum-test/src/lib.rs | 179 +---- .../output/rust-axum-test/src/server/mod.rs | 46 +- .../.openapi-generator/FILES | 2 + .../src/apis/default.rs | 30 + .../rust-axum-validation-test/src/apis/mod.rs | 1 + .../rust-axum-validation-test/src/lib.rs | 38 +- .../src/server/mod.rs | 10 +- 53 files changed, 2998 insertions(+), 2988 deletions(-) create mode 100644 samples/server/petstore/rust-axum/output/multipart-v3/src/apis/default.rs create mode 100644 samples/server/petstore/rust-axum/output/multipart-v3/src/apis/mod.rs create mode 100644 samples/server/petstore/rust-axum/output/openapi-v3/src/apis/default.rs create mode 100644 samples/server/petstore/rust-axum/output/openapi-v3/src/apis/mod.rs create mode 100644 samples/server/petstore/rust-axum/output/openapi-v3/src/apis/repo.rs create mode 100644 samples/server/petstore/rust-axum/output/ops-v3/src/apis/default.rs create mode 100644 samples/server/petstore/rust-axum/output/ops-v3/src/apis/mod.rs create mode 100644 samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/another_fake.rs create mode 100644 samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake.rs create mode 100644 samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake_classname_tags123.rs create mode 100644 samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/mod.rs create mode 100644 samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/pet.rs create mode 100644 samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/store.rs create mode 100644 samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/user.rs create mode 100644 samples/server/petstore/rust-axum/output/petstore/src/apis/mod.rs create mode 100644 samples/server/petstore/rust-axum/output/petstore/src/apis/pet.rs create mode 100644 samples/server/petstore/rust-axum/output/petstore/src/apis/store.rs create mode 100644 samples/server/petstore/rust-axum/output/petstore/src/apis/user.rs create mode 100644 samples/server/petstore/rust-axum/output/ping-bearer-auth/src/apis/default.rs create mode 100644 samples/server/petstore/rust-axum/output/ping-bearer-auth/src/apis/mod.rs create mode 100644 samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/apis/default.rs create mode 100644 samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/apis/mod.rs create mode 100644 samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/default.rs create mode 100644 samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/mod.rs create mode 100644 samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/apis/default.rs create mode 100644 samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/apis/mod.rs diff --git a/samples/server/petstore/rust-axum/output/multipart-v3/.openapi-generator/FILES b/samples/server/petstore/rust-axum/output/multipart-v3/.openapi-generator/FILES index ea1c5b8c5beb..683914c4c643 100644 --- a/samples/server/petstore/rust-axum/output/multipart-v3/.openapi-generator/FILES +++ b/samples/server/petstore/rust-axum/output/multipart-v3/.openapi-generator/FILES @@ -1,6 +1,8 @@ .gitignore Cargo.toml README.md +src/apis/default.rs +src/apis/mod.rs src/header.rs src/lib.rs src/models.rs diff --git a/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/default.rs b/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/default.rs new file mode 100644 index 000000000000..8384048e0899 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/default.rs @@ -0,0 +1,62 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum MultipartRelatedRequestPostResponse { + /// OK + Status201_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum MultipartRequestPostResponse { + /// OK + Status201_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum MultipleIdenticalMimeTypesPostResponse { + /// OK + Status200_OK, +} + +/// Default +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait Default { + /// MultipartRelatedRequestPost - POST /multipart_related_request + async fn multipart_related_request_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: axum::body::Body, + ) -> Result; + /// MultipartRequestPost - POST /multipart_request + async fn multipart_request_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Multipart, + ) -> Result; + /// MultipleIdenticalMimeTypesPost - POST /multiple-identical-mime-types + async fn multiple_identical_mime_types_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: axum::body::Body, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/mod.rs new file mode 100644 index 000000000000..1be8d340b8e0 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/mod.rs @@ -0,0 +1 @@ +pub mod default; diff --git a/samples/server/petstore/rust-axum/output/multipart-v3/src/lib.rs b/samples/server/petstore/rust-axum/output/multipart-v3/src/lib.rs index f34355edde08..cc053adc1ca5 100644 --- a/samples/server/petstore/rust-axum/output/multipart-v3/src/lib.rs +++ b/samples/server/petstore/rust-axum/output/multipart-v3/src/lib.rs @@ -8,79 +8,19 @@ unused_imports, unused_attributes )] -#![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)] - -use async_trait::async_trait; -use axum::extract::*; -use axum_extra::extract::{CookieJar, Multipart}; -use bytes::Bytes; -use http::Method; -use serde::{Deserialize, Serialize}; - -use types::*; +#![allow( + clippy::derive_partial_eq_without_eq, + clippy::disallowed_names, + clippy::too_many_arguments +)] pub const BASE_PATH: &str = ""; pub const API_VERSION: &str = "1.0.7"; -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum MultipartRelatedRequestPostResponse { - /// OK - Status201_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum MultipartRequestPostResponse { - /// OK - Status201_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum MultipleIdenticalMimeTypesPostResponse { - /// OK - Status200_OK, -} - -/// API -#[async_trait] -#[allow(clippy::ptr_arg)] -pub trait Api { - /// MultipartRelatedRequestPost - POST /multipart_related_request - async fn multipart_related_request_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: axum::body::Body, - ) -> Result; - - /// MultipartRequestPost - POST /multipart_request - async fn multipart_request_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Multipart, - ) -> Result; - - /// MultipleIdenticalMimeTypesPost - POST /multiple-identical-mime-types - async fn multiple_identical_mime_types_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: axum::body::Body, - ) -> Result; -} - #[cfg(feature = "server")] pub mod server; +pub mod apis; pub mod models; pub mod types; diff --git a/samples/server/petstore/rust-axum/output/multipart-v3/src/server/mod.rs b/samples/server/petstore/rust-axum/output/multipart-v3/src/server/mod.rs index ea53d41e0e85..89fd45ae4611 100644 --- a/samples/server/petstore/rust-axum/output/multipart-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/multipart-v3/src/server/mod.rs @@ -10,18 +10,13 @@ use validator::{Validate, ValidationErrors}; use crate::{header, types::*}; #[allow(unused_imports)] -use crate::models; - -use crate::{ - Api, MultipartRelatedRequestPostResponse, MultipartRequestPostResponse, - MultipleIdenticalMimeTypesPostResponse, -}; +use crate::{apis, models}; /// Setup API Server. pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: Api + 'static, + A: apis::default::Default + 'static, { // build our application with a route Router::new() @@ -52,7 +47,7 @@ async fn multipart_related_request_post( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = @@ -76,7 +71,7 @@ where let resp = match result { Ok(rsp) => match rsp { - MultipartRelatedRequestPostResponse::Status201_OK => { + apis::default::MultipartRelatedRequestPostResponse::Status201_OK => { let mut response = response.status(201); response.body(Body::empty()) } @@ -109,7 +104,7 @@ async fn multipart_request_post( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || multipart_request_post_validation()) @@ -132,7 +127,7 @@ where let resp = match result { Ok(rsp) => match rsp { - MultipartRequestPostResponse::Status201_OK => { + apis::default::MultipartRequestPostResponse::Status201_OK => { let mut response = response.status(201); response.body(Body::empty()) } @@ -165,7 +160,7 @@ async fn multiple_identical_mime_types_post( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = @@ -189,7 +184,7 @@ where let resp = match result { Ok(rsp) => match rsp { - MultipleIdenticalMimeTypesPostResponse::Status200_OK => { + apis::default::MultipleIdenticalMimeTypesPostResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/.openapi-generator/FILES b/samples/server/petstore/rust-axum/output/openapi-v3/.openapi-generator/FILES index ea1c5b8c5beb..747293c5be25 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/.openapi-generator/FILES +++ b/samples/server/petstore/rust-axum/output/openapi-v3/.openapi-generator/FILES @@ -1,6 +1,9 @@ .gitignore Cargo.toml README.md +src/apis/default.rs +src/apis/mod.rs +src/apis/repo.rs src/header.rs src/lib.rs src/models.rs diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/default.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/default.rs new file mode 100644 index 000000000000..21ef2e768481 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/default.rs @@ -0,0 +1,435 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum AnyOfGetResponse { + /// Success + Status200_Success(models::AnyOfObject), + /// AlternateSuccess + Status201_AlternateSuccess(models::Model12345AnyOfObject), + /// AnyOfSuccess + Status202_AnyOfSuccess(models::AnyOfGet202Response), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum CallbackWithHeaderPostResponse { + /// OK + Status204_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum ComplexQueryParamGetResponse { + /// Success + Status200_Success, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum EnumInPathPathParamGetResponse { + /// Success + Status200_Success, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum JsonComplexQueryParamGetResponse { + /// Success + Status200_Success, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum MandatoryRequestHeaderGetResponse { + /// Success + Status200_Success, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum MergePatchJsonGetResponse { + /// merge-patch+json-encoded response + Status200_Merge(models::AnotherXmlObject), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum MultigetGetResponse { + /// JSON rsp + Status200_JSONRsp(models::AnotherXmlObject), + /// XML rsp + Status201_XMLRsp(String), + /// octet rsp + Status202_OctetRsp(ByteArray), + /// string rsp + Status203_StringRsp(String), + /// Duplicate Response long text. One. + Status204_DuplicateResponseLongText(models::AnotherXmlObject), + /// Duplicate Response long text. Two. + Status205_DuplicateResponseLongText(models::AnotherXmlObject), + /// Duplicate Response long text. Three. + Status206_DuplicateResponseLongText(models::AnotherXmlObject), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum MultipleAuthSchemeGetResponse { + /// Check that limiting to multiple required auth schemes works + Status200_CheckThatLimitingToMultipleRequiredAuthSchemesWorks, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum OneOfGetResponse { + /// Success + Status200_Success(models::OneOfGet200Response), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum OverrideServerGetResponse { + /// Success. + Status204_Success, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum ParamgetGetResponse { + /// JSON rsp + Status200_JSONRsp(models::AnotherXmlObject), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum ReadonlyAuthSchemeGetResponse { + /// Check that limiting to a single required auth scheme works + Status200_CheckThatLimitingToASingleRequiredAuthSchemeWorks, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum RegisterCallbackPostResponse { + /// OK + Status204_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum RequiredOctetStreamPutResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum ResponsesWithHeadersGetResponse { + /// Success + Status200_Success { + body: String, + success_info: String, + bool_header: Option, + object_header: Option, + }, + /// Precondition Failed + Status412_PreconditionFailed { + further_info: Option, + failure_info: Option, + }, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Rfc7807GetResponse { + /// OK + Status204_OK(models::ObjectWithArrayOfObjects), + /// NotFound + Status404_NotFound(models::ObjectWithArrayOfObjects), + /// NotAcceptable + Status406_NotAcceptable(String), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum UntypedPropertyGetResponse { + /// Check that untyped properties works + Status200_CheckThatUntypedPropertiesWorks, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum UuidGetResponse { + /// Duplicate Response long text. One. + Status200_DuplicateResponseLongText(uuid::Uuid), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum XmlExtraPostResponse { + /// OK + Status201_OK, + /// Bad Request + Status400_BadRequest, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum XmlOtherPostResponse { + /// OK + Status201_OK(String), + /// Bad Request + Status400_BadRequest, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum XmlOtherPutResponse { + /// OK + Status201_OK, + /// Bad Request + Status400_BadRequest, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum XmlPostResponse { + /// OK + Status201_OK, + /// Bad Request + Status400_BadRequest, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum XmlPutResponse { + /// OK + Status201_OK, + /// Bad Request + Status400_BadRequest, +} + +/// Default +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait Default { + /// AnyOfGet - GET /any-of + async fn any_of_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::AnyOfGetQueryParams, + ) -> Result; + /// CallbackWithHeaderPost - POST /callback-with-header + async fn callback_with_header_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::CallbackWithHeaderPostQueryParams, + ) -> Result; + /// ComplexQueryParamGet - GET /complex-query-param + async fn complex_query_param_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::ComplexQueryParamGetQueryParams, + ) -> Result; + /// EnumInPathPathParamGet - GET /enum_in_path/{path_param} + async fn enum_in_path_path_param_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::EnumInPathPathParamGetPathParams, + ) -> Result; + /// JsonComplexQueryParamGet - GET /json-complex-query-param + async fn json_complex_query_param_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::JsonComplexQueryParamGetQueryParams, + ) -> Result; + /// MandatoryRequestHeaderGet - GET /mandatory-request-header + async fn mandatory_request_header_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + header_params: models::MandatoryRequestHeaderGetHeaderParams, + ) -> Result; + /// MergePatchJsonGet - GET /merge-patch-json + async fn merge_patch_json_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Get some stuff.. + /// + /// MultigetGet - GET /multiget + async fn multiget_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// MultipleAuthSchemeGet - GET /multiple_auth_scheme + async fn multiple_auth_scheme_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// OneOfGet - GET /one-of + async fn one_of_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// OverrideServerGet - GET /override-server + async fn override_server_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Get some stuff with parameters.. + /// + /// ParamgetGet - GET /paramget + async fn paramget_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::ParamgetGetQueryParams, + ) -> Result; + /// ReadonlyAuthSchemeGet - GET /readonly_auth_scheme + async fn readonly_auth_scheme_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// RegisterCallbackPost - POST /register-callback + async fn register_callback_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::RegisterCallbackPostQueryParams, + ) -> Result; + /// RequiredOctetStreamPut - PUT /required_octet_stream + async fn required_octet_stream_put( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Bytes, + ) -> Result; + /// ResponsesWithHeadersGet - GET /responses_with_headers + async fn responses_with_headers_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Rfc7807Get - GET /rfc7807 + async fn rfc7807_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// UntypedPropertyGet - GET /untyped_property + async fn untyped_property_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Option, + ) -> Result; + /// UuidGet - GET /uuid + async fn uuid_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// XmlExtraPost - POST /xml_extra + async fn xml_extra_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Bytes, + ) -> Result; + /// XmlOtherPost - POST /xml_other + async fn xml_other_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Bytes, + ) -> Result; + /// XmlOtherPut - PUT /xml_other + async fn xml_other_put( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Bytes, + ) -> Result; + /// Post an array. + /// + /// XmlPost - POST /xml + async fn xml_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Bytes, + ) -> Result; + /// XmlPut - PUT /xml + async fn xml_put( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Bytes, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/mod.rs new file mode 100644 index 000000000000..8675010ecc45 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/mod.rs @@ -0,0 +1,2 @@ +pub mod default; +pub mod repo; diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/repo.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/repo.rs new file mode 100644 index 000000000000..ebd3168dacfc --- /dev/null +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/repo.rs @@ -0,0 +1,46 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum CreateRepoResponse { + /// Success + Status200_Success, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum GetRepoInfoResponse { + /// OK + Status200_OK(String), +} + +/// Repo +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait Repo { + /// CreateRepo - POST /repos + async fn create_repo( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::ObjectParam, + ) -> Result; + /// GetRepoInfo - GET /repos/{repoId} + async fn get_repo_info( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::GetRepoInfoPathParams, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/lib.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/lib.rs index 999fa523c362..cc053adc1ca5 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/lib.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/lib.rs @@ -8,507 +8,19 @@ unused_imports, unused_attributes )] -#![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)] - -use async_trait::async_trait; -use axum::extract::*; -use axum_extra::extract::{CookieJar, Multipart}; -use bytes::Bytes; -use http::Method; -use serde::{Deserialize, Serialize}; - -use types::*; +#![allow( + clippy::derive_partial_eq_without_eq, + clippy::disallowed_names, + clippy::too_many_arguments +)] pub const BASE_PATH: &str = ""; pub const API_VERSION: &str = "1.0.7"; -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum AnyOfGetResponse { - /// Success - Status200_Success(models::AnyOfObject), - /// AlternateSuccess - Status201_AlternateSuccess(models::Model12345AnyOfObject), - /// AnyOfSuccess - Status202_AnyOfSuccess(models::AnyOfGet202Response), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum CallbackWithHeaderPostResponse { - /// OK - Status204_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum ComplexQueryParamGetResponse { - /// Success - Status200_Success, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum EnumInPathPathParamGetResponse { - /// Success - Status200_Success, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum JsonComplexQueryParamGetResponse { - /// Success - Status200_Success, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum MandatoryRequestHeaderGetResponse { - /// Success - Status200_Success, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum MergePatchJsonGetResponse { - /// merge-patch+json-encoded response - Status200_Merge(models::AnotherXmlObject), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum MultigetGetResponse { - /// JSON rsp - Status200_JSONRsp(models::AnotherXmlObject), - /// XML rsp - Status201_XMLRsp(String), - /// octet rsp - Status202_OctetRsp(ByteArray), - /// string rsp - Status203_StringRsp(String), - /// Duplicate Response long text. One. - Status204_DuplicateResponseLongText(models::AnotherXmlObject), - /// Duplicate Response long text. Two. - Status205_DuplicateResponseLongText(models::AnotherXmlObject), - /// Duplicate Response long text. Three. - Status206_DuplicateResponseLongText(models::AnotherXmlObject), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum MultipleAuthSchemeGetResponse { - /// Check that limiting to multiple required auth schemes works - Status200_CheckThatLimitingToMultipleRequiredAuthSchemesWorks, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum OneOfGetResponse { - /// Success - Status200_Success(models::OneOfGet200Response), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum OverrideServerGetResponse { - /// Success. - Status204_Success, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum ParamgetGetResponse { - /// JSON rsp - Status200_JSONRsp(models::AnotherXmlObject), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum ReadonlyAuthSchemeGetResponse { - /// Check that limiting to a single required auth scheme works - Status200_CheckThatLimitingToASingleRequiredAuthSchemeWorks, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum RegisterCallbackPostResponse { - /// OK - Status204_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum RequiredOctetStreamPutResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum ResponsesWithHeadersGetResponse { - /// Success - Status200_Success { - body: String, - success_info: String, - bool_header: Option, - object_header: Option, - }, - /// Precondition Failed - Status412_PreconditionFailed { - further_info: Option, - failure_info: Option, - }, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Rfc7807GetResponse { - /// OK - Status204_OK(models::ObjectWithArrayOfObjects), - /// NotFound - Status404_NotFound(models::ObjectWithArrayOfObjects), - /// NotAcceptable - Status406_NotAcceptable(String), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum UntypedPropertyGetResponse { - /// Check that untyped properties works - Status200_CheckThatUntypedPropertiesWorks, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum UuidGetResponse { - /// Duplicate Response long text. One. - Status200_DuplicateResponseLongText(uuid::Uuid), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum XmlExtraPostResponse { - /// OK - Status201_OK, - /// Bad Request - Status400_BadRequest, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum XmlOtherPostResponse { - /// OK - Status201_OK(String), - /// Bad Request - Status400_BadRequest, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum XmlOtherPutResponse { - /// OK - Status201_OK, - /// Bad Request - Status400_BadRequest, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum XmlPostResponse { - /// OK - Status201_OK, - /// Bad Request - Status400_BadRequest, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum XmlPutResponse { - /// OK - Status201_OK, - /// Bad Request - Status400_BadRequest, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum CreateRepoResponse { - /// Success - Status200_Success, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum GetRepoInfoResponse { - /// OK - Status200_OK(String), -} - -/// API -#[async_trait] -#[allow(clippy::ptr_arg)] -pub trait Api { - /// AnyOfGet - GET /any-of - async fn any_of_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::AnyOfGetQueryParams, - ) -> Result; - - /// CallbackWithHeaderPost - POST /callback-with-header - async fn callback_with_header_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::CallbackWithHeaderPostQueryParams, - ) -> Result; - - /// ComplexQueryParamGet - GET /complex-query-param - async fn complex_query_param_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::ComplexQueryParamGetQueryParams, - ) -> Result; - - /// EnumInPathPathParamGet - GET /enum_in_path/{path_param} - async fn enum_in_path_path_param_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::EnumInPathPathParamGetPathParams, - ) -> Result; - - /// JsonComplexQueryParamGet - GET /json-complex-query-param - async fn json_complex_query_param_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::JsonComplexQueryParamGetQueryParams, - ) -> Result; - - /// MandatoryRequestHeaderGet - GET /mandatory-request-header - async fn mandatory_request_header_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - header_params: models::MandatoryRequestHeaderGetHeaderParams, - ) -> Result; - - /// MergePatchJsonGet - GET /merge-patch-json - async fn merge_patch_json_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Get some stuff.. - /// - /// MultigetGet - GET /multiget - async fn multiget_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// MultipleAuthSchemeGet - GET /multiple_auth_scheme - async fn multiple_auth_scheme_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// OneOfGet - GET /one-of - async fn one_of_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// OverrideServerGet - GET /override-server - async fn override_server_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Get some stuff with parameters.. - /// - /// ParamgetGet - GET /paramget - async fn paramget_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::ParamgetGetQueryParams, - ) -> Result; - - /// ReadonlyAuthSchemeGet - GET /readonly_auth_scheme - async fn readonly_auth_scheme_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// RegisterCallbackPost - POST /register-callback - async fn register_callback_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::RegisterCallbackPostQueryParams, - ) -> Result; - - /// RequiredOctetStreamPut - PUT /required_octet_stream - async fn required_octet_stream_put( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; - - /// ResponsesWithHeadersGet - GET /responses_with_headers - async fn responses_with_headers_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Rfc7807Get - GET /rfc7807 - async fn rfc7807_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// UntypedPropertyGet - GET /untyped_property - async fn untyped_property_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Option, - ) -> Result; - - /// UuidGet - GET /uuid - async fn uuid_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// XmlExtraPost - POST /xml_extra - async fn xml_extra_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; - - /// XmlOtherPost - POST /xml_other - async fn xml_other_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; - - /// XmlOtherPut - PUT /xml_other - async fn xml_other_put( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; - - /// Post an array. - /// - /// XmlPost - POST /xml - async fn xml_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; - - /// XmlPut - PUT /xml - async fn xml_put( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Bytes, - ) -> Result; - - /// CreateRepo - POST /repos - async fn create_repo( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::ObjectParam, - ) -> Result; - - /// GetRepoInfo - GET /repos/{repoId} - async fn get_repo_info( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetRepoInfoPathParams, - ) -> Result; -} - #[cfg(feature = "server")] pub mod server; +pub mod apis; pub mod models; pub mod types; diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs index 77ff323cab4c..c9c13b843c7e 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs @@ -10,24 +10,13 @@ use validator::{Validate, ValidationErrors}; use crate::{header, types::*}; #[allow(unused_imports)] -use crate::models; - -use crate::{ - AnyOfGetResponse, Api, CallbackWithHeaderPostResponse, ComplexQueryParamGetResponse, - CreateRepoResponse, EnumInPathPathParamGetResponse, GetRepoInfoResponse, - JsonComplexQueryParamGetResponse, MandatoryRequestHeaderGetResponse, MergePatchJsonGetResponse, - MultigetGetResponse, MultipleAuthSchemeGetResponse, OneOfGetResponse, - OverrideServerGetResponse, ParamgetGetResponse, ReadonlyAuthSchemeGetResponse, - RegisterCallbackPostResponse, RequiredOctetStreamPutResponse, ResponsesWithHeadersGetResponse, - Rfc7807GetResponse, UntypedPropertyGetResponse, UuidGetResponse, XmlExtraPostResponse, - XmlOtherPostResponse, XmlOtherPutResponse, XmlPostResponse, XmlPutResponse, -}; +use crate::{apis, models}; /// Setup API Server. pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: Api + 'static, + A: apis::default::Default + apis::repo::Repo + 'static, { // build our application with a route Router::new() @@ -107,7 +96,7 @@ async fn any_of_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = any_of_get_validation(query_params); @@ -127,7 +116,7 @@ where let resp = match result { Ok(rsp) => match rsp { - AnyOfGetResponse::Status200_Success(body) => { + apis::default::AnyOfGetResponse::Status200_Success(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -150,7 +139,7 @@ where .unwrap()?; response.body(Body::from(body_content)) } - AnyOfGetResponse::Status201_AlternateSuccess(body) => { + apis::default::AnyOfGetResponse::Status201_AlternateSuccess(body) => { let mut response = response.status(201); { let mut response_headers = response.headers_mut().unwrap(); @@ -173,7 +162,7 @@ where .unwrap()?; response.body(Body::from(body_content)) } - AnyOfGetResponse::Status202_AnyOfSuccess(body) => { + apis::default::AnyOfGetResponse::Status202_AnyOfSuccess(body) => { let mut response = response.status(202); { let mut response_headers = response.headers_mut().unwrap(); @@ -229,7 +218,7 @@ async fn callback_with_header_post( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = callback_with_header_post_validation(query_params); @@ -249,7 +238,7 @@ where let resp = match result { Ok(rsp) => match rsp { - CallbackWithHeaderPostResponse::Status204_OK => { + apis::default::CallbackWithHeaderPostResponse::Status204_OK => { let mut response = response.status(204); response.body(Body::empty()) } @@ -286,7 +275,7 @@ async fn complex_query_param_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = complex_query_param_get_validation(query_params); @@ -306,7 +295,7 @@ where let resp = match result { Ok(rsp) => match rsp { - ComplexQueryParamGetResponse::Status200_Success => { + apis::default::ComplexQueryParamGetResponse::Status200_Success => { let mut response = response.status(200); response.body(Body::empty()) } @@ -343,7 +332,7 @@ async fn enum_in_path_path_param_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = enum_in_path_path_param_get_validation(path_params); @@ -363,7 +352,7 @@ where let resp = match result { Ok(rsp) => match rsp { - EnumInPathPathParamGetResponse::Status200_Success => { + apis::default::EnumInPathPathParamGetResponse::Status200_Success => { let mut response = response.status(200); response.body(Body::empty()) } @@ -400,7 +389,7 @@ async fn json_complex_query_param_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = json_complex_query_param_get_validation(query_params); @@ -420,7 +409,7 @@ where let resp = match result { Ok(rsp) => match rsp { - JsonComplexQueryParamGetResponse::Status200_Success => { + apis::default::JsonComplexQueryParamGetResponse::Status200_Success => { let mut response = response.status(200); response.body(Body::empty()) } @@ -457,7 +446,7 @@ async fn mandatory_request_header_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { // Header parameters let header_params = { @@ -510,7 +499,7 @@ where let resp = match result { Ok(rsp) => match rsp { - MandatoryRequestHeaderGetResponse::Status200_Success => { + apis::default::MandatoryRequestHeaderGetResponse::Status200_Success => { let mut response = response.status(200); response.body(Body::empty()) } @@ -542,7 +531,7 @@ async fn merge_patch_json_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = merge_patch_json_get_validation(); @@ -562,7 +551,7 @@ where let resp = match result { Ok(rsp) => match rsp { - MergePatchJsonGetResponse::Status200_Merge(body) => { + apis::default::MergePatchJsonGetResponse::Status200_Merge(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -613,7 +602,7 @@ async fn multiget_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = multiget_get_validation(); @@ -630,7 +619,7 @@ where let resp = match result { Ok(rsp) => match rsp { - MultigetGetResponse::Status200_JSONRsp(body) => { + apis::default::MultigetGetResponse::Status200_JSONRsp(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -653,7 +642,7 @@ where .unwrap()?; response.body(Body::from(body_content)) } - MultigetGetResponse::Status201_XMLRsp(body) => { + apis::default::MultigetGetResponse::Status201_XMLRsp(body) => { let mut response = response.status(201); { let mut response_headers = response.headers_mut().unwrap(); @@ -669,7 +658,7 @@ where let body_content = body; response.body(Body::from(body_content)) } - MultigetGetResponse::Status202_OctetRsp(body) => { + apis::default::MultigetGetResponse::Status202_OctetRsp(body) => { let mut response = response.status(202); { let mut response_headers = response.headers_mut().unwrap(); @@ -685,7 +674,7 @@ where let body_content = body.0; response.body(Body::from(body_content)) } - MultigetGetResponse::Status203_StringRsp(body) => { + apis::default::MultigetGetResponse::Status203_StringRsp(body) => { let mut response = response.status(203); { let mut response_headers = response.headers_mut().unwrap(); @@ -701,7 +690,7 @@ where let body_content = body; response.body(Body::from(body_content)) } - MultigetGetResponse::Status204_DuplicateResponseLongText(body) => { + apis::default::MultigetGetResponse::Status204_DuplicateResponseLongText(body) => { let mut response = response.status(204); { let mut response_headers = response.headers_mut().unwrap(); @@ -724,7 +713,7 @@ where .unwrap()?; response.body(Body::from(body_content)) } - MultigetGetResponse::Status205_DuplicateResponseLongText(body) => { + apis::default::MultigetGetResponse::Status205_DuplicateResponseLongText(body) => { let mut response = response.status(205); { let mut response_headers = response.headers_mut().unwrap(); @@ -747,7 +736,7 @@ where .unwrap()?; response.body(Body::from(body_content)) } - MultigetGetResponse::Status206_DuplicateResponseLongText(body) => { + apis::default::MultigetGetResponse::Status206_DuplicateResponseLongText(body) => { let mut response = response.status(206); { let mut response_headers = response.headers_mut().unwrap(); @@ -798,7 +787,7 @@ async fn multiple_auth_scheme_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = multiple_auth_scheme_get_validation(); @@ -818,7 +807,7 @@ where let resp = match result { Ok(rsp) => match rsp { - MultipleAuthSchemeGetResponse::Status200_CheckThatLimitingToMultipleRequiredAuthSchemesWorks + apis::default::MultipleAuthSchemeGetResponse::Status200_CheckThatLimitingToMultipleRequiredAuthSchemesWorks => { let mut response = response.status(200); @@ -852,7 +841,7 @@ async fn one_of_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = one_of_get_validation(); @@ -869,7 +858,7 @@ where let resp = match result { Ok(rsp) => match rsp { - OneOfGetResponse::Status200_Success(body) => { + apis::default::OneOfGetResponse::Status200_Success(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -920,7 +909,7 @@ async fn override_server_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = override_server_get_validation(); @@ -940,7 +929,7 @@ where let resp = match result { Ok(rsp) => match rsp { - OverrideServerGetResponse::Status204_Success => { + apis::default::OverrideServerGetResponse::Status204_Success => { let mut response = response.status(204); response.body(Body::empty()) } @@ -977,7 +966,7 @@ async fn paramget_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = paramget_get_validation(query_params); @@ -997,7 +986,7 @@ where let resp = match result { Ok(rsp) => match rsp { - ParamgetGetResponse::Status200_JSONRsp(body) => { + apis::default::ParamgetGetResponse::Status200_JSONRsp(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -1048,7 +1037,7 @@ async fn readonly_auth_scheme_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = readonly_auth_scheme_get_validation(); @@ -1068,7 +1057,7 @@ where let resp = match result { Ok(rsp) => match rsp { - ReadonlyAuthSchemeGetResponse::Status200_CheckThatLimitingToASingleRequiredAuthSchemeWorks + apis::default::ReadonlyAuthSchemeGetResponse::Status200_CheckThatLimitingToASingleRequiredAuthSchemeWorks => { let mut response = response.status(200); @@ -1107,7 +1096,7 @@ async fn register_callback_post( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = register_callback_post_validation(query_params); @@ -1127,7 +1116,7 @@ where let resp = match result { Ok(rsp) => match rsp { - RegisterCallbackPostResponse::Status204_OK => { + apis::default::RegisterCallbackPostResponse::Status204_OK => { let mut response = response.status(204); response.body(Body::empty()) } @@ -1168,7 +1157,7 @@ async fn required_octet_stream_put( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = required_octet_stream_put_validation(body); @@ -1188,7 +1177,7 @@ where let resp = match result { Ok(rsp) => match rsp { - RequiredOctetStreamPutResponse::Status200_OK => { + apis::default::RequiredOctetStreamPutResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1220,7 +1209,7 @@ async fn responses_with_headers_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = responses_with_headers_get_validation(); @@ -1240,7 +1229,7 @@ where let resp = match result { Ok(rsp) => match rsp { - ResponsesWithHeadersGetResponse::Status200_Success { + apis::default::ResponsesWithHeadersGetResponse::Status200_Success { body, success_info, bool_header, @@ -1312,7 +1301,7 @@ where .unwrap()?; response.body(Body::from(body_content)) } - ResponsesWithHeadersGetResponse::Status412_PreconditionFailed { + apis::default::ResponsesWithHeadersGetResponse::Status412_PreconditionFailed { further_info, failure_info, } => { @@ -1378,7 +1367,7 @@ async fn rfc7807_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = rfc7807_get_validation(); @@ -1395,7 +1384,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Rfc7807GetResponse::Status204_OK(body) => { + apis::default::Rfc7807GetResponse::Status204_OK(body) => { let mut response = response.status(204); { let mut response_headers = response.headers_mut().unwrap(); @@ -1418,7 +1407,7 @@ where .unwrap()?; response.body(Body::from(body_content)) } - Rfc7807GetResponse::Status404_NotFound(body) => { + apis::default::Rfc7807GetResponse::Status404_NotFound(body) => { let mut response = response.status(404); { let mut response_headers = response.headers_mut().unwrap(); @@ -1441,7 +1430,7 @@ where .unwrap()?; response.body(Body::from(body_content)) } - Rfc7807GetResponse::Status406_NotAcceptable(body) => { + apis::default::Rfc7807GetResponse::Status406_NotAcceptable(body) => { let mut response = response.status(406); { let mut response_headers = response.headers_mut().unwrap(); @@ -1500,7 +1489,7 @@ async fn untyped_property_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = untyped_property_get_validation(body); @@ -1519,18 +1508,20 @@ where let mut response = Response::builder(); let resp = match result { - Ok(rsp) => match rsp { - UntypedPropertyGetResponse::Status200_CheckThatUntypedPropertiesWorks => { - let mut response = response.status(200); - response.body(Body::empty()) - } - }, - Err(_) => { - // Application code returned an error. This should not happen, as the implementation should - // return a valid response. - response.status(500).body(Body::empty()) - } - }; + Ok(rsp) => match rsp { + apis::default::UntypedPropertyGetResponse::Status200_CheckThatUntypedPropertiesWorks + => { + + let mut response = response.status(200); + response.body(Body::empty()) + }, + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.status(500).body(Body::empty()) + }, + }; resp.map_err(|e| { error!(error = ?e); @@ -1552,7 +1543,7 @@ async fn uuid_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = uuid_get_validation(); @@ -1569,7 +1560,7 @@ where let resp = match result { Ok(rsp) => match rsp { - UuidGetResponse::Status200_DuplicateResponseLongText(body) => { + apis::default::UuidGetResponse::Status200_DuplicateResponseLongText(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -1627,7 +1618,7 @@ async fn xml_extra_post( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = xml_extra_post_validation(body); @@ -1647,11 +1638,11 @@ where let resp = match result { Ok(rsp) => match rsp { - XmlExtraPostResponse::Status201_OK => { + apis::default::XmlExtraPostResponse::Status201_OK => { let mut response = response.status(201); response.body(Body::empty()) } - XmlExtraPostResponse::Status400_BadRequest => { + apis::default::XmlExtraPostResponse::Status400_BadRequest => { let mut response = response.status(400); response.body(Body::empty()) } @@ -1690,7 +1681,7 @@ async fn xml_other_post( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = xml_other_post_validation(body); @@ -1710,7 +1701,7 @@ where let resp = match result { Ok(rsp) => match rsp { - XmlOtherPostResponse::Status201_OK(body) => { + apis::default::XmlOtherPostResponse::Status201_OK(body) => { let mut response = response.status(201); { let mut response_headers = response.headers_mut().unwrap(); @@ -1726,7 +1717,7 @@ where let body_content = body; response.body(Body::from(body_content)) } - XmlOtherPostResponse::Status400_BadRequest => { + apis::default::XmlOtherPostResponse::Status400_BadRequest => { let mut response = response.status(400); response.body(Body::empty()) } @@ -1765,7 +1756,7 @@ async fn xml_other_put( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = xml_other_put_validation(body); @@ -1785,11 +1776,11 @@ where let resp = match result { Ok(rsp) => match rsp { - XmlOtherPutResponse::Status201_OK => { + apis::default::XmlOtherPutResponse::Status201_OK => { let mut response = response.status(201); response.body(Body::empty()) } - XmlOtherPutResponse::Status400_BadRequest => { + apis::default::XmlOtherPutResponse::Status400_BadRequest => { let mut response = response.status(400); response.body(Body::empty()) } @@ -1828,7 +1819,7 @@ async fn xml_post( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = xml_post_validation(body); @@ -1848,11 +1839,11 @@ where let resp = match result { Ok(rsp) => match rsp { - XmlPostResponse::Status201_OK => { + apis::default::XmlPostResponse::Status201_OK => { let mut response = response.status(201); response.body(Body::empty()) } - XmlPostResponse::Status400_BadRequest => { + apis::default::XmlPostResponse::Status400_BadRequest => { let mut response = response.status(400); response.body(Body::empty()) } @@ -1891,7 +1882,7 @@ async fn xml_put( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let validation = xml_put_validation(body); @@ -1908,11 +1899,11 @@ where let resp = match result { Ok(rsp) => match rsp { - XmlPutResponse::Status201_OK => { + apis::default::XmlPutResponse::Status201_OK => { let mut response = response.status(201); response.body(Body::empty()) } - XmlPutResponse::Status400_BadRequest => { + apis::default::XmlPutResponse::Status400_BadRequest => { let mut response = response.status(400); response.body(Body::empty()) } @@ -1957,7 +1948,7 @@ async fn create_repo( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::repo::Repo, { let validation = create_repo_validation(body); @@ -1977,7 +1968,7 @@ where let resp = match result { Ok(rsp) => match rsp { - CreateRepoResponse::Status200_Success => { + apis::repo::CreateRepoResponse::Status200_Success => { let mut response = response.status(200); response.body(Body::empty()) } @@ -2014,7 +2005,7 @@ async fn get_repo_info( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::repo::Repo, { let validation = get_repo_info_validation(path_params); @@ -2034,7 +2025,7 @@ where let resp = match result { Ok(rsp) => match rsp { - GetRepoInfoResponse::Status200_OK(body) => { + apis::repo::GetRepoInfoResponse::Status200_OK(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); diff --git a/samples/server/petstore/rust-axum/output/ops-v3/.openapi-generator/FILES b/samples/server/petstore/rust-axum/output/ops-v3/.openapi-generator/FILES index ea1c5b8c5beb..683914c4c643 100644 --- a/samples/server/petstore/rust-axum/output/ops-v3/.openapi-generator/FILES +++ b/samples/server/petstore/rust-axum/output/ops-v3/.openapi-generator/FILES @@ -1,6 +1,8 @@ .gitignore Cargo.toml README.md +src/apis/default.rs +src/apis/mod.rs src/header.rs src/lib.rs src/models.rs diff --git a/samples/server/petstore/rust-axum/output/ops-v3/src/apis/default.rs b/samples/server/petstore/rust-axum/output/ops-v3/src/apis/default.rs new file mode 100644 index 000000000000..6797483ebce0 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/ops-v3/src/apis/default.rs @@ -0,0 +1,569 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op10GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op11GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op12GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op13GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op14GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op15GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op16GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op17GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op18GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op19GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op1GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op20GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op21GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op22GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op23GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op24GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op25GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op26GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op27GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op28GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op29GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op2GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op30GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op31GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op32GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op33GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op34GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op35GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op36GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op37GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op3GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op4GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op5GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op6GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op7GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op8GetResponse { + /// OK + Status200_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Op9GetResponse { + /// OK + Status200_OK, +} + +/// Default +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait Default { + /// Op10Get - GET /op10 + async fn op10_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op11Get - GET /op11 + async fn op11_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op12Get - GET /op12 + async fn op12_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op13Get - GET /op13 + async fn op13_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op14Get - GET /op14 + async fn op14_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op15Get - GET /op15 + async fn op15_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op16Get - GET /op16 + async fn op16_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op17Get - GET /op17 + async fn op17_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op18Get - GET /op18 + async fn op18_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op19Get - GET /op19 + async fn op19_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op1Get - GET /op1 + async fn op1_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op20Get - GET /op20 + async fn op20_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op21Get - GET /op21 + async fn op21_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op22Get - GET /op22 + async fn op22_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op23Get - GET /op23 + async fn op23_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op24Get - GET /op24 + async fn op24_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op25Get - GET /op25 + async fn op25_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op26Get - GET /op26 + async fn op26_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op27Get - GET /op27 + async fn op27_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op28Get - GET /op28 + async fn op28_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op29Get - GET /op29 + async fn op29_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op2Get - GET /op2 + async fn op2_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op30Get - GET /op30 + async fn op30_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op31Get - GET /op31 + async fn op31_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op32Get - GET /op32 + async fn op32_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op33Get - GET /op33 + async fn op33_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op34Get - GET /op34 + async fn op34_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op35Get - GET /op35 + async fn op35_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op36Get - GET /op36 + async fn op36_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op37Get - GET /op37 + async fn op37_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op3Get - GET /op3 + async fn op3_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op4Get - GET /op4 + async fn op4_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op5Get - GET /op5 + async fn op5_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op6Get - GET /op6 + async fn op6_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op7Get - GET /op7 + async fn op7_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op8Get - GET /op8 + async fn op8_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Op9Get - GET /op9 + async fn op9_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/ops-v3/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/ops-v3/src/apis/mod.rs new file mode 100644 index 000000000000..1be8d340b8e0 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/ops-v3/src/apis/mod.rs @@ -0,0 +1 @@ +pub mod default; diff --git a/samples/server/petstore/rust-axum/output/ops-v3/src/lib.rs b/samples/server/petstore/rust-axum/output/ops-v3/src/lib.rs index 19337219b02b..bfdd7c899236 100644 --- a/samples/server/petstore/rust-axum/output/ops-v3/src/lib.rs +++ b/samples/server/petstore/rust-axum/output/ops-v3/src/lib.rs @@ -8,620 +8,19 @@ unused_imports, unused_attributes )] -#![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)] - -use async_trait::async_trait; -use axum::extract::*; -use axum_extra::extract::{CookieJar, Multipart}; -use bytes::Bytes; -use http::Method; -use serde::{Deserialize, Serialize}; - -use types::*; +#![allow( + clippy::derive_partial_eq_without_eq, + clippy::disallowed_names, + clippy::too_many_arguments +)] pub const BASE_PATH: &str = ""; pub const API_VERSION: &str = "0.0.1"; -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op10GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op11GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op12GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op13GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op14GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op15GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op16GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op17GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op18GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op19GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op1GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op20GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op21GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op22GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op23GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op24GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op25GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op26GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op27GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op28GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op29GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op2GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op30GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op31GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op32GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op33GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op34GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op35GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op36GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op37GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op3GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op4GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op5GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op6GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op7GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op8GetResponse { - /// OK - Status200_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Op9GetResponse { - /// OK - Status200_OK, -} - -/// API -#[async_trait] -#[allow(clippy::ptr_arg)] -pub trait Api { - /// Op10Get - GET /op10 - async fn op10_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op11Get - GET /op11 - async fn op11_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op12Get - GET /op12 - async fn op12_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op13Get - GET /op13 - async fn op13_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op14Get - GET /op14 - async fn op14_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op15Get - GET /op15 - async fn op15_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op16Get - GET /op16 - async fn op16_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op17Get - GET /op17 - async fn op17_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op18Get - GET /op18 - async fn op18_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op19Get - GET /op19 - async fn op19_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op1Get - GET /op1 - async fn op1_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op20Get - GET /op20 - async fn op20_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op21Get - GET /op21 - async fn op21_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op22Get - GET /op22 - async fn op22_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op23Get - GET /op23 - async fn op23_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op24Get - GET /op24 - async fn op24_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op25Get - GET /op25 - async fn op25_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op26Get - GET /op26 - async fn op26_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op27Get - GET /op27 - async fn op27_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op28Get - GET /op28 - async fn op28_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op29Get - GET /op29 - async fn op29_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op2Get - GET /op2 - async fn op2_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op30Get - GET /op30 - async fn op30_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op31Get - GET /op31 - async fn op31_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op32Get - GET /op32 - async fn op32_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op33Get - GET /op33 - async fn op33_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op34Get - GET /op34 - async fn op34_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op35Get - GET /op35 - async fn op35_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op36Get - GET /op36 - async fn op36_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op37Get - GET /op37 - async fn op37_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op3Get - GET /op3 - async fn op3_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op4Get - GET /op4 - async fn op4_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op5Get - GET /op5 - async fn op5_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op6Get - GET /op6 - async fn op6_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op7Get - GET /op7 - async fn op7_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op8Get - GET /op8 - async fn op8_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Op9Get - GET /op9 - async fn op9_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; -} - #[cfg(feature = "server")] pub mod server; +pub mod apis; pub mod models; pub mod types; diff --git a/samples/server/petstore/rust-axum/output/ops-v3/src/server/mod.rs b/samples/server/petstore/rust-axum/output/ops-v3/src/server/mod.rs index e9bc23c2cd3f..a8b3ed89bc76 100644 --- a/samples/server/petstore/rust-axum/output/ops-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/ops-v3/src/server/mod.rs @@ -10,24 +10,13 @@ use validator::{Validate, ValidationErrors}; use crate::{header, types::*}; #[allow(unused_imports)] -use crate::models; - -use crate::{ - Api, Op10GetResponse, Op11GetResponse, Op12GetResponse, Op13GetResponse, Op14GetResponse, - Op15GetResponse, Op16GetResponse, Op17GetResponse, Op18GetResponse, Op19GetResponse, - Op1GetResponse, Op20GetResponse, Op21GetResponse, Op22GetResponse, Op23GetResponse, - Op24GetResponse, Op25GetResponse, Op26GetResponse, Op27GetResponse, Op28GetResponse, - Op29GetResponse, Op2GetResponse, Op30GetResponse, Op31GetResponse, Op32GetResponse, - Op33GetResponse, Op34GetResponse, Op35GetResponse, Op36GetResponse, Op37GetResponse, - Op3GetResponse, Op4GetResponse, Op5GetResponse, Op6GetResponse, Op7GetResponse, Op8GetResponse, - Op9GetResponse, -}; +use crate::{apis, models}; /// Setup API Server. pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: Api + 'static, + A: apis::default::Default + 'static, { // build our application with a route Router::new() @@ -85,7 +74,7 @@ async fn op10_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op10_get_validation()) @@ -105,7 +94,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op10GetResponse::Status200_OK => { + apis::default::Op10GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -137,7 +126,7 @@ async fn op11_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op11_get_validation()) @@ -157,7 +146,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op11GetResponse::Status200_OK => { + apis::default::Op11GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -189,7 +178,7 @@ async fn op12_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op12_get_validation()) @@ -209,7 +198,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op12GetResponse::Status200_OK => { + apis::default::Op12GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -241,7 +230,7 @@ async fn op13_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op13_get_validation()) @@ -261,7 +250,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op13GetResponse::Status200_OK => { + apis::default::Op13GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -293,7 +282,7 @@ async fn op14_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op14_get_validation()) @@ -313,7 +302,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op14GetResponse::Status200_OK => { + apis::default::Op14GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -345,7 +334,7 @@ async fn op15_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op15_get_validation()) @@ -365,7 +354,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op15GetResponse::Status200_OK => { + apis::default::Op15GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -397,7 +386,7 @@ async fn op16_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op16_get_validation()) @@ -417,7 +406,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op16GetResponse::Status200_OK => { + apis::default::Op16GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -449,7 +438,7 @@ async fn op17_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op17_get_validation()) @@ -469,7 +458,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op17GetResponse::Status200_OK => { + apis::default::Op17GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -501,7 +490,7 @@ async fn op18_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op18_get_validation()) @@ -521,7 +510,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op18GetResponse::Status200_OK => { + apis::default::Op18GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -553,7 +542,7 @@ async fn op19_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op19_get_validation()) @@ -573,7 +562,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op19GetResponse::Status200_OK => { + apis::default::Op19GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -605,7 +594,7 @@ async fn op1_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op1_get_validation()) @@ -625,7 +614,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op1GetResponse::Status200_OK => { + apis::default::Op1GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -657,7 +646,7 @@ async fn op20_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op20_get_validation()) @@ -677,7 +666,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op20GetResponse::Status200_OK => { + apis::default::Op20GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -709,7 +698,7 @@ async fn op21_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op21_get_validation()) @@ -729,7 +718,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op21GetResponse::Status200_OK => { + apis::default::Op21GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -761,7 +750,7 @@ async fn op22_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op22_get_validation()) @@ -781,7 +770,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op22GetResponse::Status200_OK => { + apis::default::Op22GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -813,7 +802,7 @@ async fn op23_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op23_get_validation()) @@ -833,7 +822,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op23GetResponse::Status200_OK => { + apis::default::Op23GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -865,7 +854,7 @@ async fn op24_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op24_get_validation()) @@ -885,7 +874,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op24GetResponse::Status200_OK => { + apis::default::Op24GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -917,7 +906,7 @@ async fn op25_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op25_get_validation()) @@ -937,7 +926,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op25GetResponse::Status200_OK => { + apis::default::Op25GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -969,7 +958,7 @@ async fn op26_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op26_get_validation()) @@ -989,7 +978,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op26GetResponse::Status200_OK => { + apis::default::Op26GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1021,7 +1010,7 @@ async fn op27_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op27_get_validation()) @@ -1041,7 +1030,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op27GetResponse::Status200_OK => { + apis::default::Op27GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1073,7 +1062,7 @@ async fn op28_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op28_get_validation()) @@ -1093,7 +1082,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op28GetResponse::Status200_OK => { + apis::default::Op28GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1125,7 +1114,7 @@ async fn op29_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op29_get_validation()) @@ -1145,7 +1134,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op29GetResponse::Status200_OK => { + apis::default::Op29GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1177,7 +1166,7 @@ async fn op2_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op2_get_validation()) @@ -1197,7 +1186,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op2GetResponse::Status200_OK => { + apis::default::Op2GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1229,7 +1218,7 @@ async fn op30_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op30_get_validation()) @@ -1249,7 +1238,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op30GetResponse::Status200_OK => { + apis::default::Op30GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1281,7 +1270,7 @@ async fn op31_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op31_get_validation()) @@ -1301,7 +1290,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op31GetResponse::Status200_OK => { + apis::default::Op31GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1333,7 +1322,7 @@ async fn op32_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op32_get_validation()) @@ -1353,7 +1342,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op32GetResponse::Status200_OK => { + apis::default::Op32GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1385,7 +1374,7 @@ async fn op33_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op33_get_validation()) @@ -1405,7 +1394,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op33GetResponse::Status200_OK => { + apis::default::Op33GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1437,7 +1426,7 @@ async fn op34_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op34_get_validation()) @@ -1457,7 +1446,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op34GetResponse::Status200_OK => { + apis::default::Op34GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1489,7 +1478,7 @@ async fn op35_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op35_get_validation()) @@ -1509,7 +1498,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op35GetResponse::Status200_OK => { + apis::default::Op35GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1541,7 +1530,7 @@ async fn op36_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op36_get_validation()) @@ -1561,7 +1550,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op36GetResponse::Status200_OK => { + apis::default::Op36GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1593,7 +1582,7 @@ async fn op37_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op37_get_validation()) @@ -1613,7 +1602,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op37GetResponse::Status200_OK => { + apis::default::Op37GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1645,7 +1634,7 @@ async fn op3_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op3_get_validation()) @@ -1665,7 +1654,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op3GetResponse::Status200_OK => { + apis::default::Op3GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1697,7 +1686,7 @@ async fn op4_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op4_get_validation()) @@ -1717,7 +1706,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op4GetResponse::Status200_OK => { + apis::default::Op4GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1749,7 +1738,7 @@ async fn op5_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op5_get_validation()) @@ -1769,7 +1758,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op5GetResponse::Status200_OK => { + apis::default::Op5GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1801,7 +1790,7 @@ async fn op6_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op6_get_validation()) @@ -1821,7 +1810,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op6GetResponse::Status200_OK => { + apis::default::Op6GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1853,7 +1842,7 @@ async fn op7_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op7_get_validation()) @@ -1873,7 +1862,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op7GetResponse::Status200_OK => { + apis::default::Op7GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1905,7 +1894,7 @@ async fn op8_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op8_get_validation()) @@ -1925,7 +1914,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op8GetResponse::Status200_OK => { + apis::default::Op8GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1957,7 +1946,7 @@ async fn op9_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || op9_get_validation()) @@ -1977,7 +1966,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Op9GetResponse::Status200_OK => { + apis::default::Op9GetResponse::Status200_OK => { let mut response = response.status(200); response.body(Body::empty()) } diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/.openapi-generator/FILES b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/.openapi-generator/FILES index ea1c5b8c5beb..c4774ff1a7cc 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/.openapi-generator/FILES +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/.openapi-generator/FILES @@ -1,6 +1,13 @@ .gitignore Cargo.toml README.md +src/apis/another_fake.rs +src/apis/fake.rs +src/apis/fake_classname_tags123.rs +src/apis/mod.rs +src/apis/pet.rs +src/apis/store.rs +src/apis/user.rs src/header.rs src/lib.rs src/models.rs diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/another_fake.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/another_fake.rs new file mode 100644 index 000000000000..99c6307abe80 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/another_fake.rs @@ -0,0 +1,32 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum TestSpecialTagsResponse { + /// successful operation + Status200_SuccessfulOperation(models::Client), +} + +/// AnotherFake +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait AnotherFake { + /// To test special tags. + /// + /// TestSpecialTags - PATCH /v2/another-fake/dummy + async fn test_special_tags( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Client, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake.rs new file mode 100644 index 000000000000..ffdd4cc759d5 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake.rs @@ -0,0 +1,237 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum Call123exampleResponse { + /// success + Status200_Success, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum FakeOuterBooleanSerializeResponse { + /// Output boolean + Status200_OutputBoolean(bool), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum FakeOuterCompositeSerializeResponse { + /// Output composite + Status200_OutputComposite(models::OuterComposite), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum FakeOuterNumberSerializeResponse { + /// Output number + Status200_OutputNumber(f64), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum FakeOuterStringSerializeResponse { + /// Output string + Status200_OutputString(String), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum FakeResponseWithNumericalDescriptionResponse { + /// 1234 + Status200, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum HyphenParamResponse { + /// Success + Status200_Success, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum TestBodyWithQueryParamsResponse { + /// Success + Status200_Success, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum TestClientModelResponse { + /// successful operation + Status200_SuccessfulOperation(models::Client), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum TestEndpointParametersResponse { + /// Invalid username supplied + Status400_InvalidUsernameSupplied, + /// User not found + Status404_UserNotFound, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum TestEnumParametersResponse { + /// Invalid request + Status400_InvalidRequest, + /// Not found + Status404_NotFound, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum TestInlineAdditionalPropertiesResponse { + /// successful operation + Status200_SuccessfulOperation, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum TestJsonFormDataResponse { + /// successful operation + Status200_SuccessfulOperation, +} + +/// Fake +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait Fake { + /// Call123example - GET /v2/fake/operation-with-numeric-id + async fn call123example( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// FakeOuterBooleanSerialize - POST /v2/fake/outer/boolean + async fn fake_outer_boolean_serialize( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Option, + ) -> Result; + /// FakeOuterCompositeSerialize - POST /v2/fake/outer/composite + async fn fake_outer_composite_serialize( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Option, + ) -> Result; + /// FakeOuterNumberSerialize - POST /v2/fake/outer/number + async fn fake_outer_number_serialize( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Option, + ) -> Result; + /// FakeOuterStringSerialize - POST /v2/fake/outer/string + async fn fake_outer_string_serialize( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Option, + ) -> Result; + /// FakeResponseWithNumericalDescription - GET /v2/fake/response-with-numerical-description + async fn fake_response_with_numerical_description( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// HyphenParam - GET /v2/fake/hyphenParam/{hyphen-param} + async fn hyphen_param( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::HyphenParamPathParams, + ) -> Result; + /// TestBodyWithQueryParams - PUT /v2/fake/body-with-query-params + async fn test_body_with_query_params( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::TestBodyWithQueryParamsQueryParams, + body: models::User, + ) -> Result; + /// To test \"client\" model. + /// + /// TestClientModel - PATCH /v2/fake + async fn test_client_model( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Client, + ) -> Result; + /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트. + /// + /// TestEndpointParameters - POST /v2/fake + async fn test_endpoint_parameters( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::TestEndpointParametersRequest, + ) -> Result; + /// To test enum parameters. + /// + /// TestEnumParameters - GET /v2/fake + async fn test_enum_parameters( + &self, + method: Method, + host: Host, + cookies: CookieJar, + header_params: models::TestEnumParametersHeaderParams, + query_params: models::TestEnumParametersQueryParams, + body: Option, + ) -> Result; + /// test inline additionalProperties. + /// + /// TestInlineAdditionalProperties - POST /v2/fake/inline-additionalProperties + async fn test_inline_additional_properties( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: std::collections::HashMap, + ) -> Result; + /// test json serialization of form data. + /// + /// TestJsonFormData - GET /v2/fake/jsonFormData + async fn test_json_form_data( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::TestJsonFormDataRequest, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake_classname_tags123.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake_classname_tags123.rs new file mode 100644 index 000000000000..dbc5f4b6184f --- /dev/null +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake_classname_tags123.rs @@ -0,0 +1,32 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum TestClassnameResponse { + /// successful operation + Status200_SuccessfulOperation(models::Client), +} + +/// FakeClassnameTags123 +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait FakeClassnameTags123 { + /// To test class name in snake case. + /// + /// TestClassname - PATCH /v2/fake_classname_test + async fn test_classname( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Client, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/mod.rs new file mode 100644 index 000000000000..fa714e56bee8 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/mod.rs @@ -0,0 +1,6 @@ +pub mod another_fake; +pub mod fake; +pub mod fake_classname_tags123; +pub mod pet; +pub mod store; +pub mod user; diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/pet.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/pet.rs new file mode 100644 index 000000000000..4e39af30849b --- /dev/null +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/pet.rs @@ -0,0 +1,173 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum AddPetResponse { + /// Invalid input + Status405_InvalidInput, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum DeletePetResponse { + /// Invalid pet value + Status400_InvalidPetValue, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum FindPetsByStatusResponse { + /// successful operation + Status200_SuccessfulOperation(String), + /// Invalid status value + Status400_InvalidStatusValue, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum FindPetsByTagsResponse { + /// successful operation + Status200_SuccessfulOperation(String), + /// Invalid tag value + Status400_InvalidTagValue, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum GetPetByIdResponse { + /// successful operation + Status200_SuccessfulOperation(String), + /// Invalid ID supplied + Status400_InvalidIDSupplied, + /// Pet not found + Status404_PetNotFound, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum UpdatePetResponse { + /// Invalid ID supplied + Status400_InvalidIDSupplied, + /// Pet not found + Status404_PetNotFound, + /// Validation exception + Status405_ValidationException, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum UpdatePetWithFormResponse { + /// Invalid input + Status405_InvalidInput, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum UploadFileResponse { + /// successful operation + Status200_SuccessfulOperation(models::ApiResponse), +} + +/// Pet +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait Pet { + /// Add a new pet to the store. + /// + /// AddPet - POST /v2/pet + async fn add_pet( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Pet, + ) -> Result; + /// Deletes a pet. + /// + /// DeletePet - DELETE /v2/pet/{petId} + async fn delete_pet( + &self, + method: Method, + host: Host, + cookies: CookieJar, + header_params: models::DeletePetHeaderParams, + path_params: models::DeletePetPathParams, + ) -> Result; + /// Finds Pets by status. + /// + /// FindPetsByStatus - GET /v2/pet/findByStatus + async fn find_pets_by_status( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::FindPetsByStatusQueryParams, + ) -> Result; + /// Finds Pets by tags. + /// + /// FindPetsByTags - GET /v2/pet/findByTags + async fn find_pets_by_tags( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::FindPetsByTagsQueryParams, + ) -> Result; + /// Find pet by ID. + /// + /// GetPetById - GET /v2/pet/{petId} + async fn get_pet_by_id( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::GetPetByIdPathParams, + ) -> Result; + /// Update an existing pet. + /// + /// UpdatePet - PUT /v2/pet + async fn update_pet( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Pet, + ) -> Result; + /// Updates a pet in the store with form data. + /// + /// UpdatePetWithForm - POST /v2/pet/{petId} + async fn update_pet_with_form( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::UpdatePetWithFormPathParams, + body: Option, + ) -> Result; + /// uploads an image. + /// + /// UploadFile - POST /v2/pet/{petId}/uploadImage + async fn upload_file( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::UploadFilePathParams, + body: Multipart, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/store.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/store.rs new file mode 100644 index 000000000000..d6d4eb6b6bd1 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/store.rs @@ -0,0 +1,93 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum DeleteOrderResponse { + /// Invalid ID supplied + Status400_InvalidIDSupplied, + /// Order not found + Status404_OrderNotFound, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum GetInventoryResponse { + /// successful operation + Status200_SuccessfulOperation(std::collections::HashMap), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum GetOrderByIdResponse { + /// successful operation + Status200_SuccessfulOperation(String), + /// Invalid ID supplied + Status400_InvalidIDSupplied, + /// Order not found + Status404_OrderNotFound, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum PlaceOrderResponse { + /// successful operation + Status200_SuccessfulOperation(String), + /// Invalid Order + Status400_InvalidOrder, +} + +/// Store +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait Store { + /// Delete purchase order by ID. + /// + /// DeleteOrder - DELETE /v2/store/order/{order_id} + async fn delete_order( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::DeleteOrderPathParams, + ) -> Result; + /// Returns pet inventories by status. + /// + /// GetInventory - GET /v2/store/inventory + async fn get_inventory( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Find purchase order by ID. + /// + /// GetOrderById - GET /v2/store/order/{order_id} + async fn get_order_by_id( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::GetOrderByIdPathParams, + ) -> Result; + /// Place an order for a pet. + /// + /// PlaceOrder - POST /v2/store/order + async fn place_order( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Order, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/user.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/user.rs new file mode 100644 index 000000000000..ee1a4dfe2604 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/user.rs @@ -0,0 +1,172 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum CreateUserResponse { + /// successful operation + Status0_SuccessfulOperation, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum CreateUsersWithArrayInputResponse { + /// successful operation + Status0_SuccessfulOperation, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum CreateUsersWithListInputResponse { + /// successful operation + Status0_SuccessfulOperation, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum DeleteUserResponse { + /// Invalid username supplied + Status400_InvalidUsernameSupplied, + /// User not found + Status404_UserNotFound, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum GetUserByNameResponse { + /// successful operation + Status200_SuccessfulOperation(String), + /// Invalid username supplied + Status400_InvalidUsernameSupplied, + /// User not found + Status404_UserNotFound, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum LoginUserResponse { + /// successful operation + Status200_SuccessfulOperation { + body: String, + x_rate_limit: Option, + x_expires_after: Option>, + }, + /// Invalid username/password supplied + Status400_InvalidUsername, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum LogoutUserResponse { + /// successful operation + Status0_SuccessfulOperation, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum UpdateUserResponse { + /// Invalid user supplied + Status400_InvalidUserSupplied, + /// User not found + Status404_UserNotFound, +} + +/// User +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait User { + /// Create user. + /// + /// CreateUser - POST /v2/user + async fn create_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::User, + ) -> Result; + /// Creates list of users with given input array. + /// + /// CreateUsersWithArrayInput - POST /v2/user/createWithArray + async fn create_users_with_array_input( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Vec, + ) -> Result; + /// Creates list of users with given input array. + /// + /// CreateUsersWithListInput - POST /v2/user/createWithList + async fn create_users_with_list_input( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Vec, + ) -> Result; + /// Delete user. + /// + /// DeleteUser - DELETE /v2/user/{username} + async fn delete_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::DeleteUserPathParams, + ) -> Result; + /// Get user by user name. + /// + /// GetUserByName - GET /v2/user/{username} + async fn get_user_by_name( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::GetUserByNamePathParams, + ) -> Result; + /// Logs user into the system. + /// + /// LoginUser - GET /v2/user/login + async fn login_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::LoginUserQueryParams, + ) -> Result; + /// Logs out current logged in user session. + /// + /// LogoutUser - GET /v2/user/logout + async fn logout_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Updated user. + /// + /// UpdateUser - PUT /v2/user/{username} + async fn update_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::UpdateUserPathParams, + body: models::User, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs index 4d017097f1ae..91d8f87a36a8 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs @@ -8,718 +8,19 @@ unused_imports, unused_attributes )] -#![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)] - -use async_trait::async_trait; -use axum::extract::*; -use axum_extra::extract::{CookieJar, Multipart}; -use bytes::Bytes; -use http::Method; -use serde::{Deserialize, Serialize}; - -use types::*; +#![allow( + clippy::derive_partial_eq_without_eq, + clippy::disallowed_names, + clippy::too_many_arguments +)] pub const BASE_PATH: &str = "/v2"; pub const API_VERSION: &str = "1.0.0"; -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum TestSpecialTagsResponse { - /// successful operation - Status200_SuccessfulOperation(models::Client), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum Call123exampleResponse { - /// success - Status200_Success, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum FakeOuterBooleanSerializeResponse { - /// Output boolean - Status200_OutputBoolean(bool), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum FakeOuterCompositeSerializeResponse { - /// Output composite - Status200_OutputComposite(models::OuterComposite), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum FakeOuterNumberSerializeResponse { - /// Output number - Status200_OutputNumber(f64), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum FakeOuterStringSerializeResponse { - /// Output string - Status200_OutputString(String), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum FakeResponseWithNumericalDescriptionResponse { - /// 1234 - Status200, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum HyphenParamResponse { - /// Success - Status200_Success, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum TestBodyWithQueryParamsResponse { - /// Success - Status200_Success, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum TestClientModelResponse { - /// successful operation - Status200_SuccessfulOperation(models::Client), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum TestEndpointParametersResponse { - /// Invalid username supplied - Status400_InvalidUsernameSupplied, - /// User not found - Status404_UserNotFound, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum TestEnumParametersResponse { - /// Invalid request - Status400_InvalidRequest, - /// Not found - Status404_NotFound, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum TestInlineAdditionalPropertiesResponse { - /// successful operation - Status200_SuccessfulOperation, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum TestJsonFormDataResponse { - /// successful operation - Status200_SuccessfulOperation, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum TestClassnameResponse { - /// successful operation - Status200_SuccessfulOperation(models::Client), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum AddPetResponse { - /// Invalid input - Status405_InvalidInput, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum DeletePetResponse { - /// Invalid pet value - Status400_InvalidPetValue, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum FindPetsByStatusResponse { - /// successful operation - Status200_SuccessfulOperation(String), - /// Invalid status value - Status400_InvalidStatusValue, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum FindPetsByTagsResponse { - /// successful operation - Status200_SuccessfulOperation(String), - /// Invalid tag value - Status400_InvalidTagValue, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum GetPetByIdResponse { - /// successful operation - Status200_SuccessfulOperation(String), - /// Invalid ID supplied - Status400_InvalidIDSupplied, - /// Pet not found - Status404_PetNotFound, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum UpdatePetResponse { - /// Invalid ID supplied - Status400_InvalidIDSupplied, - /// Pet not found - Status404_PetNotFound, - /// Validation exception - Status405_ValidationException, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum UpdatePetWithFormResponse { - /// Invalid input - Status405_InvalidInput, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum UploadFileResponse { - /// successful operation - Status200_SuccessfulOperation(models::ApiResponse), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum DeleteOrderResponse { - /// Invalid ID supplied - Status400_InvalidIDSupplied, - /// Order not found - Status404_OrderNotFound, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum GetInventoryResponse { - /// successful operation - Status200_SuccessfulOperation(std::collections::HashMap), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum GetOrderByIdResponse { - /// successful operation - Status200_SuccessfulOperation(String), - /// Invalid ID supplied - Status400_InvalidIDSupplied, - /// Order not found - Status404_OrderNotFound, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum PlaceOrderResponse { - /// successful operation - Status200_SuccessfulOperation(String), - /// Invalid Order - Status400_InvalidOrder, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum CreateUserResponse { - /// successful operation - Status0_SuccessfulOperation, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum CreateUsersWithArrayInputResponse { - /// successful operation - Status0_SuccessfulOperation, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum CreateUsersWithListInputResponse { - /// successful operation - Status0_SuccessfulOperation, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum DeleteUserResponse { - /// Invalid username supplied - Status400_InvalidUsernameSupplied, - /// User not found - Status404_UserNotFound, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum GetUserByNameResponse { - /// successful operation - Status200_SuccessfulOperation(String), - /// Invalid username supplied - Status400_InvalidUsernameSupplied, - /// User not found - Status404_UserNotFound, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum LoginUserResponse { - /// successful operation - Status200_SuccessfulOperation { - body: String, - x_rate_limit: Option, - x_expires_after: Option>, - }, - /// Invalid username/password supplied - Status400_InvalidUsername, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum LogoutUserResponse { - /// successful operation - Status0_SuccessfulOperation, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum UpdateUserResponse { - /// Invalid user supplied - Status400_InvalidUserSupplied, - /// User not found - Status404_UserNotFound, -} - -/// API -#[async_trait] -#[allow(clippy::ptr_arg)] -pub trait Api { - /// To test special tags. - /// - /// TestSpecialTags - PATCH /v2/another-fake/dummy - async fn test_special_tags( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Client, - ) -> Result; - - /// Call123example - GET /v2/fake/operation-with-numeric-id - async fn call123example( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// FakeOuterBooleanSerialize - POST /v2/fake/outer/boolean - async fn fake_outer_boolean_serialize( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Option, - ) -> Result; - - /// FakeOuterCompositeSerialize - POST /v2/fake/outer/composite - async fn fake_outer_composite_serialize( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Option, - ) -> Result; - - /// FakeOuterNumberSerialize - POST /v2/fake/outer/number - async fn fake_outer_number_serialize( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Option, - ) -> Result; - - /// FakeOuterStringSerialize - POST /v2/fake/outer/string - async fn fake_outer_string_serialize( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Option, - ) -> Result; - - /// FakeResponseWithNumericalDescription - GET /v2/fake/response-with-numerical-description - async fn fake_response_with_numerical_description( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// HyphenParam - GET /v2/fake/hyphenParam/{hyphen-param} - async fn hyphen_param( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::HyphenParamPathParams, - ) -> Result; - - /// TestBodyWithQueryParams - PUT /v2/fake/body-with-query-params - async fn test_body_with_query_params( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::TestBodyWithQueryParamsQueryParams, - body: models::User, - ) -> Result; - - /// To test \"client\" model. - /// - /// TestClientModel - PATCH /v2/fake - async fn test_client_model( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Client, - ) -> Result; - - /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트. - /// - /// TestEndpointParameters - POST /v2/fake - async fn test_endpoint_parameters( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::TestEndpointParametersRequest, - ) -> Result; - - /// To test enum parameters. - /// - /// TestEnumParameters - GET /v2/fake - async fn test_enum_parameters( - &self, - method: Method, - host: Host, - cookies: CookieJar, - header_params: models::TestEnumParametersHeaderParams, - query_params: models::TestEnumParametersQueryParams, - body: Option, - ) -> Result; - - /// test inline additionalProperties. - /// - /// TestInlineAdditionalProperties - POST /v2/fake/inline-additionalProperties - async fn test_inline_additional_properties( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: std::collections::HashMap, - ) -> Result; - - /// test json serialization of form data. - /// - /// TestJsonFormData - GET /v2/fake/jsonFormData - async fn test_json_form_data( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::TestJsonFormDataRequest, - ) -> Result; - - /// To test class name in snake case. - /// - /// TestClassname - PATCH /v2/fake_classname_test - async fn test_classname( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Client, - ) -> Result; - - /// Add a new pet to the store. - /// - /// AddPet - POST /v2/pet - async fn add_pet( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Pet, - ) -> Result; - - /// Deletes a pet. - /// - /// DeletePet - DELETE /v2/pet/{petId} - async fn delete_pet( - &self, - method: Method, - host: Host, - cookies: CookieJar, - header_params: models::DeletePetHeaderParams, - path_params: models::DeletePetPathParams, - ) -> Result; - - /// Finds Pets by status. - /// - /// FindPetsByStatus - GET /v2/pet/findByStatus - async fn find_pets_by_status( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::FindPetsByStatusQueryParams, - ) -> Result; - - /// Finds Pets by tags. - /// - /// FindPetsByTags - GET /v2/pet/findByTags - async fn find_pets_by_tags( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::FindPetsByTagsQueryParams, - ) -> Result; - - /// Find pet by ID. - /// - /// GetPetById - GET /v2/pet/{petId} - async fn get_pet_by_id( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetPetByIdPathParams, - ) -> Result; - - /// Update an existing pet. - /// - /// UpdatePet - PUT /v2/pet - async fn update_pet( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Pet, - ) -> Result; - - /// Updates a pet in the store with form data. - /// - /// UpdatePetWithForm - POST /v2/pet/{petId} - async fn update_pet_with_form( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UpdatePetWithFormPathParams, - body: Option, - ) -> Result; - - /// uploads an image. - /// - /// UploadFile - POST /v2/pet/{petId}/uploadImage - async fn upload_file( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UploadFilePathParams, - body: Multipart, - ) -> Result; - - /// Delete purchase order by ID. - /// - /// DeleteOrder - DELETE /v2/store/order/{order_id} - async fn delete_order( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::DeleteOrderPathParams, - ) -> Result; - - /// Returns pet inventories by status. - /// - /// GetInventory - GET /v2/store/inventory - async fn get_inventory( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Find purchase order by ID. - /// - /// GetOrderById - GET /v2/store/order/{order_id} - async fn get_order_by_id( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetOrderByIdPathParams, - ) -> Result; - - /// Place an order for a pet. - /// - /// PlaceOrder - POST /v2/store/order - async fn place_order( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Order, - ) -> Result; - - /// Create user. - /// - /// CreateUser - POST /v2/user - async fn create_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::User, - ) -> Result; - - /// Creates list of users with given input array. - /// - /// CreateUsersWithArrayInput - POST /v2/user/createWithArray - async fn create_users_with_array_input( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Vec, - ) -> Result; - - /// Creates list of users with given input array. - /// - /// CreateUsersWithListInput - POST /v2/user/createWithList - async fn create_users_with_list_input( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Vec, - ) -> Result; - - /// Delete user. - /// - /// DeleteUser - DELETE /v2/user/{username} - async fn delete_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::DeleteUserPathParams, - ) -> Result; - - /// Get user by user name. - /// - /// GetUserByName - GET /v2/user/{username} - async fn get_user_by_name( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetUserByNamePathParams, - ) -> Result; - - /// Logs user into the system. - /// - /// LoginUser - GET /v2/user/login - async fn login_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::LoginUserQueryParams, - ) -> Result; - - /// Logs out current logged in user session. - /// - /// LogoutUser - GET /v2/user/logout - async fn logout_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Updated user. - /// - /// UpdateUser - PUT /v2/user/{username} - async fn update_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UpdateUserPathParams, - body: models::User, - ) -> Result; -} - #[cfg(feature = "server")] pub mod server; +pub mod apis; pub mod models; pub mod types; diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs index e566756227e4..281996e15e3e 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs @@ -10,27 +10,19 @@ use validator::{Validate, ValidationErrors}; use crate::{header, types::*}; #[allow(unused_imports)] -use crate::models; - -use crate::{ - AddPetResponse, Api, Call123exampleResponse, CreateUserResponse, - CreateUsersWithArrayInputResponse, CreateUsersWithListInputResponse, DeleteOrderResponse, - DeletePetResponse, DeleteUserResponse, FakeOuterBooleanSerializeResponse, - FakeOuterCompositeSerializeResponse, FakeOuterNumberSerializeResponse, - FakeOuterStringSerializeResponse, FakeResponseWithNumericalDescriptionResponse, - FindPetsByStatusResponse, FindPetsByTagsResponse, GetInventoryResponse, GetOrderByIdResponse, - GetPetByIdResponse, GetUserByNameResponse, HyphenParamResponse, LoginUserResponse, - LogoutUserResponse, PlaceOrderResponse, TestBodyWithQueryParamsResponse, TestClassnameResponse, - TestClientModelResponse, TestEndpointParametersResponse, TestEnumParametersResponse, - TestInlineAdditionalPropertiesResponse, TestJsonFormDataResponse, TestSpecialTagsResponse, - UpdatePetResponse, UpdatePetWithFormResponse, UpdateUserResponse, UploadFileResponse, -}; +use crate::{apis, models}; /// Setup API Server. pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: Api + 'static, + A: apis::another_fake::AnotherFake + + apis::fake::Fake + + apis::fake_classname_tags123::FakeClassnameTags123 + + apis::pet::Pet + + apis::store::Store + + apis::user::User + + 'static, { // build our application with a route Router::new() @@ -142,7 +134,7 @@ async fn test_special_tags( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::another_fake::AnotherFake, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || test_special_tags_validation(body)) @@ -165,7 +157,7 @@ where let resp = match result { Ok(rsp) => match rsp { - TestSpecialTagsResponse::Status200_SuccessfulOperation(body) => { + apis::another_fake::TestSpecialTagsResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -216,7 +208,7 @@ async fn call123example( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::fake::Fake, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || call123example_validation()) @@ -239,7 +231,7 @@ where let resp = match result { Ok(rsp) => match rsp { - Call123exampleResponse::Status200_Success => { + apis::fake::Call123exampleResponse::Status200_Success => { let mut response = response.status(200); response.body(Body::empty()) } @@ -286,7 +278,7 @@ async fn fake_outer_boolean_serialize( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::fake::Fake, { #[allow(clippy::redundant_closure)] let validation = @@ -310,7 +302,7 @@ where let resp = match result { Ok(rsp) => match rsp { - FakeOuterBooleanSerializeResponse::Status200_OutputBoolean(body) => { + apis::fake::FakeOuterBooleanSerializeResponse::Status200_OutputBoolean(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -376,7 +368,7 @@ async fn fake_outer_composite_serialize( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::fake::Fake, { #[allow(clippy::redundant_closure)] let validation = @@ -400,7 +392,7 @@ where let resp = match result { Ok(rsp) => match rsp { - FakeOuterCompositeSerializeResponse::Status200_OutputComposite(body) => { + apis::fake::FakeOuterCompositeSerializeResponse::Status200_OutputComposite(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -466,7 +458,7 @@ async fn fake_outer_number_serialize( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::fake::Fake, { #[allow(clippy::redundant_closure)] let validation = @@ -490,7 +482,7 @@ where let resp = match result { Ok(rsp) => match rsp { - FakeOuterNumberSerializeResponse::Status200_OutputNumber(body) => { + apis::fake::FakeOuterNumberSerializeResponse::Status200_OutputNumber(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -556,7 +548,7 @@ async fn fake_outer_string_serialize( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::fake::Fake, { #[allow(clippy::redundant_closure)] let validation = @@ -580,7 +572,7 @@ where let resp = match result { Ok(rsp) => match rsp { - FakeOuterStringSerializeResponse::Status200_OutputString(body) => { + apis::fake::FakeOuterStringSerializeResponse::Status200_OutputString(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -632,7 +624,7 @@ async fn fake_response_with_numerical_description( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::fake::Fake, { #[allow(clippy::redundant_closure)] let validation = @@ -656,7 +648,7 @@ where let resp = match result { Ok(rsp) => match rsp { - FakeResponseWithNumericalDescriptionResponse::Status200 => { + apis::fake::FakeResponseWithNumericalDescriptionResponse::Status200 => { let mut response = response.status(200); response.body(Body::empty()) } @@ -693,7 +685,7 @@ async fn hyphen_param( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::fake::Fake, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || hyphen_param_validation(path_params)) @@ -716,7 +708,7 @@ where let resp = match result { Ok(rsp) => match rsp { - HyphenParamResponse::Status200_Success => { + apis::fake::HyphenParamResponse::Status200_Success => { let mut response = response.status(200); response.body(Body::empty()) } @@ -765,7 +757,7 @@ async fn test_body_with_query_params( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::fake::Fake, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || { @@ -790,7 +782,7 @@ where let resp = match result { Ok(rsp) => match rsp { - TestBodyWithQueryParamsResponse::Status200_Success => { + apis::fake::TestBodyWithQueryParamsResponse::Status200_Success => { let mut response = response.status(200); response.body(Body::empty()) } @@ -835,7 +827,7 @@ async fn test_client_model( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::fake::Fake, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || test_client_model_validation(body)) @@ -858,7 +850,7 @@ where let resp = match result { Ok(rsp) => match rsp { - TestClientModelResponse::Status200_SuccessfulOperation(body) => { + apis::fake::TestClientModelResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -922,7 +914,7 @@ async fn test_endpoint_parameters( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::fake::Fake, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || test_endpoint_parameters_validation(body)) @@ -945,11 +937,11 @@ where let resp = match result { Ok(rsp) => match rsp { - TestEndpointParametersResponse::Status400_InvalidUsernameSupplied => { + apis::fake::TestEndpointParametersResponse::Status400_InvalidUsernameSupplied => { let mut response = response.status(400); response.body(Body::empty()) } - TestEndpointParametersResponse::Status404_UserNotFound => { + apis::fake::TestEndpointParametersResponse::Status404_UserNotFound => { let mut response = response.status(404); response.body(Body::empty()) } @@ -1009,7 +1001,7 @@ async fn test_enum_parameters( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::fake::Fake, { // Header parameters let header_params = { @@ -1084,11 +1076,11 @@ where let resp = match result { Ok(rsp) => match rsp { - TestEnumParametersResponse::Status400_InvalidRequest => { + apis::fake::TestEnumParametersResponse::Status400_InvalidRequest => { let mut response = response.status(400); response.body(Body::empty()) } - TestEnumParametersResponse::Status404_NotFound => { + apis::fake::TestEnumParametersResponse::Status404_NotFound => { let mut response = response.status(404); response.body(Body::empty()) } @@ -1132,7 +1124,7 @@ async fn test_inline_additional_properties( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::fake::Fake, { #[allow(clippy::redundant_closure)] let validation = @@ -1156,7 +1148,7 @@ where let resp = match result { Ok(rsp) => match rsp { - TestInlineAdditionalPropertiesResponse::Status200_SuccessfulOperation => { + apis::fake::TestInlineAdditionalPropertiesResponse::Status200_SuccessfulOperation => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1201,7 +1193,7 @@ async fn test_json_form_data( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::fake::Fake, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || test_json_form_data_validation(body)) @@ -1224,7 +1216,7 @@ where let resp = match result { Ok(rsp) => match rsp { - TestJsonFormDataResponse::Status200_SuccessfulOperation => { + apis::fake::TestJsonFormDataResponse::Status200_SuccessfulOperation => { let mut response = response.status(200); response.body(Body::empty()) } @@ -1269,7 +1261,7 @@ async fn test_classname( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::fake_classname_tags123::FakeClassnameTags123, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || test_classname_validation(body)) @@ -1292,7 +1284,9 @@ where let resp = match result { Ok(rsp) => match rsp { - TestClassnameResponse::Status200_SuccessfulOperation(body) => { + apis::fake_classname_tags123::TestClassnameResponse::Status200_SuccessfulOperation( + body, + ) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -1354,7 +1348,7 @@ async fn add_pet( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::pet::Pet, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || add_pet_validation(body)) @@ -1374,7 +1368,7 @@ where let resp = match result { Ok(rsp) => match rsp { - AddPetResponse::Status405_InvalidInput => { + apis::pet::AddPetResponse::Status405_InvalidInput => { let mut response = response.status(405); response.body(Body::empty()) } @@ -1417,7 +1411,7 @@ async fn delete_pet( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::pet::Pet, { // Header parameters let header_params = { @@ -1466,7 +1460,7 @@ where let resp = match result { Ok(rsp) => match rsp { - DeletePetResponse::Status400_InvalidPetValue => { + apis::pet::DeletePetResponse::Status400_InvalidPetValue => { let mut response = response.status(400); response.body(Body::empty()) } @@ -1503,7 +1497,7 @@ async fn find_pets_by_status( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::pet::Pet, { #[allow(clippy::redundant_closure)] let validation = @@ -1527,7 +1521,7 @@ where let resp = match result { Ok(rsp) => match rsp { - FindPetsByStatusResponse::Status200_SuccessfulOperation(body) => { + apis::pet::FindPetsByStatusResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -1543,7 +1537,7 @@ where let body_content = body; response.body(Body::from(body_content)) } - FindPetsByStatusResponse::Status400_InvalidStatusValue => { + apis::pet::FindPetsByStatusResponse::Status400_InvalidStatusValue => { let mut response = response.status(400); response.body(Body::empty()) } @@ -1580,7 +1574,7 @@ async fn find_pets_by_tags( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::pet::Pet, { #[allow(clippy::redundant_closure)] let validation = @@ -1604,7 +1598,7 @@ where let resp = match result { Ok(rsp) => match rsp { - FindPetsByTagsResponse::Status200_SuccessfulOperation(body) => { + apis::pet::FindPetsByTagsResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -1620,7 +1614,7 @@ where let body_content = body; response.body(Body::from(body_content)) } - FindPetsByTagsResponse::Status400_InvalidTagValue => { + apis::pet::FindPetsByTagsResponse::Status400_InvalidTagValue => { let mut response = response.status(400); response.body(Body::empty()) } @@ -1657,7 +1651,7 @@ async fn get_pet_by_id( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::pet::Pet, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || get_pet_by_id_validation(path_params)) @@ -1680,7 +1674,7 @@ where let resp = match result { Ok(rsp) => match rsp { - GetPetByIdResponse::Status200_SuccessfulOperation(body) => { + apis::pet::GetPetByIdResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -1696,11 +1690,11 @@ where let body_content = body; response.body(Body::from(body_content)) } - GetPetByIdResponse::Status400_InvalidIDSupplied => { + apis::pet::GetPetByIdResponse::Status400_InvalidIDSupplied => { let mut response = response.status(400); response.body(Body::empty()) } - GetPetByIdResponse::Status404_PetNotFound => { + apis::pet::GetPetByIdResponse::Status404_PetNotFound => { let mut response = response.status(404); response.body(Body::empty()) } @@ -1745,7 +1739,7 @@ async fn update_pet( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::pet::Pet, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || update_pet_validation(body)) @@ -1768,15 +1762,15 @@ where let resp = match result { Ok(rsp) => match rsp { - UpdatePetResponse::Status400_InvalidIDSupplied => { + apis::pet::UpdatePetResponse::Status400_InvalidIDSupplied => { let mut response = response.status(400); response.body(Body::empty()) } - UpdatePetResponse::Status404_PetNotFound => { + apis::pet::UpdatePetResponse::Status404_PetNotFound => { let mut response = response.status(404); response.body(Body::empty()) } - UpdatePetResponse::Status405_ValidationException => { + apis::pet::UpdatePetResponse::Status405_ValidationException => { let mut response = response.status(405); response.body(Body::empty()) } @@ -1832,7 +1826,7 @@ async fn update_pet_with_form( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::pet::Pet, { #[allow(clippy::redundant_closure)] let validation = @@ -1856,7 +1850,7 @@ where let resp = match result { Ok(rsp) => match rsp { - UpdatePetWithFormResponse::Status405_InvalidInput => { + apis::pet::UpdatePetWithFormResponse::Status405_InvalidInput => { let mut response = response.status(405); response.body(Body::empty()) } @@ -1894,7 +1888,7 @@ async fn upload_file( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::pet::Pet, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || upload_file_validation(path_params)) @@ -1917,7 +1911,7 @@ where let resp = match result { Ok(rsp) => match rsp { - UploadFileResponse::Status200_SuccessfulOperation(body) => { + apis::pet::UploadFileResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -1973,7 +1967,7 @@ async fn delete_order( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::store::Store, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || delete_order_validation(path_params)) @@ -1996,11 +1990,11 @@ where let resp = match result { Ok(rsp) => match rsp { - DeleteOrderResponse::Status400_InvalidIDSupplied => { + apis::store::DeleteOrderResponse::Status400_InvalidIDSupplied => { let mut response = response.status(400); response.body(Body::empty()) } - DeleteOrderResponse::Status404_OrderNotFound => { + apis::store::DeleteOrderResponse::Status404_OrderNotFound => { let mut response = response.status(404); response.body(Body::empty()) } @@ -2032,7 +2026,7 @@ async fn get_inventory( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::store::Store, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || get_inventory_validation()) @@ -2052,7 +2046,7 @@ where let resp = match result { Ok(rsp) => match rsp { - GetInventoryResponse::Status200_SuccessfulOperation(body) => { + apis::store::GetInventoryResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -2108,7 +2102,7 @@ async fn get_order_by_id( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::store::Store, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || get_order_by_id_validation(path_params)) @@ -2131,7 +2125,7 @@ where let resp = match result { Ok(rsp) => match rsp { - GetOrderByIdResponse::Status200_SuccessfulOperation(body) => { + apis::store::GetOrderByIdResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -2147,11 +2141,11 @@ where let body_content = body; response.body(Body::from(body_content)) } - GetOrderByIdResponse::Status400_InvalidIDSupplied => { + apis::store::GetOrderByIdResponse::Status400_InvalidIDSupplied => { let mut response = response.status(400); response.body(Body::empty()) } - GetOrderByIdResponse::Status404_OrderNotFound => { + apis::store::GetOrderByIdResponse::Status404_OrderNotFound => { let mut response = response.status(404); response.body(Body::empty()) } @@ -2196,7 +2190,7 @@ async fn place_order( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::store::Store, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || place_order_validation(body)) @@ -2219,7 +2213,7 @@ where let resp = match result { Ok(rsp) => match rsp { - PlaceOrderResponse::Status200_SuccessfulOperation(body) => { + apis::store::PlaceOrderResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -2235,7 +2229,7 @@ where let body_content = body; response.body(Body::from(body_content)) } - PlaceOrderResponse::Status400_InvalidOrder => { + apis::store::PlaceOrderResponse::Status400_InvalidOrder => { let mut response = response.status(400); response.body(Body::empty()) } @@ -2280,7 +2274,7 @@ async fn create_user( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::user::User, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || create_user_validation(body)) @@ -2303,7 +2297,7 @@ where let resp = match result { Ok(rsp) => match rsp { - CreateUserResponse::Status0_SuccessfulOperation => { + apis::user::CreateUserResponse::Status0_SuccessfulOperation => { let mut response = response.status(0); response.body(Body::empty()) } @@ -2348,7 +2342,7 @@ async fn create_users_with_array_input( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::user::User, { #[allow(clippy::redundant_closure)] let validation = @@ -2372,7 +2366,7 @@ where let resp = match result { Ok(rsp) => match rsp { - CreateUsersWithArrayInputResponse::Status0_SuccessfulOperation => { + apis::user::CreateUsersWithArrayInputResponse::Status0_SuccessfulOperation => { let mut response = response.status(0); response.body(Body::empty()) } @@ -2417,7 +2411,7 @@ async fn create_users_with_list_input( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::user::User, { #[allow(clippy::redundant_closure)] let validation = @@ -2441,7 +2435,7 @@ where let resp = match result { Ok(rsp) => match rsp { - CreateUsersWithListInputResponse::Status0_SuccessfulOperation => { + apis::user::CreateUsersWithListInputResponse::Status0_SuccessfulOperation => { let mut response = response.status(0); response.body(Body::empty()) } @@ -2478,7 +2472,7 @@ async fn delete_user( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::user::User, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || delete_user_validation(path_params)) @@ -2501,11 +2495,11 @@ where let resp = match result { Ok(rsp) => match rsp { - DeleteUserResponse::Status400_InvalidUsernameSupplied => { + apis::user::DeleteUserResponse::Status400_InvalidUsernameSupplied => { let mut response = response.status(400); response.body(Body::empty()) } - DeleteUserResponse::Status404_UserNotFound => { + apis::user::DeleteUserResponse::Status404_UserNotFound => { let mut response = response.status(404); response.body(Body::empty()) } @@ -2542,7 +2536,7 @@ async fn get_user_by_name( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::user::User, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || get_user_by_name_validation(path_params)) @@ -2565,7 +2559,7 @@ where let resp = match result { Ok(rsp) => match rsp { - GetUserByNameResponse::Status200_SuccessfulOperation(body) => { + apis::user::GetUserByNameResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -2581,11 +2575,11 @@ where let body_content = body; response.body(Body::from(body_content)) } - GetUserByNameResponse::Status400_InvalidUsernameSupplied => { + apis::user::GetUserByNameResponse::Status400_InvalidUsernameSupplied => { let mut response = response.status(400); response.body(Body::empty()) } - GetUserByNameResponse::Status404_UserNotFound => { + apis::user::GetUserByNameResponse::Status404_UserNotFound => { let mut response = response.status(404); response.body(Body::empty()) } @@ -2622,7 +2616,7 @@ async fn login_user( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::user::User, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || login_user_validation(query_params)) @@ -2645,7 +2639,7 @@ where let resp = match result { Ok(rsp) => match rsp { - LoginUserResponse::Status200_SuccessfulOperation { + apis::user::LoginUserResponse::Status200_SuccessfulOperation { body, x_rate_limit, x_expires_after, @@ -2697,7 +2691,7 @@ where let body_content = body; response.body(Body::from(body_content)) } - LoginUserResponse::Status400_InvalidUsername => { + apis::user::LoginUserResponse::Status400_InvalidUsername => { let mut response = response.status(400); response.body(Body::empty()) } @@ -2729,7 +2723,7 @@ async fn logout_user( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::user::User, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || logout_user_validation()) @@ -2749,7 +2743,7 @@ where let resp = match result { Ok(rsp) => match rsp { - LogoutUserResponse::Status0_SuccessfulOperation => { + apis::user::LogoutUserResponse::Status0_SuccessfulOperation => { let mut response = response.status(0); response.body(Body::empty()) } @@ -2797,7 +2791,7 @@ async fn update_user( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::user::User, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || update_user_validation(path_params, body)) @@ -2820,11 +2814,11 @@ where let resp = match result { Ok(rsp) => match rsp { - UpdateUserResponse::Status400_InvalidUserSupplied => { + apis::user::UpdateUserResponse::Status400_InvalidUserSupplied => { let mut response = response.status(400); response.body(Body::empty()) } - UpdateUserResponse::Status404_UserNotFound => { + apis::user::UpdateUserResponse::Status404_UserNotFound => { let mut response = response.status(404); response.body(Body::empty()) } diff --git a/samples/server/petstore/rust-axum/output/petstore/.openapi-generator/FILES b/samples/server/petstore/rust-axum/output/petstore/.openapi-generator/FILES index ea1c5b8c5beb..2520d7516ecb 100644 --- a/samples/server/petstore/rust-axum/output/petstore/.openapi-generator/FILES +++ b/samples/server/petstore/rust-axum/output/petstore/.openapi-generator/FILES @@ -1,6 +1,10 @@ .gitignore Cargo.toml README.md +src/apis/mod.rs +src/apis/pet.rs +src/apis/store.rs +src/apis/user.rs src/header.rs src/lib.rs src/models.rs diff --git a/samples/server/petstore/rust-axum/output/petstore/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/petstore/src/apis/mod.rs new file mode 100644 index 000000000000..cdc670909a4d --- /dev/null +++ b/samples/server/petstore/rust-axum/output/petstore/src/apis/mod.rs @@ -0,0 +1,3 @@ +pub mod pet; +pub mod store; +pub mod user; diff --git a/samples/server/petstore/rust-axum/output/petstore/src/apis/pet.rs b/samples/server/petstore/rust-axum/output/petstore/src/apis/pet.rs new file mode 100644 index 000000000000..ba8f3059dbac --- /dev/null +++ b/samples/server/petstore/rust-axum/output/petstore/src/apis/pet.rs @@ -0,0 +1,177 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum AddPetResponse { + /// successful operation + Status200_SuccessfulOperation(String), + /// Invalid input + Status405_InvalidInput, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum DeletePetResponse { + /// Invalid pet value + Status400_InvalidPetValue, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum FindPetsByStatusResponse { + /// successful operation + Status200_SuccessfulOperation(String), + /// Invalid status value + Status400_InvalidStatusValue, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum FindPetsByTagsResponse { + /// successful operation + Status200_SuccessfulOperation(String), + /// Invalid tag value + Status400_InvalidTagValue, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum GetPetByIdResponse { + /// successful operation + Status200_SuccessfulOperation(String), + /// Invalid ID supplied + Status400_InvalidIDSupplied, + /// Pet not found + Status404_PetNotFound, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum UpdatePetResponse { + /// successful operation + Status200_SuccessfulOperation(String), + /// Invalid ID supplied + Status400_InvalidIDSupplied, + /// Pet not found + Status404_PetNotFound, + /// Validation exception + Status405_ValidationException, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum UpdatePetWithFormResponse { + /// Invalid input + Status405_InvalidInput, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum UploadFileResponse { + /// successful operation + Status200_SuccessfulOperation(models::ApiResponse), +} + +/// Pet +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait Pet { + /// Add a new pet to the store. + /// + /// AddPet - POST /v2/pet + async fn add_pet( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Pet, + ) -> Result; + /// Deletes a pet. + /// + /// DeletePet - DELETE /v2/pet/{petId} + async fn delete_pet( + &self, + method: Method, + host: Host, + cookies: CookieJar, + header_params: models::DeletePetHeaderParams, + path_params: models::DeletePetPathParams, + ) -> Result; + /// Finds Pets by status. + /// + /// FindPetsByStatus - GET /v2/pet/findByStatus + async fn find_pets_by_status( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::FindPetsByStatusQueryParams, + ) -> Result; + /// Finds Pets by tags. + /// + /// FindPetsByTags - GET /v2/pet/findByTags + async fn find_pets_by_tags( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::FindPetsByTagsQueryParams, + ) -> Result; + /// Find pet by ID. + /// + /// GetPetById - GET /v2/pet/{petId} + async fn get_pet_by_id( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::GetPetByIdPathParams, + ) -> Result; + /// Update an existing pet. + /// + /// UpdatePet - PUT /v2/pet + async fn update_pet( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Pet, + ) -> Result; + /// Updates a pet in the store with form data. + /// + /// UpdatePetWithForm - POST /v2/pet/{petId} + async fn update_pet_with_form( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::UpdatePetWithFormPathParams, + body: Option, + ) -> Result; + /// uploads an image. + /// + /// UploadFile - POST /v2/pet/{petId}/uploadImage + async fn upload_file( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::UploadFilePathParams, + body: Multipart, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/petstore/src/apis/store.rs b/samples/server/petstore/rust-axum/output/petstore/src/apis/store.rs new file mode 100644 index 000000000000..77c83f31a3a3 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/petstore/src/apis/store.rs @@ -0,0 +1,93 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum DeleteOrderResponse { + /// Invalid ID supplied + Status400_InvalidIDSupplied, + /// Order not found + Status404_OrderNotFound, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum GetInventoryResponse { + /// successful operation + Status200_SuccessfulOperation(std::collections::HashMap), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum GetOrderByIdResponse { + /// successful operation + Status200_SuccessfulOperation(String), + /// Invalid ID supplied + Status400_InvalidIDSupplied, + /// Order not found + Status404_OrderNotFound, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum PlaceOrderResponse { + /// successful operation + Status200_SuccessfulOperation(String), + /// Invalid Order + Status400_InvalidOrder, +} + +/// Store +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait Store { + /// Delete purchase order by ID. + /// + /// DeleteOrder - DELETE /v2/store/order/{orderId} + async fn delete_order( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::DeleteOrderPathParams, + ) -> Result; + /// Returns pet inventories by status. + /// + /// GetInventory - GET /v2/store/inventory + async fn get_inventory( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Find purchase order by ID. + /// + /// GetOrderById - GET /v2/store/order/{orderId} + async fn get_order_by_id( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::GetOrderByIdPathParams, + ) -> Result; + /// Place an order for a pet. + /// + /// PlaceOrder - POST /v2/store/order + async fn place_order( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Order, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/petstore/src/apis/user.rs b/samples/server/petstore/rust-axum/output/petstore/src/apis/user.rs new file mode 100644 index 000000000000..118a72d4f21b --- /dev/null +++ b/samples/server/petstore/rust-axum/output/petstore/src/apis/user.rs @@ -0,0 +1,173 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum CreateUserResponse { + /// successful operation + Status0_SuccessfulOperation, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum CreateUsersWithArrayInputResponse { + /// successful operation + Status0_SuccessfulOperation, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum CreateUsersWithListInputResponse { + /// successful operation + Status0_SuccessfulOperation, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum DeleteUserResponse { + /// Invalid username supplied + Status400_InvalidUsernameSupplied, + /// User not found + Status404_UserNotFound, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum GetUserByNameResponse { + /// successful operation + Status200_SuccessfulOperation(String), + /// Invalid username supplied + Status400_InvalidUsernameSupplied, + /// User not found + Status404_UserNotFound, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum LoginUserResponse { + /// successful operation + Status200_SuccessfulOperation { + body: String, + set_cookie: Option, + x_rate_limit: Option, + x_expires_after: Option>, + }, + /// Invalid username/password supplied + Status400_InvalidUsername, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum LogoutUserResponse { + /// successful operation + Status0_SuccessfulOperation, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum UpdateUserResponse { + /// Invalid user supplied + Status400_InvalidUserSupplied, + /// User not found + Status404_UserNotFound, +} + +/// User +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait User { + /// Create user. + /// + /// CreateUser - POST /v2/user + async fn create_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::User, + ) -> Result; + /// Creates list of users with given input array. + /// + /// CreateUsersWithArrayInput - POST /v2/user/createWithArray + async fn create_users_with_array_input( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Vec, + ) -> Result; + /// Creates list of users with given input array. + /// + /// CreateUsersWithListInput - POST /v2/user/createWithList + async fn create_users_with_list_input( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: Vec, + ) -> Result; + /// Delete user. + /// + /// DeleteUser - DELETE /v2/user/{username} + async fn delete_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::DeleteUserPathParams, + ) -> Result; + /// Get user by user name. + /// + /// GetUserByName - GET /v2/user/{username} + async fn get_user_by_name( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::GetUserByNamePathParams, + ) -> Result; + /// Logs user into the system. + /// + /// LoginUser - GET /v2/user/login + async fn login_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + query_params: models::LoginUserQueryParams, + ) -> Result; + /// Logs out current logged in user session. + /// + /// LogoutUser - GET /v2/user/logout + async fn logout_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Updated user. + /// + /// UpdateUser - PUT /v2/user/{username} + async fn update_user( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::UpdateUserPathParams, + body: models::User, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/petstore/src/lib.rs b/samples/server/petstore/rust-axum/output/petstore/src/lib.rs index 9cf4c904abaa..91d8f87a36a8 100644 --- a/samples/server/petstore/rust-axum/output/petstore/src/lib.rs +++ b/samples/server/petstore/rust-axum/output/petstore/src/lib.rs @@ -8,449 +8,19 @@ unused_imports, unused_attributes )] -#![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)] - -use async_trait::async_trait; -use axum::extract::*; -use axum_extra::extract::{CookieJar, Multipart}; -use bytes::Bytes; -use http::Method; -use serde::{Deserialize, Serialize}; - -use types::*; +#![allow( + clippy::derive_partial_eq_without_eq, + clippy::disallowed_names, + clippy::too_many_arguments +)] pub const BASE_PATH: &str = "/v2"; pub const API_VERSION: &str = "1.0.0"; -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum AddPetResponse { - /// successful operation - Status200_SuccessfulOperation(String), - /// Invalid input - Status405_InvalidInput, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum DeletePetResponse { - /// Invalid pet value - Status400_InvalidPetValue, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum FindPetsByStatusResponse { - /// successful operation - Status200_SuccessfulOperation(String), - /// Invalid status value - Status400_InvalidStatusValue, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum FindPetsByTagsResponse { - /// successful operation - Status200_SuccessfulOperation(String), - /// Invalid tag value - Status400_InvalidTagValue, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum GetPetByIdResponse { - /// successful operation - Status200_SuccessfulOperation(String), - /// Invalid ID supplied - Status400_InvalidIDSupplied, - /// Pet not found - Status404_PetNotFound, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum UpdatePetResponse { - /// successful operation - Status200_SuccessfulOperation(String), - /// Invalid ID supplied - Status400_InvalidIDSupplied, - /// Pet not found - Status404_PetNotFound, - /// Validation exception - Status405_ValidationException, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum UpdatePetWithFormResponse { - /// Invalid input - Status405_InvalidInput, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum UploadFileResponse { - /// successful operation - Status200_SuccessfulOperation(models::ApiResponse), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum DeleteOrderResponse { - /// Invalid ID supplied - Status400_InvalidIDSupplied, - /// Order not found - Status404_OrderNotFound, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum GetInventoryResponse { - /// successful operation - Status200_SuccessfulOperation(std::collections::HashMap), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum GetOrderByIdResponse { - /// successful operation - Status200_SuccessfulOperation(String), - /// Invalid ID supplied - Status400_InvalidIDSupplied, - /// Order not found - Status404_OrderNotFound, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum PlaceOrderResponse { - /// successful operation - Status200_SuccessfulOperation(String), - /// Invalid Order - Status400_InvalidOrder, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum CreateUserResponse { - /// successful operation - Status0_SuccessfulOperation, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum CreateUsersWithArrayInputResponse { - /// successful operation - Status0_SuccessfulOperation, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum CreateUsersWithListInputResponse { - /// successful operation - Status0_SuccessfulOperation, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum DeleteUserResponse { - /// Invalid username supplied - Status400_InvalidUsernameSupplied, - /// User not found - Status404_UserNotFound, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum GetUserByNameResponse { - /// successful operation - Status200_SuccessfulOperation(String), - /// Invalid username supplied - Status400_InvalidUsernameSupplied, - /// User not found - Status404_UserNotFound, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum LoginUserResponse { - /// successful operation - Status200_SuccessfulOperation { - body: String, - set_cookie: Option, - x_rate_limit: Option, - x_expires_after: Option>, - }, - /// Invalid username/password supplied - Status400_InvalidUsername, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum LogoutUserResponse { - /// successful operation - Status0_SuccessfulOperation, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum UpdateUserResponse { - /// Invalid user supplied - Status400_InvalidUserSupplied, - /// User not found - Status404_UserNotFound, -} - -/// API -#[async_trait] -#[allow(clippy::ptr_arg)] -pub trait Api { - /// Add a new pet to the store. - /// - /// AddPet - POST /v2/pet - async fn add_pet( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Pet, - ) -> Result; - - /// Deletes a pet. - /// - /// DeletePet - DELETE /v2/pet/{petId} - async fn delete_pet( - &self, - method: Method, - host: Host, - cookies: CookieJar, - header_params: models::DeletePetHeaderParams, - path_params: models::DeletePetPathParams, - ) -> Result; - - /// Finds Pets by status. - /// - /// FindPetsByStatus - GET /v2/pet/findByStatus - async fn find_pets_by_status( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::FindPetsByStatusQueryParams, - ) -> Result; - - /// Finds Pets by tags. - /// - /// FindPetsByTags - GET /v2/pet/findByTags - async fn find_pets_by_tags( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::FindPetsByTagsQueryParams, - ) -> Result; - - /// Find pet by ID. - /// - /// GetPetById - GET /v2/pet/{petId} - async fn get_pet_by_id( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetPetByIdPathParams, - ) -> Result; - - /// Update an existing pet. - /// - /// UpdatePet - PUT /v2/pet - async fn update_pet( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Pet, - ) -> Result; - - /// Updates a pet in the store with form data. - /// - /// UpdatePetWithForm - POST /v2/pet/{petId} - async fn update_pet_with_form( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UpdatePetWithFormPathParams, - body: Option, - ) -> Result; - - /// uploads an image. - /// - /// UploadFile - POST /v2/pet/{petId}/uploadImage - async fn upload_file( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UploadFilePathParams, - body: Multipart, - ) -> Result; - - /// Delete purchase order by ID. - /// - /// DeleteOrder - DELETE /v2/store/order/{orderId} - async fn delete_order( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::DeleteOrderPathParams, - ) -> Result; - - /// Returns pet inventories by status. - /// - /// GetInventory - GET /v2/store/inventory - async fn get_inventory( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Find purchase order by ID. - /// - /// GetOrderById - GET /v2/store/order/{orderId} - async fn get_order_by_id( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetOrderByIdPathParams, - ) -> Result; - - /// Place an order for a pet. - /// - /// PlaceOrder - POST /v2/store/order - async fn place_order( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Order, - ) -> Result; - - /// Create user. - /// - /// CreateUser - POST /v2/user - async fn create_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::User, - ) -> Result; - - /// Creates list of users with given input array. - /// - /// CreateUsersWithArrayInput - POST /v2/user/createWithArray - async fn create_users_with_array_input( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Vec, - ) -> Result; - - /// Creates list of users with given input array. - /// - /// CreateUsersWithListInput - POST /v2/user/createWithList - async fn create_users_with_list_input( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: Vec, - ) -> Result; - - /// Delete user. - /// - /// DeleteUser - DELETE /v2/user/{username} - async fn delete_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::DeleteUserPathParams, - ) -> Result; - - /// Get user by user name. - /// - /// GetUserByName - GET /v2/user/{username} - async fn get_user_by_name( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetUserByNamePathParams, - ) -> Result; - - /// Logs user into the system. - /// - /// LoginUser - GET /v2/user/login - async fn login_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - query_params: models::LoginUserQueryParams, - ) -> Result; - - /// Logs out current logged in user session. - /// - /// LogoutUser - GET /v2/user/logout - async fn logout_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Updated user. - /// - /// UpdateUser - PUT /v2/user/{username} - async fn update_user( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::UpdateUserPathParams, - body: models::User, - ) -> Result; -} - #[cfg(feature = "server")] pub mod server; +pub mod apis; pub mod models; pub mod types; diff --git a/samples/server/petstore/rust-axum/output/petstore/src/server/mod.rs b/samples/server/petstore/rust-axum/output/petstore/src/server/mod.rs index 2abdd54e9c40..097c6b1cd7c8 100644 --- a/samples/server/petstore/rust-axum/output/petstore/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/petstore/src/server/mod.rs @@ -10,22 +10,13 @@ use validator::{Validate, ValidationErrors}; use crate::{header, types::*}; #[allow(unused_imports)] -use crate::models; - -use crate::{ - AddPetResponse, Api, CreateUserResponse, CreateUsersWithArrayInputResponse, - CreateUsersWithListInputResponse, DeleteOrderResponse, DeletePetResponse, DeleteUserResponse, - FindPetsByStatusResponse, FindPetsByTagsResponse, GetInventoryResponse, GetOrderByIdResponse, - GetPetByIdResponse, GetUserByNameResponse, LoginUserResponse, LogoutUserResponse, - PlaceOrderResponse, UpdatePetResponse, UpdatePetWithFormResponse, UpdateUserResponse, - UploadFileResponse, -}; +use crate::{apis, models}; /// Setup API Server. pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: Api + 'static, + A: apis::pet::Pet + apis::store::Store + apis::user::User + 'static, { // build our application with a route Router::new() @@ -90,7 +81,7 @@ async fn add_pet( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::pet::Pet, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || add_pet_validation(body)) @@ -110,7 +101,7 @@ where let resp = match result { Ok(rsp) => match rsp { - AddPetResponse::Status200_SuccessfulOperation(body) => { + apis::pet::AddPetResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -126,7 +117,7 @@ where let body_content = body; response.body(Body::from(body_content)) } - AddPetResponse::Status405_InvalidInput => { + apis::pet::AddPetResponse::Status405_InvalidInput => { let mut response = response.status(405); response.body(Body::empty()) } @@ -169,7 +160,7 @@ async fn delete_pet( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::pet::Pet, { // Header parameters let header_params = { @@ -218,7 +209,7 @@ where let resp = match result { Ok(rsp) => match rsp { - DeletePetResponse::Status400_InvalidPetValue => { + apis::pet::DeletePetResponse::Status400_InvalidPetValue => { let mut response = response.status(400); response.body(Body::empty()) } @@ -255,7 +246,7 @@ async fn find_pets_by_status( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::pet::Pet, { #[allow(clippy::redundant_closure)] let validation = @@ -279,7 +270,7 @@ where let resp = match result { Ok(rsp) => match rsp { - FindPetsByStatusResponse::Status200_SuccessfulOperation(body) => { + apis::pet::FindPetsByStatusResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -295,7 +286,7 @@ where let body_content = body; response.body(Body::from(body_content)) } - FindPetsByStatusResponse::Status400_InvalidStatusValue => { + apis::pet::FindPetsByStatusResponse::Status400_InvalidStatusValue => { let mut response = response.status(400); response.body(Body::empty()) } @@ -332,7 +323,7 @@ async fn find_pets_by_tags( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::pet::Pet, { #[allow(clippy::redundant_closure)] let validation = @@ -356,7 +347,7 @@ where let resp = match result { Ok(rsp) => match rsp { - FindPetsByTagsResponse::Status200_SuccessfulOperation(body) => { + apis::pet::FindPetsByTagsResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -372,7 +363,7 @@ where let body_content = body; response.body(Body::from(body_content)) } - FindPetsByTagsResponse::Status400_InvalidTagValue => { + apis::pet::FindPetsByTagsResponse::Status400_InvalidTagValue => { let mut response = response.status(400); response.body(Body::empty()) } @@ -409,7 +400,7 @@ async fn get_pet_by_id( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::pet::Pet, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || get_pet_by_id_validation(path_params)) @@ -432,7 +423,7 @@ where let resp = match result { Ok(rsp) => match rsp { - GetPetByIdResponse::Status200_SuccessfulOperation(body) => { + apis::pet::GetPetByIdResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -448,11 +439,11 @@ where let body_content = body; response.body(Body::from(body_content)) } - GetPetByIdResponse::Status400_InvalidIDSupplied => { + apis::pet::GetPetByIdResponse::Status400_InvalidIDSupplied => { let mut response = response.status(400); response.body(Body::empty()) } - GetPetByIdResponse::Status404_PetNotFound => { + apis::pet::GetPetByIdResponse::Status404_PetNotFound => { let mut response = response.status(404); response.body(Body::empty()) } @@ -497,7 +488,7 @@ async fn update_pet( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::pet::Pet, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || update_pet_validation(body)) @@ -520,7 +511,7 @@ where let resp = match result { Ok(rsp) => match rsp { - UpdatePetResponse::Status200_SuccessfulOperation(body) => { + apis::pet::UpdatePetResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -536,15 +527,15 @@ where let body_content = body; response.body(Body::from(body_content)) } - UpdatePetResponse::Status400_InvalidIDSupplied => { + apis::pet::UpdatePetResponse::Status400_InvalidIDSupplied => { let mut response = response.status(400); response.body(Body::empty()) } - UpdatePetResponse::Status404_PetNotFound => { + apis::pet::UpdatePetResponse::Status404_PetNotFound => { let mut response = response.status(404); response.body(Body::empty()) } - UpdatePetResponse::Status405_ValidationException => { + apis::pet::UpdatePetResponse::Status405_ValidationException => { let mut response = response.status(405); response.body(Body::empty()) } @@ -600,7 +591,7 @@ async fn update_pet_with_form( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::pet::Pet, { #[allow(clippy::redundant_closure)] let validation = @@ -624,7 +615,7 @@ where let resp = match result { Ok(rsp) => match rsp { - UpdatePetWithFormResponse::Status405_InvalidInput => { + apis::pet::UpdatePetWithFormResponse::Status405_InvalidInput => { let mut response = response.status(405); response.body(Body::empty()) } @@ -662,7 +653,7 @@ async fn upload_file( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::pet::Pet, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || upload_file_validation(path_params)) @@ -685,7 +676,7 @@ where let resp = match result { Ok(rsp) => match rsp { - UploadFileResponse::Status200_SuccessfulOperation(body) => { + apis::pet::UploadFileResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -741,7 +732,7 @@ async fn delete_order( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::store::Store, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || delete_order_validation(path_params)) @@ -764,11 +755,11 @@ where let resp = match result { Ok(rsp) => match rsp { - DeleteOrderResponse::Status400_InvalidIDSupplied => { + apis::store::DeleteOrderResponse::Status400_InvalidIDSupplied => { let mut response = response.status(400); response.body(Body::empty()) } - DeleteOrderResponse::Status404_OrderNotFound => { + apis::store::DeleteOrderResponse::Status404_OrderNotFound => { let mut response = response.status(404); response.body(Body::empty()) } @@ -800,7 +791,7 @@ async fn get_inventory( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::store::Store, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || get_inventory_validation()) @@ -820,7 +811,7 @@ where let resp = match result { Ok(rsp) => match rsp { - GetInventoryResponse::Status200_SuccessfulOperation(body) => { + apis::store::GetInventoryResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -876,7 +867,7 @@ async fn get_order_by_id( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::store::Store, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || get_order_by_id_validation(path_params)) @@ -899,7 +890,7 @@ where let resp = match result { Ok(rsp) => match rsp { - GetOrderByIdResponse::Status200_SuccessfulOperation(body) => { + apis::store::GetOrderByIdResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -915,11 +906,11 @@ where let body_content = body; response.body(Body::from(body_content)) } - GetOrderByIdResponse::Status400_InvalidIDSupplied => { + apis::store::GetOrderByIdResponse::Status400_InvalidIDSupplied => { let mut response = response.status(400); response.body(Body::empty()) } - GetOrderByIdResponse::Status404_OrderNotFound => { + apis::store::GetOrderByIdResponse::Status404_OrderNotFound => { let mut response = response.status(404); response.body(Body::empty()) } @@ -964,7 +955,7 @@ async fn place_order( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::store::Store, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || place_order_validation(body)) @@ -987,7 +978,7 @@ where let resp = match result { Ok(rsp) => match rsp { - PlaceOrderResponse::Status200_SuccessfulOperation(body) => { + apis::store::PlaceOrderResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -1003,7 +994,7 @@ where let body_content = body; response.body(Body::from(body_content)) } - PlaceOrderResponse::Status400_InvalidOrder => { + apis::store::PlaceOrderResponse::Status400_InvalidOrder => { let mut response = response.status(400); response.body(Body::empty()) } @@ -1048,7 +1039,7 @@ async fn create_user( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::user::User, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || create_user_validation(body)) @@ -1071,7 +1062,7 @@ where let resp = match result { Ok(rsp) => match rsp { - CreateUserResponse::Status0_SuccessfulOperation => { + apis::user::CreateUserResponse::Status0_SuccessfulOperation => { let mut response = response.status(0); response.body(Body::empty()) } @@ -1116,7 +1107,7 @@ async fn create_users_with_array_input( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::user::User, { #[allow(clippy::redundant_closure)] let validation = @@ -1140,7 +1131,7 @@ where let resp = match result { Ok(rsp) => match rsp { - CreateUsersWithArrayInputResponse::Status0_SuccessfulOperation => { + apis::user::CreateUsersWithArrayInputResponse::Status0_SuccessfulOperation => { let mut response = response.status(0); response.body(Body::empty()) } @@ -1185,7 +1176,7 @@ async fn create_users_with_list_input( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::user::User, { #[allow(clippy::redundant_closure)] let validation = @@ -1209,7 +1200,7 @@ where let resp = match result { Ok(rsp) => match rsp { - CreateUsersWithListInputResponse::Status0_SuccessfulOperation => { + apis::user::CreateUsersWithListInputResponse::Status0_SuccessfulOperation => { let mut response = response.status(0); response.body(Body::empty()) } @@ -1246,7 +1237,7 @@ async fn delete_user( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::user::User, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || delete_user_validation(path_params)) @@ -1269,11 +1260,11 @@ where let resp = match result { Ok(rsp) => match rsp { - DeleteUserResponse::Status400_InvalidUsernameSupplied => { + apis::user::DeleteUserResponse::Status400_InvalidUsernameSupplied => { let mut response = response.status(400); response.body(Body::empty()) } - DeleteUserResponse::Status404_UserNotFound => { + apis::user::DeleteUserResponse::Status404_UserNotFound => { let mut response = response.status(404); response.body(Body::empty()) } @@ -1310,7 +1301,7 @@ async fn get_user_by_name( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::user::User, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || get_user_by_name_validation(path_params)) @@ -1333,7 +1324,7 @@ where let resp = match result { Ok(rsp) => match rsp { - GetUserByNameResponse::Status200_SuccessfulOperation(body) => { + apis::user::GetUserByNameResponse::Status200_SuccessfulOperation(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -1349,11 +1340,11 @@ where let body_content = body; response.body(Body::from(body_content)) } - GetUserByNameResponse::Status400_InvalidUsernameSupplied => { + apis::user::GetUserByNameResponse::Status400_InvalidUsernameSupplied => { let mut response = response.status(400); response.body(Body::empty()) } - GetUserByNameResponse::Status404_UserNotFound => { + apis::user::GetUserByNameResponse::Status404_UserNotFound => { let mut response = response.status(404); response.body(Body::empty()) } @@ -1390,7 +1381,7 @@ async fn login_user( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::user::User, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || login_user_validation(query_params)) @@ -1413,7 +1404,7 @@ where let resp = match result { Ok(rsp) => match rsp { - LoginUserResponse::Status200_SuccessfulOperation { + apis::user::LoginUserResponse::Status200_SuccessfulOperation { body, set_cookie, x_rate_limit, @@ -1481,7 +1472,7 @@ where let body_content = body; response.body(Body::from(body_content)) } - LoginUserResponse::Status400_InvalidUsername => { + apis::user::LoginUserResponse::Status400_InvalidUsername => { let mut response = response.status(400); response.body(Body::empty()) } @@ -1513,7 +1504,7 @@ async fn logout_user( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::user::User, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || logout_user_validation()) @@ -1533,7 +1524,7 @@ where let resp = match result { Ok(rsp) => match rsp { - LogoutUserResponse::Status0_SuccessfulOperation => { + apis::user::LogoutUserResponse::Status0_SuccessfulOperation => { let mut response = response.status(0); response.body(Body::empty()) } @@ -1581,7 +1572,7 @@ async fn update_user( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::user::User, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || update_user_validation(path_params, body)) @@ -1604,11 +1595,11 @@ where let resp = match result { Ok(rsp) => match rsp { - UpdateUserResponse::Status400_InvalidUserSupplied => { + apis::user::UpdateUserResponse::Status400_InvalidUserSupplied => { let mut response = response.status(400); response.body(Body::empty()) } - UpdateUserResponse::Status404_UserNotFound => { + apis::user::UpdateUserResponse::Status404_UserNotFound => { let mut response = response.status(404); response.body(Body::empty()) } diff --git a/samples/server/petstore/rust-axum/output/ping-bearer-auth/.openapi-generator/FILES b/samples/server/petstore/rust-axum/output/ping-bearer-auth/.openapi-generator/FILES index ea1c5b8c5beb..683914c4c643 100644 --- a/samples/server/petstore/rust-axum/output/ping-bearer-auth/.openapi-generator/FILES +++ b/samples/server/petstore/rust-axum/output/ping-bearer-auth/.openapi-generator/FILES @@ -1,6 +1,8 @@ .gitignore Cargo.toml README.md +src/apis/default.rs +src/apis/mod.rs src/header.rs src/lib.rs src/models.rs diff --git a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/apis/default.rs b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/apis/default.rs new file mode 100644 index 000000000000..3608ffa65572 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/apis/default.rs @@ -0,0 +1,29 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum PingGetResponse { + /// OK + Status201_OK, +} + +/// Default +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait Default { + /// PingGet - GET /ping + async fn ping_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/apis/mod.rs new file mode 100644 index 000000000000..1be8d340b8e0 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/apis/mod.rs @@ -0,0 +1 @@ +pub mod default; diff --git a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/lib.rs b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/lib.rs index f09f3f93369d..127b67da835e 100644 --- a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/lib.rs +++ b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/lib.rs @@ -8,44 +8,19 @@ unused_imports, unused_attributes )] -#![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)] - -use async_trait::async_trait; -use axum::extract::*; -use axum_extra::extract::{CookieJar, Multipart}; -use bytes::Bytes; -use http::Method; -use serde::{Deserialize, Serialize}; - -use types::*; +#![allow( + clippy::derive_partial_eq_without_eq, + clippy::disallowed_names, + clippy::too_many_arguments +)] pub const BASE_PATH: &str = ""; pub const API_VERSION: &str = "1.0"; -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum PingGetResponse { - /// OK - Status201_OK, -} - -/// API -#[async_trait] -#[allow(clippy::ptr_arg)] -pub trait Api { - /// PingGet - GET /ping - async fn ping_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; -} - #[cfg(feature = "server")] pub mod server; +pub mod apis; pub mod models; pub mod types; diff --git a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/server/mod.rs b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/server/mod.rs index 6f0aa768504f..2d1e7ca10116 100644 --- a/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/ping-bearer-auth/src/server/mod.rs @@ -10,15 +10,13 @@ use validator::{Validate, ValidationErrors}; use crate::{header, types::*}; #[allow(unused_imports)] -use crate::models; - -use crate::{Api, PingGetResponse}; +use crate::{apis, models}; /// Setup API Server. pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: Api + 'static, + A: apis::default::Default + 'static, { // build our application with a route Router::new() @@ -40,7 +38,7 @@ async fn ping_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || ping_get_validation()) @@ -60,7 +58,7 @@ where let resp = match result { Ok(rsp) => match rsp { - PingGetResponse::Status201_OK => { + apis::default::PingGetResponse::Status201_OK => { let mut response = response.status(201); response.body(Body::empty()) } diff --git a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/.openapi-generator/FILES b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/.openapi-generator/FILES index 129313d13b57..683914c4c643 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/.openapi-generator/FILES +++ b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/.openapi-generator/FILES @@ -1,7 +1,8 @@ .gitignore -.openapi-generator-ignore Cargo.toml README.md +src/apis/default.rs +src/apis/mod.rs src/header.rs src/lib.rs src/models.rs diff --git a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/apis/default.rs b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/apis/default.rs new file mode 100644 index 000000000000..cd590f6819ac --- /dev/null +++ b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/apis/default.rs @@ -0,0 +1,30 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum UsersPostResponse { + /// Added row to table! + Status201_AddedRowToTable(String), +} + +/// Default +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait Default { + /// UsersPost - POST /users + async fn users_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + header_params: models::UsersPostHeaderParams, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/apis/mod.rs new file mode 100644 index 000000000000..1be8d340b8e0 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/apis/mod.rs @@ -0,0 +1 @@ +pub mod default; diff --git a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/lib.rs b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/lib.rs index cc68ed2682b2..7f6af70e59f7 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/lib.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/lib.rs @@ -8,49 +8,19 @@ unused_imports, unused_attributes )] -#![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)] - -use async_trait::async_trait; -use axum::extract::*; -use axum_extra::extract::{CookieJar, Multipart}; -use bytes::Bytes; -use http::Method; -use serde::{Deserialize, Serialize}; - -use types::*; +#![allow( + clippy::derive_partial_eq_without_eq, + clippy::disallowed_names, + clippy::too_many_arguments +)] pub const BASE_PATH: &str = ""; pub const API_VERSION: &str = "0.1.9"; - #[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum UsersPostResponse { - /// Added row to table! - Status201_AddedRowToTable - (String) -} - - -/// API -#[async_trait] -#[allow(clippy::ptr_arg)] -pub trait Api { - - /// UsersPost - POST /users - async fn users_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - header_params: models::UsersPostHeaderParams, - ) -> Result; - -} - #[cfg(feature = "server")] pub mod server; +pub mod apis; pub mod models; pub mod types; diff --git a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/server/mod.rs b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/server/mod.rs index 2a0fa5663243..e0deda59d9c9 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-header-uuid/src/server/mod.rs @@ -10,15 +10,13 @@ use validator::{Validate, ValidationErrors}; use crate::{header, types::*}; #[allow(unused_imports)] -use crate::models; - -use crate::{Api, UsersPostResponse}; +use crate::{apis, models}; /// Setup API Server. pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: Api + 'static, + A: apis::default::Default + 'static, { // build our application with a route Router::new() @@ -45,7 +43,7 @@ async fn users_post( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { // Header parameters let header_params = { @@ -101,7 +99,7 @@ where let resp = match result { Ok(rsp) => match rsp { - UsersPostResponse::Status201_AddedRowToTable(body) => { + apis::default::UsersPostResponse::Status201_AddedRowToTable(body) => { let mut response = response.status(201); { let mut response_headers = response.headers_mut().unwrap(); diff --git a/samples/server/petstore/rust-axum/output/rust-axum-test/.openapi-generator/FILES b/samples/server/petstore/rust-axum/output/rust-axum-test/.openapi-generator/FILES index ea1c5b8c5beb..683914c4c643 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-test/.openapi-generator/FILES +++ b/samples/server/petstore/rust-axum/output/rust-axum-test/.openapi-generator/FILES @@ -1,6 +1,8 @@ .gitignore Cargo.toml README.md +src/apis/default.rs +src/apis/mod.rs src/header.rs src/lib.rs src/models.rs diff --git a/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/default.rs b/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/default.rs new file mode 100644 index 000000000000..d92b8dbf3ae4 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/default.rs @@ -0,0 +1,163 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum AllOfGetResponse { + /// OK + Status200_OK(models::AllOfObject), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum DummyGetResponse { + /// Success + Status200_Success, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum DummyPutResponse { + /// Success + Status200_Success, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum FileResponseGetResponse { + /// Success + Status200_Success(ByteArray), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum GetStructuredYamlResponse { + /// OK + Status200_OK(String), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum HtmlPostResponse { + /// Success + Status200_Success(String), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum PostYamlResponse { + /// OK + Status204_OK, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum RawJsonGetResponse { + /// Success + Status200_Success(crate::types::Object), +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum SoloObjectPostResponse { + /// OK + Status204_OK, +} + +/// Default +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait Default { + /// AllOfGet - GET /allOf + async fn all_of_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// A dummy endpoint to make the spec valid.. + /// + /// DummyGet - GET /dummy + async fn dummy_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// DummyPut - PUT /dummy + async fn dummy_put( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::DummyPutRequest, + ) -> Result; + /// Get a file. + /// + /// FileResponseGet - GET /file_response + async fn file_response_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// GetStructuredYaml - GET /get-structured-yaml + async fn get_structured_yaml( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Test HTML handling. + /// + /// HtmlPost - POST /html + async fn html_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: String, + ) -> Result; + /// PostYaml - POST /post-yaml + async fn post_yaml( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: String, + ) -> Result; + /// Get an arbitrary JSON blob.. + /// + /// RawJsonGet - GET /raw_json + async fn raw_json_get( + &self, + method: Method, + host: Host, + cookies: CookieJar, + ) -> Result; + /// Send an arbitrary JSON blob. + /// + /// SoloObjectPost - POST /solo-object + async fn solo_object_post( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: crate::types::Object, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/mod.rs new file mode 100644 index 000000000000..1be8d340b8e0 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/mod.rs @@ -0,0 +1 @@ +pub mod default; diff --git a/samples/server/petstore/rust-axum/output/rust-axum-test/src/lib.rs b/samples/server/petstore/rust-axum/output/rust-axum-test/src/lib.rs index 305ff1df6d15..d9085fbe8b9b 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-test/src/lib.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-test/src/lib.rs @@ -8,186 +8,19 @@ unused_imports, unused_attributes )] -#![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)] - -use async_trait::async_trait; -use axum::extract::*; -use axum_extra::extract::{CookieJar, Multipart}; -use bytes::Bytes; -use http::Method; -use serde::{Deserialize, Serialize}; - -use types::*; +#![allow( + clippy::derive_partial_eq_without_eq, + clippy::disallowed_names, + clippy::too_many_arguments +)] pub const BASE_PATH: &str = ""; pub const API_VERSION: &str = "2.3.4"; -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum AllOfGetResponse { - /// OK - Status200_OK(models::AllOfObject), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum DummyGetResponse { - /// Success - Status200_Success, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum DummyPutResponse { - /// Success - Status200_Success, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum FileResponseGetResponse { - /// Success - Status200_Success(ByteArray), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum GetStructuredYamlResponse { - /// OK - Status200_OK(String), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum HtmlPostResponse { - /// Success - Status200_Success(String), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum PostYamlResponse { - /// OK - Status204_OK, -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum RawJsonGetResponse { - /// Success - Status200_Success(crate::types::Object), -} - -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum SoloObjectPostResponse { - /// OK - Status204_OK, -} - -/// API -#[async_trait] -#[allow(clippy::ptr_arg)] -pub trait Api { - /// AllOfGet - GET /allOf - async fn all_of_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// A dummy endpoint to make the spec valid.. - /// - /// DummyGet - GET /dummy - async fn dummy_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// DummyPut - PUT /dummy - async fn dummy_put( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::DummyPutRequest, - ) -> Result; - - /// Get a file. - /// - /// FileResponseGet - GET /file_response - async fn file_response_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// GetStructuredYaml - GET /get-structured-yaml - async fn get_structured_yaml( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Test HTML handling. - /// - /// HtmlPost - POST /html - async fn html_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: String, - ) -> Result; - - /// PostYaml - POST /post-yaml - async fn post_yaml( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: String, - ) -> Result; - - /// Get an arbitrary JSON blob.. - /// - /// RawJsonGet - GET /raw_json - async fn raw_json_get( - &self, - method: Method, - host: Host, - cookies: CookieJar, - ) -> Result; - - /// Send an arbitrary JSON blob. - /// - /// SoloObjectPost - POST /solo-object - async fn solo_object_post( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: crate::types::Object, - ) -> Result; -} - #[cfg(feature = "server")] pub mod server; +pub mod apis; pub mod models; pub mod types; diff --git a/samples/server/petstore/rust-axum/output/rust-axum-test/src/server/mod.rs b/samples/server/petstore/rust-axum/output/rust-axum-test/src/server/mod.rs index da5d544f848a..f16aec9b6e14 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-test/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-test/src/server/mod.rs @@ -10,19 +10,13 @@ use validator::{Validate, ValidationErrors}; use crate::{header, types::*}; #[allow(unused_imports)] -use crate::models; - -use crate::{ - AllOfGetResponse, Api, DummyGetResponse, DummyPutResponse, FileResponseGetResponse, - GetStructuredYamlResponse, HtmlPostResponse, PostYamlResponse, RawJsonGetResponse, - SoloObjectPostResponse, -}; +use crate::{apis, models}; /// Setup API Server. pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: Api + 'static, + A: apis::default::Default + 'static, { // build our application with a route Router::new() @@ -51,7 +45,7 @@ async fn all_of_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || all_of_get_validation()) @@ -71,7 +65,7 @@ where let resp = match result { Ok(rsp) => match rsp { - AllOfGetResponse::Status200_OK(body) => { + apis::default::AllOfGetResponse::Status200_OK(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -122,7 +116,7 @@ async fn dummy_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || dummy_get_validation()) @@ -142,7 +136,7 @@ where let resp = match result { Ok(rsp) => match rsp { - DummyGetResponse::Status200_Success => { + apis::default::DummyGetResponse::Status200_Success => { let mut response = response.status(200); response.body(Body::empty()) } @@ -187,7 +181,7 @@ async fn dummy_put( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || dummy_put_validation(body)) @@ -210,7 +204,7 @@ where let resp = match result { Ok(rsp) => match rsp { - DummyPutResponse::Status200_Success => { + apis::default::DummyPutResponse::Status200_Success => { let mut response = response.status(200); response.body(Body::empty()) } @@ -242,7 +236,7 @@ async fn file_response_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || file_response_get_validation()) @@ -265,7 +259,7 @@ where let resp = match result { Ok(rsp) => match rsp { - FileResponseGetResponse::Status200_Success(body) => { + apis::default::FileResponseGetResponse::Status200_Success(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -316,7 +310,7 @@ async fn get_structured_yaml( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || get_structured_yaml_validation()) @@ -339,7 +333,7 @@ where let resp = match result { Ok(rsp) => match rsp { - GetStructuredYamlResponse::Status200_OK(body) => { + apis::default::GetStructuredYamlResponse::Status200_OK(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -390,7 +384,7 @@ async fn html_post( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || html_post_validation(body)) @@ -413,7 +407,7 @@ where let resp = match result { Ok(rsp) => match rsp { - HtmlPostResponse::Status200_Success(body) => { + apis::default::HtmlPostResponse::Status200_Success(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -464,7 +458,7 @@ async fn post_yaml( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || post_yaml_validation(body)) @@ -487,7 +481,7 @@ where let resp = match result { Ok(rsp) => match rsp { - PostYamlResponse::Status204_OK => { + apis::default::PostYamlResponse::Status204_OK => { let mut response = response.status(204); response.body(Body::empty()) } @@ -519,7 +513,7 @@ async fn raw_json_get( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || raw_json_get_validation()) @@ -539,7 +533,7 @@ where let resp = match result { Ok(rsp) => match rsp { - RawJsonGetResponse::Status200_Success(body) => { + apis::default::RawJsonGetResponse::Status200_Success(body) => { let mut response = response.status(200); { let mut response_headers = response.headers_mut().unwrap(); @@ -602,7 +596,7 @@ async fn solo_object_post( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { #[allow(clippy::redundant_closure)] let validation = tokio::task::spawn_blocking(move || solo_object_post_validation(body)) @@ -625,7 +619,7 @@ where let resp = match result { Ok(rsp) => match rsp { - SoloObjectPostResponse::Status204_OK => { + apis::default::SoloObjectPostResponse::Status204_OK => { let mut response = response.status(204); response.body(Body::empty()) } diff --git a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/.openapi-generator/FILES b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/.openapi-generator/FILES index ea1c5b8c5beb..683914c4c643 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/.openapi-generator/FILES +++ b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/.openapi-generator/FILES @@ -1,6 +1,8 @@ .gitignore Cargo.toml README.md +src/apis/default.rs +src/apis/mod.rs src/header.rs src/lib.rs src/models.rs diff --git a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/apis/default.rs b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/apis/default.rs new file mode 100644 index 000000000000..a5b9394198a1 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/apis/default.rs @@ -0,0 +1,30 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum MailPutResponse { + /// OK. + Status204_OK, +} + +/// Default +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait Default { + /// MailPut - PUT /mail + async fn mail_put( + &self, + method: Method, + host: Host, + cookies: CookieJar, + body: models::Email, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/apis/mod.rs new file mode 100644 index 000000000000..1be8d340b8e0 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/apis/mod.rs @@ -0,0 +1 @@ +pub mod default; diff --git a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/lib.rs b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/lib.rs index f66c98cbf624..bfdd7c899236 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/lib.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/lib.rs @@ -8,45 +8,19 @@ unused_imports, unused_attributes )] -#![allow(clippy::derive_partial_eq_without_eq, clippy::disallowed_names)] - -use async_trait::async_trait; -use axum::extract::*; -use axum_extra::extract::{CookieJar, Multipart}; -use bytes::Bytes; -use http::Method; -use serde::{Deserialize, Serialize}; - -use types::*; +#![allow( + clippy::derive_partial_eq_without_eq, + clippy::disallowed_names, + clippy::too_many_arguments +)] pub const BASE_PATH: &str = ""; pub const API_VERSION: &str = "0.0.1"; -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum MailPutResponse { - /// OK. - Status204_OK, -} - -/// API -#[async_trait] -#[allow(clippy::ptr_arg)] -pub trait Api { - /// MailPut - PUT /mail - async fn mail_put( - &self, - method: Method, - host: Host, - cookies: CookieJar, - body: models::Email, - ) -> Result; -} - #[cfg(feature = "server")] pub mod server; +pub mod apis; pub mod models; pub mod types; diff --git a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/server/mod.rs b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/server/mod.rs index 98533a86b73d..822b74a61f60 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-validation-test/src/server/mod.rs @@ -10,15 +10,13 @@ use validator::{Validate, ValidationErrors}; use crate::{header, types::*}; #[allow(unused_imports)] -use crate::models; - -use crate::{Api, MailPutResponse}; +use crate::{apis, models}; /// Setup API Server. pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: Api + 'static, + A: apis::default::Default + 'static, { // build our application with a route Router::new() @@ -37,7 +35,7 @@ async fn mail_put( ) -> Result where I: AsRef + Send + Sync, - A: Api, + A: apis::default::Default, { let result = api_impl .as_ref() @@ -48,7 +46,7 @@ where let resp = match result { Ok(rsp) => match rsp { - MailPutResponse::Status204_OK => { + apis::default::MailPutResponse::Status204_OK => { let mut response = response.status(204); response.body(Body::empty()) } From a896ed821d016452971e15d501f1c5cb8227c859 Mon Sep 17 00:00:00 2001 From: Kalvin Pearce Date: Fri, 10 May 2024 15:00:46 +1000 Subject: [PATCH 4/6] [rust-axum] Feat: handle mutli tagged operations --- .../languages/RustAxumServerCodegen.java | 12 +- .../openapi-v3/.openapi-generator/FILES | 1 + .../output/openapi-v3/src/apis/info_repo.rs | 30 +++++ .../output/openapi-v3/src/apis/mod.rs | 1 + .../output/openapi-v3/src/apis/repo.rs | 16 --- .../output/openapi-v3/src/server/mod.rs | 110 +++++++++--------- 6 files changed, 98 insertions(+), 72 deletions(-) create mode 100644 samples/server/petstore/rust-axum/output/openapi-v3/src/apis/info_repo.rs diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java index 6409834c1cd3..9641ec5f8564 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java @@ -657,13 +657,23 @@ public boolean isDataTypeFile(final String dataType) { @Override public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation op, Map> operations) { - // only generate operation for the first tag of the tags + // If more than one tag, combine into a single unique group if (tag != null && op.tags.size() > 1) { + // Skip any tags other than the first one. This is because we + // override the tag with a combined version of all the tags. String expectedTag = sanitizeTag(op.tags.get(0).getName()); if (!tag.equals(expectedTag)) { LOGGER.info("generated skip additional tag `{}` with operationId={}", tag, op.operationId); return; } + + // Get all tags sorted by name + List tags = op.tags.stream().map(t -> t.getName()).sorted().collect(Collectors.toList()); + // Combine into a single group + String combinedTag = tags.stream().collect(Collectors.joining("-")); + // Add to group + super.addOperationToGroup(combinedTag, resourcePath, operation, op, operations); + return; } super.addOperationToGroup(tag, resourcePath, operation, op, operations); } diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/.openapi-generator/FILES b/samples/server/petstore/rust-axum/output/openapi-v3/.openapi-generator/FILES index 747293c5be25..2c6783a8355b 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/.openapi-generator/FILES +++ b/samples/server/petstore/rust-axum/output/openapi-v3/.openapi-generator/FILES @@ -2,6 +2,7 @@ Cargo.toml README.md src/apis/default.rs +src/apis/info_repo.rs src/apis/mod.rs src/apis/repo.rs src/header.rs diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/info_repo.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/info_repo.rs new file mode 100644 index 000000000000..bd68394bf230 --- /dev/null +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/info_repo.rs @@ -0,0 +1,30 @@ +use async_trait::async_trait; +use axum::extract::*; +use axum_extra::extract::{CookieJar, Multipart}; +use bytes::Bytes; +use http::Method; +use serde::{Deserialize, Serialize}; + +use crate::{models, types::*}; + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[must_use] +#[allow(clippy::large_enum_variant)] +pub enum GetRepoInfoResponse { + /// OK + Status200_OK(String), +} + +/// InfoRepo +#[async_trait] +#[allow(clippy::ptr_arg)] +pub trait InfoRepo { + /// GetRepoInfo - GET /repos/{repoId} + async fn get_repo_info( + &self, + method: Method, + host: Host, + cookies: CookieJar, + path_params: models::GetRepoInfoPathParams, + ) -> Result; +} diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/mod.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/mod.rs index 8675010ecc45..63ecd2990e89 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/mod.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/mod.rs @@ -1,2 +1,3 @@ pub mod default; +pub mod info_repo; pub mod repo; diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/repo.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/repo.rs index ebd3168dacfc..e08336d7799e 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/repo.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/repo.rs @@ -15,14 +15,6 @@ pub enum CreateRepoResponse { Status200_Success, } -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[must_use] -#[allow(clippy::large_enum_variant)] -pub enum GetRepoInfoResponse { - /// OK - Status200_OK(String), -} - /// Repo #[async_trait] #[allow(clippy::ptr_arg)] @@ -35,12 +27,4 @@ pub trait Repo { cookies: CookieJar, body: models::ObjectParam, ) -> Result; - /// GetRepoInfo - GET /repos/{repoId} - async fn get_repo_info( - &self, - method: Method, - host: Host, - cookies: CookieJar, - path_params: models::GetRepoInfoPathParams, - ) -> Result; } diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs index c9c13b843c7e..cc8091d104de 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs @@ -16,7 +16,7 @@ use crate::{apis, models}; pub fn new(api_impl: I) -> Router where I: AsRef + Clone + Send + Sync + 'static, - A: apis::default::Default + apis::repo::Repo + 'static, + A: apis::default::Default + apis::info_repo::InfoRepo + apis::repo::Repo + 'static, { // build our application with a route Router::new() @@ -1921,38 +1921,30 @@ where }) } -#[derive(validator::Validate)] -#[allow(dead_code)] -struct CreateRepoBodyValidator<'a> { - #[validate(nested)] - body: &'a models::ObjectParam, -} - #[tracing::instrument(skip_all)] -fn create_repo_validation( - body: models::ObjectParam, -) -> std::result::Result<(models::ObjectParam,), ValidationErrors> { - let b = CreateRepoBodyValidator { body: &body }; - b.validate()?; +fn get_repo_info_validation( + path_params: models::GetRepoInfoPathParams, +) -> std::result::Result<(models::GetRepoInfoPathParams,), ValidationErrors> { + path_params.validate()?; - Ok((body,)) + Ok((path_params,)) } -/// CreateRepo - POST /repos +/// GetRepoInfo - GET /repos/{repoId} #[tracing::instrument(skip_all)] -async fn create_repo( +async fn get_repo_info( method: Method, host: Host, cookies: CookieJar, + Path(path_params): Path, State(api_impl): State, - Json(body): Json, ) -> Result where I: AsRef + Send + Sync, - A: apis::repo::Repo, + A: apis::info_repo::InfoRepo, { - let validation = create_repo_validation(body); + let validation = get_repo_info_validation(path_params); - let Ok((body,)) = validation else { + let Ok((path_params,)) = validation else { return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) @@ -1961,16 +1953,35 @@ where let result = api_impl .as_ref() - .create_repo(method, host, cookies, body) + .get_repo_info(method, host, cookies, path_params) .await; let mut response = Response::builder(); let resp = match result { Ok(rsp) => match rsp { - apis::repo::CreateRepoResponse::Status200_Success => { + apis::info_repo::GetRepoInfoResponse::Status200_OK(body) => { let mut response = response.status(200); - response.body(Body::empty()) + { + let mut response_headers = response.headers_mut().unwrap(); + response_headers.insert( + CONTENT_TYPE, + HeaderValue::from_str("application/json").map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + })?, + ); + } + + let body_content = tokio::task::spawn_blocking(move || { + serde_json::to_vec(&body).map_err(|e| { + error!(error = ?e); + StatusCode::INTERNAL_SERVER_ERROR + }) + }) + .await + .unwrap()?; + response.body(Body::from(body_content)) } }, Err(_) => { @@ -1986,30 +1997,38 @@ where }) } +#[derive(validator::Validate)] +#[allow(dead_code)] +struct CreateRepoBodyValidator<'a> { + #[validate(nested)] + body: &'a models::ObjectParam, +} + #[tracing::instrument(skip_all)] -fn get_repo_info_validation( - path_params: models::GetRepoInfoPathParams, -) -> std::result::Result<(models::GetRepoInfoPathParams,), ValidationErrors> { - path_params.validate()?; +fn create_repo_validation( + body: models::ObjectParam, +) -> std::result::Result<(models::ObjectParam,), ValidationErrors> { + let b = CreateRepoBodyValidator { body: &body }; + b.validate()?; - Ok((path_params,)) + Ok((body,)) } -/// GetRepoInfo - GET /repos/{repoId} +/// CreateRepo - POST /repos #[tracing::instrument(skip_all)] -async fn get_repo_info( +async fn create_repo( method: Method, host: Host, cookies: CookieJar, - Path(path_params): Path, State(api_impl): State, + Json(body): Json, ) -> Result where I: AsRef + Send + Sync, A: apis::repo::Repo, { - let validation = get_repo_info_validation(path_params); + let validation = create_repo_validation(body); - let Ok((path_params,)) = validation else { + let Ok((body,)) = validation else { return Response::builder() .status(StatusCode::BAD_REQUEST) .body(Body::from(validation.unwrap_err().to_string())) @@ -2018,35 +2037,16 @@ where let result = api_impl .as_ref() - .get_repo_info(method, host, cookies, path_params) + .create_repo(method, host, cookies, body) .await; let mut response = Response::builder(); let resp = match result { Ok(rsp) => match rsp { - apis::repo::GetRepoInfoResponse::Status200_OK(body) => { + apis::repo::CreateRepoResponse::Status200_Success => { let mut response = response.status(200); - { - let mut response_headers = response.headers_mut().unwrap(); - response_headers.insert( - CONTENT_TYPE, - HeaderValue::from_str("application/json").map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - })?, - ); - } - - let body_content = tokio::task::spawn_blocking(move || { - serde_json::to_vec(&body).map_err(|e| { - error!(error = ?e); - StatusCode::INTERNAL_SERVER_ERROR - }) - }) - .await - .unwrap()?; - response.body(Body::from(body_content)) + response.body(Body::empty()) } }, Err(_) => { From cfc074b074f09db05cb546fb8221d398b799a6fb Mon Sep 17 00:00:00 2001 From: Kalvin Pearce Date: Fri, 10 May 2024 15:07:38 +1000 Subject: [PATCH 5/6] [rust-axum] Fix: spacing between generated operations --- .../main/resources/rust-axum/apis.mustache | 3 ++ .../output/multipart-v3/src/apis/default.rs | 2 ++ .../output/openapi-v3/src/apis/default.rs | 23 ++++++++++++ .../output/ops-v3/src/apis/default.rs | 36 +++++++++++++++++++ .../src/apis/fake.rs | 12 +++++++ .../src/apis/pet.rs | 7 ++++ .../src/apis/store.rs | 3 ++ .../src/apis/user.rs | 7 ++++ .../rust-axum/output/petstore/src/apis/pet.rs | 7 ++++ .../output/petstore/src/apis/store.rs | 3 ++ .../output/petstore/src/apis/user.rs | 7 ++++ .../output/rust-axum-test/src/apis/default.rs | 8 +++++ 12 files changed, 118 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/rust-axum/apis.mustache b/modules/openapi-generator/src/main/resources/rust-axum/apis.mustache index 86f58f7ce380..5f3253ac5c47 100644 --- a/modules/openapi-generator/src/main/resources/rust-axum/apis.mustache +++ b/modules/openapi-generator/src/main/resources/rust-axum/apis.mustache @@ -66,6 +66,9 @@ pub trait {{classnamePascalCase}} { {{/x-consumes-multipart-related}} ) -> Result<{{{operationId}}}Response, String>; {{/vendorExtensions}} + {{^-last}} + + {{/-last}} {{/operation}} } {{/operations}} diff --git a/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/default.rs b/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/default.rs index 8384048e0899..27d8cf2ee301 100644 --- a/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/default.rs +++ b/samples/server/petstore/rust-axum/output/multipart-v3/src/apis/default.rs @@ -43,6 +43,7 @@ pub trait Default { cookies: CookieJar, body: axum::body::Body, ) -> Result; + /// MultipartRequestPost - POST /multipart_request async fn multipart_request_post( &self, @@ -51,6 +52,7 @@ pub trait Default { cookies: CookieJar, body: Multipart, ) -> Result; + /// MultipleIdenticalMimeTypesPost - POST /multiple-identical-mime-types async fn multiple_identical_mime_types_post( &self, diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/default.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/default.rs index 21ef2e768481..d7d7e8232db7 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/default.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/apis/default.rs @@ -251,6 +251,7 @@ pub trait Default { cookies: CookieJar, query_params: models::AnyOfGetQueryParams, ) -> Result; + /// CallbackWithHeaderPost - POST /callback-with-header async fn callback_with_header_post( &self, @@ -259,6 +260,7 @@ pub trait Default { cookies: CookieJar, query_params: models::CallbackWithHeaderPostQueryParams, ) -> Result; + /// ComplexQueryParamGet - GET /complex-query-param async fn complex_query_param_get( &self, @@ -267,6 +269,7 @@ pub trait Default { cookies: CookieJar, query_params: models::ComplexQueryParamGetQueryParams, ) -> Result; + /// EnumInPathPathParamGet - GET /enum_in_path/{path_param} async fn enum_in_path_path_param_get( &self, @@ -275,6 +278,7 @@ pub trait Default { cookies: CookieJar, path_params: models::EnumInPathPathParamGetPathParams, ) -> Result; + /// JsonComplexQueryParamGet - GET /json-complex-query-param async fn json_complex_query_param_get( &self, @@ -283,6 +287,7 @@ pub trait Default { cookies: CookieJar, query_params: models::JsonComplexQueryParamGetQueryParams, ) -> Result; + /// MandatoryRequestHeaderGet - GET /mandatory-request-header async fn mandatory_request_header_get( &self, @@ -291,6 +296,7 @@ pub trait Default { cookies: CookieJar, header_params: models::MandatoryRequestHeaderGetHeaderParams, ) -> Result; + /// MergePatchJsonGet - GET /merge-patch-json async fn merge_patch_json_get( &self, @@ -298,6 +304,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Get some stuff.. /// /// MultigetGet - GET /multiget @@ -307,6 +314,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// MultipleAuthSchemeGet - GET /multiple_auth_scheme async fn multiple_auth_scheme_get( &self, @@ -314,6 +322,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// OneOfGet - GET /one-of async fn one_of_get( &self, @@ -321,6 +330,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// OverrideServerGet - GET /override-server async fn override_server_get( &self, @@ -328,6 +338,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Get some stuff with parameters.. /// /// ParamgetGet - GET /paramget @@ -338,6 +349,7 @@ pub trait Default { cookies: CookieJar, query_params: models::ParamgetGetQueryParams, ) -> Result; + /// ReadonlyAuthSchemeGet - GET /readonly_auth_scheme async fn readonly_auth_scheme_get( &self, @@ -345,6 +357,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// RegisterCallbackPost - POST /register-callback async fn register_callback_post( &self, @@ -353,6 +366,7 @@ pub trait Default { cookies: CookieJar, query_params: models::RegisterCallbackPostQueryParams, ) -> Result; + /// RequiredOctetStreamPut - PUT /required_octet_stream async fn required_octet_stream_put( &self, @@ -361,6 +375,7 @@ pub trait Default { cookies: CookieJar, body: Bytes, ) -> Result; + /// ResponsesWithHeadersGet - GET /responses_with_headers async fn responses_with_headers_get( &self, @@ -368,6 +383,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Rfc7807Get - GET /rfc7807 async fn rfc7807_get( &self, @@ -375,6 +391,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// UntypedPropertyGet - GET /untyped_property async fn untyped_property_get( &self, @@ -383,6 +400,7 @@ pub trait Default { cookies: CookieJar, body: Option, ) -> Result; + /// UuidGet - GET /uuid async fn uuid_get( &self, @@ -390,6 +408,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// XmlExtraPost - POST /xml_extra async fn xml_extra_post( &self, @@ -398,6 +417,7 @@ pub trait Default { cookies: CookieJar, body: Bytes, ) -> Result; + /// XmlOtherPost - POST /xml_other async fn xml_other_post( &self, @@ -406,6 +426,7 @@ pub trait Default { cookies: CookieJar, body: Bytes, ) -> Result; + /// XmlOtherPut - PUT /xml_other async fn xml_other_put( &self, @@ -414,6 +435,7 @@ pub trait Default { cookies: CookieJar, body: Bytes, ) -> Result; + /// Post an array. /// /// XmlPost - POST /xml @@ -424,6 +446,7 @@ pub trait Default { cookies: CookieJar, body: Bytes, ) -> Result; + /// XmlPut - PUT /xml async fn xml_put( &self, diff --git a/samples/server/petstore/rust-axum/output/ops-v3/src/apis/default.rs b/samples/server/petstore/rust-axum/output/ops-v3/src/apis/default.rs index 6797483ebce0..c24558c161db 100644 --- a/samples/server/petstore/rust-axum/output/ops-v3/src/apis/default.rs +++ b/samples/server/petstore/rust-axum/output/ops-v3/src/apis/default.rs @@ -314,6 +314,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op11Get - GET /op11 async fn op11_get( &self, @@ -321,6 +322,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op12Get - GET /op12 async fn op12_get( &self, @@ -328,6 +330,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op13Get - GET /op13 async fn op13_get( &self, @@ -335,6 +338,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op14Get - GET /op14 async fn op14_get( &self, @@ -342,6 +346,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op15Get - GET /op15 async fn op15_get( &self, @@ -349,6 +354,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op16Get - GET /op16 async fn op16_get( &self, @@ -356,6 +362,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op17Get - GET /op17 async fn op17_get( &self, @@ -363,6 +370,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op18Get - GET /op18 async fn op18_get( &self, @@ -370,6 +378,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op19Get - GET /op19 async fn op19_get( &self, @@ -377,6 +386,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op1Get - GET /op1 async fn op1_get( &self, @@ -384,6 +394,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op20Get - GET /op20 async fn op20_get( &self, @@ -391,6 +402,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op21Get - GET /op21 async fn op21_get( &self, @@ -398,6 +410,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op22Get - GET /op22 async fn op22_get( &self, @@ -405,6 +418,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op23Get - GET /op23 async fn op23_get( &self, @@ -412,6 +426,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op24Get - GET /op24 async fn op24_get( &self, @@ -419,6 +434,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op25Get - GET /op25 async fn op25_get( &self, @@ -426,6 +442,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op26Get - GET /op26 async fn op26_get( &self, @@ -433,6 +450,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op27Get - GET /op27 async fn op27_get( &self, @@ -440,6 +458,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op28Get - GET /op28 async fn op28_get( &self, @@ -447,6 +466,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op29Get - GET /op29 async fn op29_get( &self, @@ -454,6 +474,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op2Get - GET /op2 async fn op2_get( &self, @@ -461,6 +482,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op30Get - GET /op30 async fn op30_get( &self, @@ -468,6 +490,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op31Get - GET /op31 async fn op31_get( &self, @@ -475,6 +498,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op32Get - GET /op32 async fn op32_get( &self, @@ -482,6 +506,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op33Get - GET /op33 async fn op33_get( &self, @@ -489,6 +514,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op34Get - GET /op34 async fn op34_get( &self, @@ -496,6 +522,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op35Get - GET /op35 async fn op35_get( &self, @@ -503,6 +530,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op36Get - GET /op36 async fn op36_get( &self, @@ -510,6 +538,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op37Get - GET /op37 async fn op37_get( &self, @@ -517,6 +546,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op3Get - GET /op3 async fn op3_get( &self, @@ -524,6 +554,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op4Get - GET /op4 async fn op4_get( &self, @@ -531,6 +562,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op5Get - GET /op5 async fn op5_get( &self, @@ -538,6 +570,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op6Get - GET /op6 async fn op6_get( &self, @@ -545,6 +578,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op7Get - GET /op7 async fn op7_get( &self, @@ -552,6 +586,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op8Get - GET /op8 async fn op8_get( &self, @@ -559,6 +594,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Op9Get - GET /op9 async fn op9_get( &self, diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake.rs index ffdd4cc759d5..38c5c477b253 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/fake.rs @@ -126,6 +126,7 @@ pub trait Fake { host: Host, cookies: CookieJar, ) -> Result; + /// FakeOuterBooleanSerialize - POST /v2/fake/outer/boolean async fn fake_outer_boolean_serialize( &self, @@ -134,6 +135,7 @@ pub trait Fake { cookies: CookieJar, body: Option, ) -> Result; + /// FakeOuterCompositeSerialize - POST /v2/fake/outer/composite async fn fake_outer_composite_serialize( &self, @@ -142,6 +144,7 @@ pub trait Fake { cookies: CookieJar, body: Option, ) -> Result; + /// FakeOuterNumberSerialize - POST /v2/fake/outer/number async fn fake_outer_number_serialize( &self, @@ -150,6 +153,7 @@ pub trait Fake { cookies: CookieJar, body: Option, ) -> Result; + /// FakeOuterStringSerialize - POST /v2/fake/outer/string async fn fake_outer_string_serialize( &self, @@ -158,6 +162,7 @@ pub trait Fake { cookies: CookieJar, body: Option, ) -> Result; + /// FakeResponseWithNumericalDescription - GET /v2/fake/response-with-numerical-description async fn fake_response_with_numerical_description( &self, @@ -165,6 +170,7 @@ pub trait Fake { host: Host, cookies: CookieJar, ) -> Result; + /// HyphenParam - GET /v2/fake/hyphenParam/{hyphen-param} async fn hyphen_param( &self, @@ -173,6 +179,7 @@ pub trait Fake { cookies: CookieJar, path_params: models::HyphenParamPathParams, ) -> Result; + /// TestBodyWithQueryParams - PUT /v2/fake/body-with-query-params async fn test_body_with_query_params( &self, @@ -182,6 +189,7 @@ pub trait Fake { query_params: models::TestBodyWithQueryParamsQueryParams, body: models::User, ) -> Result; + /// To test \"client\" model. /// /// TestClientModel - PATCH /v2/fake @@ -192,6 +200,7 @@ pub trait Fake { cookies: CookieJar, body: models::Client, ) -> Result; + /// Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트. /// /// TestEndpointParameters - POST /v2/fake @@ -202,6 +211,7 @@ pub trait Fake { cookies: CookieJar, body: models::TestEndpointParametersRequest, ) -> Result; + /// To test enum parameters. /// /// TestEnumParameters - GET /v2/fake @@ -214,6 +224,7 @@ pub trait Fake { query_params: models::TestEnumParametersQueryParams, body: Option, ) -> Result; + /// test inline additionalProperties. /// /// TestInlineAdditionalProperties - POST /v2/fake/inline-additionalProperties @@ -224,6 +235,7 @@ pub trait Fake { cookies: CookieJar, body: std::collections::HashMap, ) -> Result; + /// test json serialization of form data. /// /// TestJsonFormData - GET /v2/fake/jsonFormData diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/pet.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/pet.rs index 4e39af30849b..f2c36cd51af4 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/pet.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/pet.rs @@ -97,6 +97,7 @@ pub trait Pet { cookies: CookieJar, body: models::Pet, ) -> Result; + /// Deletes a pet. /// /// DeletePet - DELETE /v2/pet/{petId} @@ -108,6 +109,7 @@ pub trait Pet { header_params: models::DeletePetHeaderParams, path_params: models::DeletePetPathParams, ) -> Result; + /// Finds Pets by status. /// /// FindPetsByStatus - GET /v2/pet/findByStatus @@ -118,6 +120,7 @@ pub trait Pet { cookies: CookieJar, query_params: models::FindPetsByStatusQueryParams, ) -> Result; + /// Finds Pets by tags. /// /// FindPetsByTags - GET /v2/pet/findByTags @@ -128,6 +131,7 @@ pub trait Pet { cookies: CookieJar, query_params: models::FindPetsByTagsQueryParams, ) -> Result; + /// Find pet by ID. /// /// GetPetById - GET /v2/pet/{petId} @@ -138,6 +142,7 @@ pub trait Pet { cookies: CookieJar, path_params: models::GetPetByIdPathParams, ) -> Result; + /// Update an existing pet. /// /// UpdatePet - PUT /v2/pet @@ -148,6 +153,7 @@ pub trait Pet { cookies: CookieJar, body: models::Pet, ) -> Result; + /// Updates a pet in the store with form data. /// /// UpdatePetWithForm - POST /v2/pet/{petId} @@ -159,6 +165,7 @@ pub trait Pet { path_params: models::UpdatePetWithFormPathParams, body: Option, ) -> Result; + /// uploads an image. /// /// UploadFile - POST /v2/pet/{petId}/uploadImage diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/store.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/store.rs index d6d4eb6b6bd1..607bf6f568f2 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/store.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/store.rs @@ -61,6 +61,7 @@ pub trait Store { cookies: CookieJar, path_params: models::DeleteOrderPathParams, ) -> Result; + /// Returns pet inventories by status. /// /// GetInventory - GET /v2/store/inventory @@ -70,6 +71,7 @@ pub trait Store { host: Host, cookies: CookieJar, ) -> Result; + /// Find purchase order by ID. /// /// GetOrderById - GET /v2/store/order/{order_id} @@ -80,6 +82,7 @@ pub trait Store { cookies: CookieJar, path_params: models::GetOrderByIdPathParams, ) -> Result; + /// Place an order for a pet. /// /// PlaceOrder - POST /v2/store/order diff --git a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/user.rs b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/user.rs index ee1a4dfe2604..ba3e68d8424d 100644 --- a/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/user.rs +++ b/samples/server/petstore/rust-axum/output/petstore-with-fake-endpoints-models-for-testing/src/apis/user.rs @@ -99,6 +99,7 @@ pub trait User { cookies: CookieJar, body: models::User, ) -> Result; + /// Creates list of users with given input array. /// /// CreateUsersWithArrayInput - POST /v2/user/createWithArray @@ -109,6 +110,7 @@ pub trait User { cookies: CookieJar, body: Vec, ) -> Result; + /// Creates list of users with given input array. /// /// CreateUsersWithListInput - POST /v2/user/createWithList @@ -119,6 +121,7 @@ pub trait User { cookies: CookieJar, body: Vec, ) -> Result; + /// Delete user. /// /// DeleteUser - DELETE /v2/user/{username} @@ -129,6 +132,7 @@ pub trait User { cookies: CookieJar, path_params: models::DeleteUserPathParams, ) -> Result; + /// Get user by user name. /// /// GetUserByName - GET /v2/user/{username} @@ -139,6 +143,7 @@ pub trait User { cookies: CookieJar, path_params: models::GetUserByNamePathParams, ) -> Result; + /// Logs user into the system. /// /// LoginUser - GET /v2/user/login @@ -149,6 +154,7 @@ pub trait User { cookies: CookieJar, query_params: models::LoginUserQueryParams, ) -> Result; + /// Logs out current logged in user session. /// /// LogoutUser - GET /v2/user/logout @@ -158,6 +164,7 @@ pub trait User { host: Host, cookies: CookieJar, ) -> Result; + /// Updated user. /// /// UpdateUser - PUT /v2/user/{username} diff --git a/samples/server/petstore/rust-axum/output/petstore/src/apis/pet.rs b/samples/server/petstore/rust-axum/output/petstore/src/apis/pet.rs index ba8f3059dbac..057eafbec187 100644 --- a/samples/server/petstore/rust-axum/output/petstore/src/apis/pet.rs +++ b/samples/server/petstore/rust-axum/output/petstore/src/apis/pet.rs @@ -101,6 +101,7 @@ pub trait Pet { cookies: CookieJar, body: models::Pet, ) -> Result; + /// Deletes a pet. /// /// DeletePet - DELETE /v2/pet/{petId} @@ -112,6 +113,7 @@ pub trait Pet { header_params: models::DeletePetHeaderParams, path_params: models::DeletePetPathParams, ) -> Result; + /// Finds Pets by status. /// /// FindPetsByStatus - GET /v2/pet/findByStatus @@ -122,6 +124,7 @@ pub trait Pet { cookies: CookieJar, query_params: models::FindPetsByStatusQueryParams, ) -> Result; + /// Finds Pets by tags. /// /// FindPetsByTags - GET /v2/pet/findByTags @@ -132,6 +135,7 @@ pub trait Pet { cookies: CookieJar, query_params: models::FindPetsByTagsQueryParams, ) -> Result; + /// Find pet by ID. /// /// GetPetById - GET /v2/pet/{petId} @@ -142,6 +146,7 @@ pub trait Pet { cookies: CookieJar, path_params: models::GetPetByIdPathParams, ) -> Result; + /// Update an existing pet. /// /// UpdatePet - PUT /v2/pet @@ -152,6 +157,7 @@ pub trait Pet { cookies: CookieJar, body: models::Pet, ) -> Result; + /// Updates a pet in the store with form data. /// /// UpdatePetWithForm - POST /v2/pet/{petId} @@ -163,6 +169,7 @@ pub trait Pet { path_params: models::UpdatePetWithFormPathParams, body: Option, ) -> Result; + /// uploads an image. /// /// UploadFile - POST /v2/pet/{petId}/uploadImage diff --git a/samples/server/petstore/rust-axum/output/petstore/src/apis/store.rs b/samples/server/petstore/rust-axum/output/petstore/src/apis/store.rs index 77c83f31a3a3..d584d6535804 100644 --- a/samples/server/petstore/rust-axum/output/petstore/src/apis/store.rs +++ b/samples/server/petstore/rust-axum/output/petstore/src/apis/store.rs @@ -61,6 +61,7 @@ pub trait Store { cookies: CookieJar, path_params: models::DeleteOrderPathParams, ) -> Result; + /// Returns pet inventories by status. /// /// GetInventory - GET /v2/store/inventory @@ -70,6 +71,7 @@ pub trait Store { host: Host, cookies: CookieJar, ) -> Result; + /// Find purchase order by ID. /// /// GetOrderById - GET /v2/store/order/{orderId} @@ -80,6 +82,7 @@ pub trait Store { cookies: CookieJar, path_params: models::GetOrderByIdPathParams, ) -> Result; + /// Place an order for a pet. /// /// PlaceOrder - POST /v2/store/order diff --git a/samples/server/petstore/rust-axum/output/petstore/src/apis/user.rs b/samples/server/petstore/rust-axum/output/petstore/src/apis/user.rs index 118a72d4f21b..e786750bc831 100644 --- a/samples/server/petstore/rust-axum/output/petstore/src/apis/user.rs +++ b/samples/server/petstore/rust-axum/output/petstore/src/apis/user.rs @@ -100,6 +100,7 @@ pub trait User { cookies: CookieJar, body: models::User, ) -> Result; + /// Creates list of users with given input array. /// /// CreateUsersWithArrayInput - POST /v2/user/createWithArray @@ -110,6 +111,7 @@ pub trait User { cookies: CookieJar, body: Vec, ) -> Result; + /// Creates list of users with given input array. /// /// CreateUsersWithListInput - POST /v2/user/createWithList @@ -120,6 +122,7 @@ pub trait User { cookies: CookieJar, body: Vec, ) -> Result; + /// Delete user. /// /// DeleteUser - DELETE /v2/user/{username} @@ -130,6 +133,7 @@ pub trait User { cookies: CookieJar, path_params: models::DeleteUserPathParams, ) -> Result; + /// Get user by user name. /// /// GetUserByName - GET /v2/user/{username} @@ -140,6 +144,7 @@ pub trait User { cookies: CookieJar, path_params: models::GetUserByNamePathParams, ) -> Result; + /// Logs user into the system. /// /// LoginUser - GET /v2/user/login @@ -150,6 +155,7 @@ pub trait User { cookies: CookieJar, query_params: models::LoginUserQueryParams, ) -> Result; + /// Logs out current logged in user session. /// /// LogoutUser - GET /v2/user/logout @@ -159,6 +165,7 @@ pub trait User { host: Host, cookies: CookieJar, ) -> Result; + /// Updated user. /// /// UpdateUser - PUT /v2/user/{username} diff --git a/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/default.rs b/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/default.rs index d92b8dbf3ae4..b6809341c826 100644 --- a/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/default.rs +++ b/samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/default.rs @@ -90,6 +90,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// A dummy endpoint to make the spec valid.. /// /// DummyGet - GET /dummy @@ -99,6 +100,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// DummyPut - PUT /dummy async fn dummy_put( &self, @@ -107,6 +109,7 @@ pub trait Default { cookies: CookieJar, body: models::DummyPutRequest, ) -> Result; + /// Get a file. /// /// FileResponseGet - GET /file_response @@ -116,6 +119,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// GetStructuredYaml - GET /get-structured-yaml async fn get_structured_yaml( &self, @@ -123,6 +127,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Test HTML handling. /// /// HtmlPost - POST /html @@ -133,6 +138,7 @@ pub trait Default { cookies: CookieJar, body: String, ) -> Result; + /// PostYaml - POST /post-yaml async fn post_yaml( &self, @@ -141,6 +147,7 @@ pub trait Default { cookies: CookieJar, body: String, ) -> Result; + /// Get an arbitrary JSON blob.. /// /// RawJsonGet - GET /raw_json @@ -150,6 +157,7 @@ pub trait Default { host: Host, cookies: CookieJar, ) -> Result; + /// Send an arbitrary JSON blob. /// /// SoloObjectPost - POST /solo-object From 01af1a8d07cbd1771b54c74165e7066f94faf0fd Mon Sep 17 00:00:00 2001 From: Kalvin Pearce Date: Tue, 14 May 2024 21:50:39 +1000 Subject: [PATCH 6/6] [rust-axum] Fix: coding standards --- .../codegen/languages/RustAxumServerCodegen.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java index 9641ec5f8564..4b36b305c097 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java @@ -571,8 +571,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation @Override public OperationsMap postProcessOperationsWithModels(OperationsMap operationsMap, List allModels) { OperationMap operations = operationsMap.getOperations(); - String classname = operations.getClassname(); - operations.put("classnamePascalCase", camelize(classname)); + operations.put("classnamePascalCase", camelize(operations.getClassname())); List operationList = operations.getOperation(); for (CodegenOperation op : operationList) { @@ -668,9 +667,9 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera } // Get all tags sorted by name - List tags = op.tags.stream().map(t -> t.getName()).sorted().collect(Collectors.toList()); + final List tags = op.tags.stream().map(t -> t.getName()).sorted().collect(Collectors.toList()); // Combine into a single group - String combinedTag = tags.stream().collect(Collectors.joining("-")); + final String combinedTag = tags.stream().collect(Collectors.joining("-")); // Add to group super.addOperationToGroup(combinedTag, resourcePath, operation, op, operations); return;