Skip to content

Commit 7c4d727

Browse files
authored
Separate Basic Authorization into new template file (#21828)
1 parent 065eceb commit 7c4d727

File tree

62 files changed

+356
-345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+356
-345
lines changed

modules/openapi-generator/src/main/resources/rust-axum/apis.mustache

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,73 +16,7 @@ use crate::{models, types::*};
1616

1717
{{#operations}}
1818

19-
{{#basicAuthorization}}
20-
/// {{classnamePascalCase}} APIs - Authorization.
21-
#[async_trait]
22-
#[allow(clippy::ptr_arg)]
23-
pub trait {{classnamePascalCase}}Authorization {
24-
type Claims;
25-
26-
{{#operation}}
27-
{{#vendorExtensions}}
28-
{{#x-has-auth-methods}}
29-
{{#basicAuthorization}}
30-
{{#vendorExtensions}}
31-
/// Authorization{{#summary}} - {{{.}}}{{/summary}}.
32-
/// {{{operationId}}} - {{{httpMethod}}} {{{basePathWithoutHost}}}{{{path}}}
33-
async fn {{{x-operation-id}}}_authorize(
34-
&self,
35-
method: &Method,
36-
host: &Host,
37-
cookies: &CookieJar,
38-
claims: &Self::Claims,
39-
{{#headerParams.size}}
40-
header_params: &models::{{{operationIdCamelCase}}}HeaderParams,
41-
{{/headerParams.size}}
42-
{{#pathParams.size}}
43-
path_params: &models::{{{operationIdCamelCase}}}PathParams,
44-
{{/pathParams.size}}
45-
{{#queryParams.size}}
46-
query_params: &models::{{{operationIdCamelCase}}}QueryParams,
47-
{{/queryParams.size}}
48-
{{^x-consumes-multipart-related}}
49-
{{^x-consumes-multipart}}
50-
{{#bodyParam}}
51-
{{#vendorExtensions}}
52-
{{^x-consumes-plain-text}}
53-
body: &{{^required}}Option<{{/required}}{{{dataType}}}{{^required}}>{{/required}},
54-
{{/x-consumes-plain-text}}
55-
{{#x-consumes-plain-text}}
56-
{{#isString}}
57-
body: &String,
58-
{{/isString}}
59-
{{^isString}}
60-
body: &Bytes,
61-
{{/isString}}
62-
{{/x-consumes-plain-text}}
63-
{{/vendorExtensions}}
64-
{{/bodyParam}}
65-
{{/x-consumes-multipart}}
66-
{{/x-consumes-multipart-related}}
67-
{{#x-consumes-multipart}}
68-
body: &Multipart,
69-
{{/x-consumes-multipart}}
70-
{{#x-consumes-multipart-related}}
71-
body: &axum::body::Body,
72-
{{/x-consumes-multipart-related}}
73-
) -> Result<super::Authorization, ()> {
74-
Ok(super::Authorization::Authorized)
75-
}
76-
{{/vendorExtensions}}
77-
{{/basicAuthorization}}
78-
{{/x-has-auth-methods}}
79-
{{/vendorExtensions}}
80-
{{^-last}}
81-
82-
{{/-last}}
83-
{{/operation}}
84-
}
85-
{{/basicAuthorization}}
19+
{{>authorization}}
8620

8721
/// {{classnamePascalCase}}
8822
#[async_trait]
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{{#basicAuthorization}}
2+
/// {{classnamePascalCase}} APIs - Authorization.
3+
#[async_trait]
4+
#[allow(clippy::ptr_arg)]
5+
pub trait {{classnamePascalCase}}Authorization {
6+
type Claims;
7+
8+
{{#operation}}
9+
{{#vendorExtensions}}
10+
{{#x-has-auth-methods}}
11+
{{#basicAuthorization}}
12+
{{#vendorExtensions}}
13+
/// Authorization{{#summary}} - {{{.}}}{{/summary}}.
14+
/// {{{operationId}}} - {{{httpMethod}}} {{{basePathWithoutHost}}}{{{path}}}
15+
async fn {{{x-operation-id}}}_authorize(
16+
&self,
17+
method: &Method,
18+
host: &Host,
19+
cookies: &CookieJar,
20+
claims: &Self::Claims,
21+
{{#headerParams.size}}
22+
header_params: &models::{{{operationIdCamelCase}}}HeaderParams,
23+
{{/headerParams.size}}
24+
{{#pathParams.size}}
25+
path_params: &models::{{{operationIdCamelCase}}}PathParams,
26+
{{/pathParams.size}}
27+
{{#queryParams.size}}
28+
query_params: &models::{{{operationIdCamelCase}}}QueryParams,
29+
{{/queryParams.size}}
30+
{{^x-consumes-multipart-related}}
31+
{{^x-consumes-multipart}}
32+
{{#bodyParam}}
33+
{{#vendorExtensions}}
34+
{{^x-consumes-plain-text}}
35+
body: &{{^required}}Option<{{/required}}{{{dataType}}}{{^required}}>{{/required}},
36+
{{/x-consumes-plain-text}}
37+
{{#x-consumes-plain-text}}
38+
{{#isString}}
39+
body: &String,
40+
{{/isString}}
41+
{{^isString}}
42+
body: &Bytes,
43+
{{/isString}}
44+
{{/x-consumes-plain-text}}
45+
{{/vendorExtensions}}
46+
{{/bodyParam}}
47+
{{/x-consumes-multipart}}
48+
{{/x-consumes-multipart-related}}
49+
{{#x-consumes-multipart}}
50+
body: &Multipart,
51+
{{/x-consumes-multipart}}
52+
{{#x-consumes-multipart-related}}
53+
body: &axum::body::Body,
54+
{{/x-consumes-multipart-related}}
55+
) -> Result<super::Authorization, ()> {
56+
Ok(super::Authorization::Authorized)
57+
}
58+
{{/vendorExtensions}}
59+
{{/basicAuthorization}}
60+
{{/x-has-auth-methods}}
61+
{{/vendorExtensions}}
62+
{{^-last}}
63+
64+
{{/-last}}
65+
{{/operation}}
66+
}
67+
{{/basicAuthorization}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.15.0-SNAPSHOT
1+
7.16.0-SNAPSHOT

samples/server/petstore/rust-axum/output/apikey-authorization/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ server, you can easily generate a server stub.
1212
To see how to make this your own, look here: [README]((https://openapi-generator.tech))
1313

1414
- API version: 1.0.0
15-
- Generator version: 7.15.0-SNAPSHOT
15+
- Generator version: 7.16.0-SNAPSHOT
1616

1717

1818

samples/server/petstore/rust-axum/output/apikey-authorization/src/models.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl std::str::FromStr for Amount {
135135
None => {
136136
return std::result::Result::Err(
137137
"Missing value while parsing Amount".to_string(),
138-
)
138+
);
139139
}
140140
};
141141

@@ -153,7 +153,7 @@ impl std::str::FromStr for Amount {
153153
_ => {
154154
return std::result::Result::Err(
155155
"Unexpected key while parsing Amount".to_string(),
156-
)
156+
);
157157
}
158158
}
159159
}
@@ -288,7 +288,7 @@ impl std::str::FromStr for CheckoutError {
288288
None => {
289289
return std::result::Result::Err(
290290
"Missing value while parsing CheckoutError".to_string(),
291-
)
291+
);
292292
}
293293
};
294294

@@ -306,7 +306,7 @@ impl std::str::FromStr for CheckoutError {
306306
_ => {
307307
return std::result::Result::Err(
308308
"Unexpected key while parsing CheckoutError".to_string(),
309-
)
309+
);
310310
}
311311
}
312312
}
@@ -474,7 +474,7 @@ impl std::str::FromStr for Payment {
474474
None => {
475475
return std::result::Result::Err(
476476
"Missing value while parsing Payment".to_string(),
477-
)
477+
);
478478
}
479479
};
480480

@@ -506,7 +506,7 @@ impl std::str::FromStr for Payment {
506506
_ => {
507507
return std::result::Result::Err(
508508
"Unexpected key while parsing Payment".to_string(),
509-
)
509+
);
510510
}
511511
}
512512
}
@@ -656,7 +656,7 @@ impl std::str::FromStr for PaymentMethod {
656656
None => {
657657
return std::result::Result::Err(
658658
"Missing value while parsing PaymentMethod".to_string(),
659-
)
659+
);
660660
}
661661
};
662662

@@ -674,7 +674,7 @@ impl std::str::FromStr for PaymentMethod {
674674
_ => {
675675
return std::result::Result::Err(
676676
"Unexpected key while parsing PaymentMethod".to_string(),
677-
)
677+
);
678678
}
679679
}
680680
}
@@ -805,7 +805,7 @@ impl std::str::FromStr for PaymentResult {
805805
None => {
806806
return std::result::Result::Err(
807807
"Missing value while parsing PaymentResult".to_string(),
808-
)
808+
);
809809
}
810810
};
811811

@@ -823,7 +823,7 @@ impl std::str::FromStr for PaymentResult {
823823
_ => {
824824
return std::result::Result::Err(
825825
"Unexpected key while parsing PaymentResult".to_string(),
826-
)
826+
);
827827
}
828828
}
829829
}

samples/server/petstore/rust-axum/output/apikey-authorization/src/server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::collections::HashMap;
33
use axum::{body::Body, extract::*, response::Response, routing::*};
44
use axum_extra::extract::{CookieJar, Host, Query as QueryExtra};
55
use bytes::Bytes;
6-
use http::{header::CONTENT_TYPE, HeaderMap, HeaderName, HeaderValue, Method, StatusCode};
6+
use http::{HeaderMap, HeaderName, HeaderValue, Method, StatusCode, header::CONTENT_TYPE};
77
use tracing::error;
88
use validator::{Validate, ValidationErrors};
99

samples/server/petstore/rust-axum/output/apikey-authorization/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{mem, str::FromStr};
22

3-
use base64::{engine::general_purpose, Engine};
3+
use base64::{Engine, engine::general_purpose};
44
use serde::{Deserialize, Deserializer, Serialize, Serializer};
55

66
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.15.0-SNAPSHOT
1+
7.16.0-SNAPSHOT

samples/server/petstore/rust-axum/output/apikey-auths/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ server, you can easily generate a server stub.
1212
To see how to make this your own, look here: [README]((https://openapi-generator.tech))
1313

1414
- API version: 1.0.0
15-
- Generator version: 7.15.0-SNAPSHOT
15+
- Generator version: 7.16.0-SNAPSHOT
1616

1717

1818

samples/server/petstore/rust-axum/output/apikey-auths/src/models.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl std::str::FromStr for Amount {
135135
None => {
136136
return std::result::Result::Err(
137137
"Missing value while parsing Amount".to_string(),
138-
)
138+
);
139139
}
140140
};
141141

@@ -153,7 +153,7 @@ impl std::str::FromStr for Amount {
153153
_ => {
154154
return std::result::Result::Err(
155155
"Unexpected key while parsing Amount".to_string(),
156-
)
156+
);
157157
}
158158
}
159159
}
@@ -288,7 +288,7 @@ impl std::str::FromStr for CheckoutError {
288288
None => {
289289
return std::result::Result::Err(
290290
"Missing value while parsing CheckoutError".to_string(),
291-
)
291+
);
292292
}
293293
};
294294

@@ -306,7 +306,7 @@ impl std::str::FromStr for CheckoutError {
306306
_ => {
307307
return std::result::Result::Err(
308308
"Unexpected key while parsing CheckoutError".to_string(),
309-
)
309+
);
310310
}
311311
}
312312
}
@@ -474,7 +474,7 @@ impl std::str::FromStr for Payment {
474474
None => {
475475
return std::result::Result::Err(
476476
"Missing value while parsing Payment".to_string(),
477-
)
477+
);
478478
}
479479
};
480480

@@ -506,7 +506,7 @@ impl std::str::FromStr for Payment {
506506
_ => {
507507
return std::result::Result::Err(
508508
"Unexpected key while parsing Payment".to_string(),
509-
)
509+
);
510510
}
511511
}
512512
}
@@ -656,7 +656,7 @@ impl std::str::FromStr for PaymentMethod {
656656
None => {
657657
return std::result::Result::Err(
658658
"Missing value while parsing PaymentMethod".to_string(),
659-
)
659+
);
660660
}
661661
};
662662

@@ -674,7 +674,7 @@ impl std::str::FromStr for PaymentMethod {
674674
_ => {
675675
return std::result::Result::Err(
676676
"Unexpected key while parsing PaymentMethod".to_string(),
677-
)
677+
);
678678
}
679679
}
680680
}
@@ -805,7 +805,7 @@ impl std::str::FromStr for PaymentResult {
805805
None => {
806806
return std::result::Result::Err(
807807
"Missing value while parsing PaymentResult".to_string(),
808-
)
808+
);
809809
}
810810
};
811811

@@ -823,7 +823,7 @@ impl std::str::FromStr for PaymentResult {
823823
_ => {
824824
return std::result::Result::Err(
825825
"Unexpected key while parsing PaymentResult".to_string(),
826-
)
826+
);
827827
}
828828
}
829829
}

0 commit comments

Comments
 (0)