Skip to content

Commit 974790d

Browse files
committed
Update
1 parent ac02fe7 commit 974790d

File tree

8 files changed

+80
-77
lines changed

8 files changed

+80
-77
lines changed

bin/configs/manual/rust-axum-apikey-authorization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ additionalProperties:
88
packageName: apikey-authorization
99
basicAuthorization: true
1010
basicAnalytic: true
11+
ownedRequest: true
1112
globalProperties:
1213
skipFormModel: false
1314
enablePostProcessFile: true

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege
6363
private String externCrateName;
6464
private Boolean basicAuthorization = false;
6565
private Boolean basicAnalytic = false;
66+
private Boolean ownedRequest = false;
6667

6768
// Types
6869
private static final String uuidType = "uuid::Uuid";
@@ -330,6 +331,12 @@ public void processOpts() {
330331
} else {
331332
additionalProperties.put("basicAnalytic", basicAnalytic);
332333
}
334+
335+
if (additionalProperties.containsKey("ownedRequest")) {
336+
ownedRequest = convertPropertyToBooleanAndWriteBack("ownedRequest");
337+
} else {
338+
additionalProperties.put("ownedRequest", ownedRequest);
339+
}
333340
}
334341

335342
private void setPackageName(String packageName) {
@@ -748,6 +755,11 @@ public OperationsMap postProcessOperationsWithModels(final OperationsMap operati
748755
operations.getOperation().forEach(op -> op.vendorExtensions.put("basicAnalytic", true));
749756
}
750757

758+
if (ownedRequest) {
759+
operations.put("ownedRequest", true);
760+
operations.getOperation().forEach(op -> op.vendorExtensions.put("ownedRequest", true));
761+
}
762+
751763
return operationsMap;
752764
}
753765

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub trait {{classnamePascalCase}}Authorization {
5454
{{/x-consumes-plain-text}}
5555
{{#x-consumes-plain-text}}
5656
{{#isString}}
57-
body: &str,
57+
body: &String,
5858
{{/isString}}
5959
{{^isString}}
6060
body: &Bytes,
@@ -102,36 +102,36 @@ pub trait {{classnamePascalCase}}<E: std::fmt::Debug + Send + Sync + 'static = (
102102
async fn {{{x-operation-id}}}(
103103
&self,
104104
{{#basicAnalytic}}event: &mut super::event::Event,{{/basicAnalytic}}
105-
method: &Method,
106-
host: &Host,
107-
cookies: &CookieJar,
105+
method: {{^ownedRequest}}&{{/ownedRequest}}Method,
106+
host: {{^ownedRequest}}&{{/ownedRequest}}Host,
107+
cookies: {{^ownedRequest}}&{{/ownedRequest}}CookieJar,
108108
{{#vendorExtensions}}
109109
{{#x-has-auth-methods}}
110-
claims: &Self::Claims,
110+
claims: {{^ownedRequest}}&{{/ownedRequest}}Self::Claims,
111111
{{/x-has-auth-methods}}
112112
{{/vendorExtensions}}
113113
{{#headerParams.size}}
114-
header_params: &models::{{{operationIdCamelCase}}}HeaderParams,
114+
header_params: {{^ownedRequest}}&{{/ownedRequest}}models::{{{operationIdCamelCase}}}HeaderParams,
115115
{{/headerParams.size}}
116116
{{#pathParams.size}}
117-
path_params: &models::{{{operationIdCamelCase}}}PathParams,
117+
path_params: {{^ownedRequest}}&{{/ownedRequest}}models::{{{operationIdCamelCase}}}PathParams,
118118
{{/pathParams.size}}
119119
{{#queryParams.size}}
120-
query_params: &models::{{{operationIdCamelCase}}}QueryParams,
120+
query_params: {{^ownedRequest}}&{{/ownedRequest}}models::{{{operationIdCamelCase}}}QueryParams,
121121
{{/queryParams.size}}
122122
{{^x-consumes-multipart-related}}
123123
{{^x-consumes-multipart}}
124124
{{#bodyParam}}
125125
{{#vendorExtensions}}
126126
{{^x-consumes-plain-text}}
127-
body: &{{^required}}Option<{{/required}}{{{dataType}}}{{^required}}>{{/required}},
127+
body: {{^ownedRequest}}&{{/ownedRequest}}{{^required}}Option<{{/required}}{{{dataType}}}{{^required}}>{{/required}},
128128
{{/x-consumes-plain-text}}
129129
{{#x-consumes-plain-text}}
130130
{{#isString}}
131-
body: &str,
131+
body: {{^ownedRequest}}&{{/ownedRequest}}String,
132132
{{/isString}}
133133
{{^isString}}
134-
body: &Bytes,
134+
body: {{^ownedRequest}}&{{/ownedRequest}}Bytes,
135135
{{/isString}}
136136
{{/x-consumes-plain-text}}
137137
{{/vendorExtensions}}

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -245,32 +245,32 @@ where
245245
{{/x-has-auth-methods}}
246246
{{/vendorExtensions}}
247247

248-
{{#basicAnalytic}}let mut event = apis::event::Event::default();{{/basicAnalytic}}
249-
let result = api_impl.as_ref().{{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}(
248+
{{#basicAnalytic}}let mut event = apis::event::Event::default();{{/basicAnalytic}}
249+
let result = api_impl.as_ref().{{#vendorExtensions}}{{{x-operation-id}}}{{/vendorExtensions}}(
250250
{{#basicAnalytic}}&mut event,{{/basicAnalytic}}
251-
&method,
252-
&host,
253-
&cookies,
251+
{{^ownedRequest}}&{{/ownedRequest}}method,
252+
{{^ownedRequest}}&{{/ownedRequest}}host,
253+
{{^ownedRequest}}&{{/ownedRequest}}cookies,
254254
{{#vendorExtensions}}
255255
{{#x-has-auth-methods}}
256-
&claims,
256+
{{^ownedRequest}}&{{/ownedRequest}}claims,
257257
{{/x-has-auth-methods}}
258258
{{/vendorExtensions}}
259259
{{#headerParams.size}}
260-
&header_params,
260+
{{^ownedRequest}}&{{/ownedRequest}}header_params,
261261
{{/headerParams.size}}
262262
{{#pathParams.size}}
263-
&path_params,
263+
{{^ownedRequest}}&{{/ownedRequest}}path_params,
264264
{{/pathParams.size}}
265265
{{#queryParams.size}}
266-
&query_params,
266+
{{^ownedRequest}}&{{/ownedRequest}}query_params,
267267
{{/queryParams.size}}
268268
{{#vendorExtensions}}
269269
{{^x-consumes-multipart-related}}
270270
{{^x-consumes-multipart}}
271271
{{#bodyParams}}
272272
{{#-first}}
273-
&body,
273+
{{^ownedRequest}}&{{/ownedRequest}}body,
274274
{{/-first}}
275275
{{/bodyParams}}
276276
{{/x-consumes-multipart}}
@@ -404,10 +404,15 @@ where
404404
},
405405
{{/responses}}
406406
},
407-
Err(why) => {
408-
// Application code returned an error. This should not happen, as the implementation should
409-
// return a valid response.
410-
return api_impl.as_ref().handle_error(&method, &host, &cookies, why).await;
407+
Err({{#ownedRequest}}_{{/ownedRequest}}why) => {
408+
{{^ownedRequest}}
409+
// Application code returned an error. This should not happen, as the implementation should
410+
// return a valid response.
411+
return api_impl.as_ref().handle_error(&method, &host, &cookies, why).await;
412+
{{/ownedRequest}}
413+
{{#ownedRequest}}
414+
return response_with_status_code_only(StatusCode::INTERNAL_SERVER_ERROR);
415+
{{/ownedRequest}}
411416
},
412417
};
413418

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ pub trait Payments<E: std::fmt::Debug + Send + Sync + 'static = ()>:
9494
async fn get_payment_method_by_id(
9595
&self,
9696
event: &mut super::event::Event,
97-
method: &Method,
98-
host: &Host,
99-
cookies: &CookieJar,
100-
claims: &Self::Claims,
101-
path_params: &models::GetPaymentMethodByIdPathParams,
97+
method: Method,
98+
host: Host,
99+
cookies: CookieJar,
100+
claims: Self::Claims,
101+
path_params: models::GetPaymentMethodByIdPathParams,
102102
) -> Result<GetPaymentMethodByIdResponse, E>;
103103

104104
/// Get payment methods.
@@ -107,10 +107,10 @@ pub trait Payments<E: std::fmt::Debug + Send + Sync + 'static = ()>:
107107
async fn get_payment_methods(
108108
&self,
109109
event: &mut super::event::Event,
110-
method: &Method,
111-
host: &Host,
112-
cookies: &CookieJar,
113-
claims: &Self::Claims,
110+
method: Method,
111+
host: Host,
112+
cookies: CookieJar,
113+
claims: Self::Claims,
114114
) -> Result<GetPaymentMethodsResponse, E>;
115115

116116
/// Make a payment.
@@ -119,10 +119,10 @@ pub trait Payments<E: std::fmt::Debug + Send + Sync + 'static = ()>:
119119
async fn post_make_payment(
120120
&self,
121121
event: &mut super::event::Event,
122-
method: &Method,
123-
host: &Host,
124-
cookies: &CookieJar,
125-
claims: &Self::Claims,
126-
body: &Option<models::Payment>,
122+
method: Method,
123+
host: Host,
124+
cookies: CookieJar,
125+
claims: Self::Claims,
126+
body: Option<models::Payment>,
127127
) -> Result<PostMakePaymentResponse, E>;
128128
}

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

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ where
116116
let mut event = apis::event::Event::default();
117117
let result = api_impl
118118
.as_ref()
119-
.get_payment_method_by_id(&mut event, &method, &host, &cookies, &claims, &path_params)
119+
.get_payment_method_by_id(&mut event, method, host, cookies, claims, path_params)
120120
.await;
121121

122122
let mut response = Response::builder();
@@ -170,13 +170,8 @@ where
170170
response.body(Body::from(body_content))
171171
}
172172
},
173-
Err(why) => {
174-
// Application code returned an error. This should not happen, as the implementation should
175-
// return a valid response.
176-
return api_impl
177-
.as_ref()
178-
.handle_error(&method, &host, &cookies, why)
179-
.await;
173+
Err(_why) => {
174+
return response_with_status_code_only(StatusCode::INTERNAL_SERVER_ERROR);
180175
}
181176
};
182177

@@ -284,7 +279,7 @@ where
284279
let mut event = apis::event::Event::default();
285280
let result = api_impl
286281
.as_ref()
287-
.get_payment_methods(&mut event, &method, &host, &cookies, &claims)
282+
.get_payment_methods(&mut event, method, host, cookies, claims)
288283
.await;
289284

290285
let mut response = Response::builder();
@@ -315,13 +310,8 @@ where
315310
response.body(Body::from(body_content))
316311
}
317312
},
318-
Err(why) => {
319-
// Application code returned an error. This should not happen, as the implementation should
320-
// return a valid response.
321-
return api_impl
322-
.as_ref()
323-
.handle_error(&method, &host, &cookies, why)
324-
.await;
313+
Err(_why) => {
314+
return response_with_status_code_only(StatusCode::INTERNAL_SERVER_ERROR);
325315
}
326316
};
327317

@@ -449,7 +439,7 @@ where
449439
let mut event = apis::event::Event::default();
450440
let result = api_impl
451441
.as_ref()
452-
.post_make_payment(&mut event, &method, &host, &cookies, &claims, &body)
442+
.post_make_payment(&mut event, method, host, cookies, claims, body)
453443
.await;
454444

455445
let mut response = Response::builder();
@@ -503,13 +493,8 @@ where
503493
response.body(Body::from(body_content))
504494
}
505495
},
506-
Err(why) => {
507-
// Application code returned an error. This should not happen, as the implementation should
508-
// return a valid response.
509-
return api_impl
510-
.as_ref()
511-
.handle_error(&method, &host, &cookies, why)
512-
.await;
496+
Err(_why) => {
497+
return response_with_status_code_only(StatusCode::INTERNAL_SERVER_ERROR);
513498
}
514499
};
515500

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,9 +1099,9 @@ where
10991099
},
11001100
},
11011101
Err(why) => {
1102-
// Application code returned an error. This should not happen, as the implementation should
1103-
// return a valid response.
1104-
return api_impl.as_ref().handle_error(&method, &host, &cookies, why).await;
1102+
// Application code returned an error. This should not happen, as the implementation should
1103+
// return a valid response.
1104+
return api_impl.as_ref().handle_error(&method, &host, &cookies, why).await;
11051105
},
11061106
};
11071107

@@ -1176,9 +1176,9 @@ where
11761176
},
11771177
},
11781178
Err(why) => {
1179-
// Application code returned an error. This should not happen, as the implementation should
1180-
// return a valid response.
1181-
return api_impl.as_ref().handle_error(&method, &host, &cookies, why).await;
1179+
// Application code returned an error. This should not happen, as the implementation should
1180+
// return a valid response.
1181+
return api_impl.as_ref().handle_error(&method, &host, &cookies, why).await;
11821182
},
11831183
};
11841184

@@ -1438,9 +1438,9 @@ where
14381438
},
14391439
},
14401440
Err(why) => {
1441-
// Application code returned an error. This should not happen, as the implementation should
1442-
// return a valid response.
1443-
return api_impl.as_ref().handle_error(&method, &host, &cookies, why).await;
1441+
// Application code returned an error. This should not happen, as the implementation should
1442+
// return a valid response.
1443+
return api_impl.as_ref().handle_error(&method, &host, &cookies, why).await;
14441444
},
14451445
};
14461446

@@ -2015,9 +2015,9 @@ where
20152015
},
20162016
},
20172017
Err(why) => {
2018-
// Application code returned an error. This should not happen, as the implementation should
2019-
// return a valid response.
2020-
return api_impl.as_ref().handle_error(&method, &host, &cookies, why).await;
2018+
// Application code returned an error. This should not happen, as the implementation should
2019+
// return a valid response.
2020+
return api_impl.as_ref().handle_error(&method, &host, &cookies, why).await;
20212021
},
20222022
};
20232023

samples/server/petstore/rust-axum/output/rust-axum-test/src/apis/default.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub trait Default<E: std::fmt::Debug + Send + Sync + 'static = ()>: super::Error
142142
method: &Method,
143143
host: &Host,
144144
cookies: &CookieJar,
145-
body: &str,
145+
body: &String,
146146
) -> Result<HtmlPostResponse, E>;
147147

148148
/// PostYaml - POST /post-yaml
@@ -152,7 +152,7 @@ pub trait Default<E: std::fmt::Debug + Send + Sync + 'static = ()>: super::Error
152152
method: &Method,
153153
host: &Host,
154154
cookies: &CookieJar,
155-
body: &str,
155+
body: &String,
156156
) -> Result<PostYamlResponse, E>;
157157

158158
/// Get an arbitrary JSON blob..

0 commit comments

Comments
 (0)