Skip to content

Commit e27d148

Browse files
chore: rerun axum samples
1 parent e490e92 commit e27d148

43 files changed

Lines changed: 733 additions & 500 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.12.0-SNAPSHOT
1+
7.14.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.12.0-SNAPSHOT
15+
- Generator version: 7.14.0-SNAPSHOT
1616

1717

1818

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@ pub trait CookieAuthentication {
2626
) -> Option<Self::Claims>;
2727
}
2828

29+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
30+
#[non_exhaustive]
31+
pub enum BasicAuthKind {
32+
Basic,
33+
Bearer,
34+
}
35+
36+
/// API Key Authentication - Authentication Header.
37+
/// For `Basic token` and `Bearer token`
38+
#[async_trait::async_trait]
39+
pub trait ApiAuthBasic {
40+
type Claims;
41+
42+
/// Extracting Claims from Header. Return None if the Claims are invalid.
43+
async fn extract_claims_from_auth_header(
44+
&self,
45+
kind: BasicAuthKind,
46+
headers: &axum::http::header::HeaderMap,
47+
key: &str,
48+
) -> Option<Self::Claims>;
49+
}
50+
2951
// Error handler for unhandled errors.
3052
#[async_trait::async_trait]
3153
pub trait ErrorHandler<E: std::fmt::Debug + Send + Sync + 'static = ()> {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub trait Payments<E: std::fmt::Debug + Send + Sync + 'static = ()>:
5151
method: &Method,
5252
host: &Host,
5353
cookies: &CookieJar,
54+
claims: &Self::Claims,
5455
path_params: &models::GetPaymentMethodByIdPathParams,
5556
) -> Result<GetPaymentMethodByIdResponse, E>;
5657

@@ -62,6 +63,7 @@ pub trait Payments<E: std::fmt::Debug + Send + Sync + 'static = ()>:
6263
method: &Method,
6364
host: &Host,
6465
cookies: &CookieJar,
66+
claims: &Self::Claims,
6567
) -> Result<GetPaymentMethodsResponse, E>;
6668

6769
/// Make a payment.

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

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ where
3434
get(get_payment_methods::<I, A, E, C>),
3535
)
3636
.route(
37-
"/v71/paymentMethods/:id",
37+
"/v71/paymentMethods/{id}",
3838
get(get_payment_method_by_id::<I, A, E, C>),
3939
)
4040
.route("/v71/payments", post(post_make_payment::<I, A, E, C>))
@@ -55,14 +55,28 @@ async fn get_payment_method_by_id<I, A, E, C>(
5555
method: Method,
5656
host: Host,
5757
cookies: CookieJar,
58+
headers: HeaderMap,
5859
Path(path_params): Path<models::GetPaymentMethodByIdPathParams>,
5960
State(api_impl): State<I>,
6061
) -> Result<Response, StatusCode>
6162
where
6263
I: AsRef<A> + Send + Sync,
63-
A: apis::payments::Payments<E, Claims = C> + Send + Sync,
64+
A: apis::payments::Payments<E, Claims = C> + apis::ApiAuthBasic<Claims = C> + Send + Sync,
6465
E: std::fmt::Debug + Send + Sync + 'static,
6566
{
67+
// Authentication
68+
let claims_in_auth_header = api_impl
69+
.as_ref()
70+
.extract_claims_from_auth_header(apis::BasicAuthKind::Bearer, &headers, "authorization")
71+
.await;
72+
let claims = None.or(claims_in_auth_header);
73+
let Some(claims) = claims else {
74+
return Response::builder()
75+
.status(StatusCode::UNAUTHORIZED)
76+
.body(Body::empty())
77+
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR);
78+
};
79+
6680
#[allow(clippy::redundant_closure)]
6781
let validation =
6882
tokio::task::spawn_blocking(move || get_payment_method_by_id_validation(path_params))
@@ -78,7 +92,7 @@ where
7892

7993
let result = api_impl
8094
.as_ref()
81-
.get_payment_method_by_id(&method, &host, &cookies, &path_params)
95+
.get_payment_method_by_id(&method, &host, &cookies, &claims, &path_params)
8296
.await;
8397

8498
let mut response = Response::builder();
@@ -158,13 +172,27 @@ async fn get_payment_methods<I, A, E, C>(
158172
method: Method,
159173
host: Host,
160174
cookies: CookieJar,
175+
headers: HeaderMap,
161176
State(api_impl): State<I>,
162177
) -> Result<Response, StatusCode>
163178
where
164179
I: AsRef<A> + Send + Sync,
165-
A: apis::payments::Payments<E, Claims = C> + Send + Sync,
180+
A: apis::payments::Payments<E, Claims = C> + apis::ApiAuthBasic<Claims = C> + Send + Sync,
166181
E: std::fmt::Debug + Send + Sync + 'static,
167182
{
183+
// Authentication
184+
let claims_in_auth_header = api_impl
185+
.as_ref()
186+
.extract_claims_from_auth_header(apis::BasicAuthKind::Bearer, &headers, "authorization")
187+
.await;
188+
let claims = None.or(claims_in_auth_header);
189+
let Some(claims) = claims else {
190+
return Response::builder()
191+
.status(StatusCode::UNAUTHORIZED)
192+
.body(Body::empty())
193+
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR);
194+
};
195+
168196
#[allow(clippy::redundant_closure)]
169197
let validation = tokio::task::spawn_blocking(move || get_payment_methods_validation())
170198
.await
@@ -179,7 +207,7 @@ where
179207

180208
let result = api_impl
181209
.as_ref()
182-
.get_payment_methods(&method, &host, &cookies)
210+
.get_payment_methods(&method, &host, &cookies, &claims)
183211
.await;
184212

185213
let mut response = Response::builder();
@@ -250,13 +278,15 @@ async fn post_make_payment<I, A, E, C>(
250278
method: Method,
251279
host: Host,
252280
cookies: CookieJar,
281+
headers: HeaderMap,
253282
State(api_impl): State<I>,
254283
Json(body): Json<Option<models::Payment>>,
255284
) -> Result<Response, StatusCode>
256285
where
257286
I: AsRef<A> + Send + Sync,
258287
A: apis::payments::Payments<E, Claims = C>
259288
+ apis::CookieAuthentication<Claims = C>
289+
+ apis::ApiAuthBasic<Claims = C>
260290
+ Send
261291
+ Sync,
262292
E: std::fmt::Debug + Send + Sync + 'static,
@@ -266,7 +296,11 @@ where
266296
.as_ref()
267297
.extract_claims_from_cookie(&cookies, "X-API-Key")
268298
.await;
269-
let claims = None.or(claims_in_cookie);
299+
let claims_in_auth_header = api_impl
300+
.as_ref()
301+
.extract_claims_from_auth_header(apis::BasicAuthKind::Bearer, &headers, "authorization")
302+
.await;
303+
let claims = None.or(claims_in_cookie).or(claims_in_auth_header);
270304
let Some(claims) = claims else {
271305
return Response::builder()
272306
.status(StatusCode::UNAUTHORIZED)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.12.0-SNAPSHOT
1+
7.14.0-SNAPSHOT

samples/server/petstore/rust-axum/output/multipart-v3/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.7
15-
- Generator version: 7.12.0-SNAPSHOT
15+
- Generator version: 7.14.0-SNAPSHOT
1616

1717

1818

samples/server/petstore/rust-axum/output/multipart-v3/src/server/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ where
6969

7070
let result = api_impl
7171
.as_ref()
72-
.multipart_related_request_post(&method, &host, &cookies, &body)
72+
.multipart_related_request_post(&method, &host, &cookies, body)
7373
.await;
7474

7575
let mut response = Response::builder();
@@ -129,7 +129,7 @@ where
129129

130130
let result = api_impl
131131
.as_ref()
132-
.multipart_request_post(&method, &host, &cookies, &body)
132+
.multipart_request_post(&method, &host, &cookies, body)
133133
.await;
134134

135135
let mut response = Response::builder();
@@ -190,7 +190,7 @@ where
190190

191191
let result = api_impl
192192
.as_ref()
193-
.multiple_identical_mime_types_post(&method, &host, &cookies, &body)
193+
.multiple_identical_mime_types_post(&method, &host, &cookies, body)
194194
.await;
195195

196196
let mut response = Response::builder();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.12.0-SNAPSHOT
1+
7.14.0-SNAPSHOT

samples/server/petstore/rust-axum/output/openapi-v3/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.7
15-
- Generator version: 7.12.0-SNAPSHOT
15+
- Generator version: 7.14.0-SNAPSHOT
1616

1717

1818

0 commit comments

Comments
 (0)