Skip to content

Commit 722ca19

Browse files
committed
Update
1 parent bb8181d commit 722ca19

File tree

29 files changed

+1178
-39
lines changed

29 files changed

+1178
-39
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,22 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
10001000
property.dataType = objectType;
10011001
property.isNullable = false;
10021002
}
1003+
1004+
if (property.dataType.startsWith(vecType + "<String")) {
1005+
property.vendorExtensions.put("is-vec-string", true);
1006+
} else if (property.dataType.startsWith(vecType + "<models::")) {
1007+
property.vendorExtensions.put("is-vec-nested", true);
1008+
} else if (property.dataType.startsWith(mapType + "<String, String")) {
1009+
property.vendorExtensions.put("is-map-string", true);
1010+
} else if (property.dataType.startsWith(mapType + "<String, models::")) {
1011+
property.vendorExtensions.put("is-map-nested", true);
1012+
} else if (property.dataType.startsWith(mapType + "<String")) {
1013+
property.vendorExtensions.put("is-map", true);
1014+
} else if (property.dataType.startsWith("models::")) {
1015+
property.vendorExtensions.put("is-nested", true);
1016+
} else if (stringType.equals(property.dataType)) {
1017+
property.vendorExtensions.put("is-string", true);
1018+
}
10031019
}
10041020

10051021
@Override

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ conversion = [
3939
]
4040

4141
[dependencies]
42+
ammonia = "4"
4243
async-trait = "0.1"
4344
axum = { version = "0.8", features = ["multipart"] }
4445
axum-extra = { version = "0.10", features = ["cookie", "query"] }

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

Lines changed: 277 additions & 30 deletions
Large diffs are not rendered by default.

samples/server/petstore/rust-axum/output/apikey-authorization/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ conversion = [
1717
]
1818

1919
[dependencies]
20+
ammonia = "4"
2021
async-trait = "0.1"
2122
axum = { version = "0.8", features = ["multipart"] }
2223
axum-extra = { version = "0.10", features = ["cookie", "query"] }

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

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,60 @@ use validator::Validate;
77
use crate::header;
88
use crate::{models, types::*};
99

10+
#[allow(dead_code)]
11+
pub fn check_xss_string(v: &str) -> std::result::Result<(), validator::ValidationError> {
12+
if ammonia::is_html(v) {
13+
std::result::Result::Err(validator::ValidationError::new("xss detected"))
14+
} else {
15+
std::result::Result::Ok(())
16+
}
17+
}
18+
19+
#[allow(dead_code)]
20+
pub fn check_xss_vec_string(v: &[String]) -> std::result::Result<(), validator::ValidationError> {
21+
if v.iter().any(|i| ammonia::is_html(i)) {
22+
std::result::Result::Err(validator::ValidationError::new("xss detected"))
23+
} else {
24+
std::result::Result::Ok(())
25+
}
26+
}
27+
28+
#[allow(dead_code)]
29+
pub fn check_xss_map_string(
30+
v: &std::collections::HashMap<String, String>,
31+
) -> std::result::Result<(), validator::ValidationError> {
32+
if v.keys().any(|k| ammonia::is_html(k)) || v.values().any(|v| ammonia::is_html(v)) {
33+
std::result::Result::Err(validator::ValidationError::new("xss detected"))
34+
} else {
35+
std::result::Result::Ok(())
36+
}
37+
}
38+
39+
#[allow(dead_code)]
40+
pub fn check_xss_map_nested<T>(
41+
v: &std::collections::HashMap<String, T>,
42+
) -> std::result::Result<(), validator::ValidationError>
43+
where
44+
T: validator::Validate,
45+
{
46+
if v.keys().any(|k| ammonia::is_html(k)) || v.values().any(|v| v.validate().is_err()) {
47+
std::result::Result::Err(validator::ValidationError::new("xss detected"))
48+
} else {
49+
std::result::Result::Ok(())
50+
}
51+
}
52+
53+
#[allow(dead_code)]
54+
pub fn check_xss_map<T>(
55+
v: &std::collections::HashMap<String, T>,
56+
) -> std::result::Result<(), validator::ValidationError> {
57+
if v.keys().any(|k| ammonia::is_html(k)) {
58+
std::result::Result::Err(validator::ValidationError::new("xss detected"))
59+
} else {
60+
std::result::Result::Ok(())
61+
}
62+
}
63+
1064
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
1165
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
1266
pub struct GetPaymentMethodByIdPathParams {
@@ -19,7 +73,7 @@ pub struct GetPaymentMethodByIdPathParams {
1973
pub struct Amount {
2074
/// The three-character [ISO currency code](https://docs.adyen.com/development-resources/currency-codes).
2175
#[serde(rename = "currency")]
22-
#[validate(length(min = 3, max = 3))]
76+
#[validate(length(min = 3, max = 3), custom(function = "check_xss_string"))]
2377
pub currency: String,
2478

2579
/// The amount of the transaction, in [minor units](https://docs.adyen.com/development-resources/currency-codes).
@@ -171,10 +225,12 @@ impl std::convert::TryFrom<HeaderValue> for header::IntoHeaderValue<Amount> {
171225
pub struct CheckoutError {
172226
/// Error code
173227
#[serde(rename = "code")]
228+
#[validate(custom(function = "check_xss_string"))]
174229
pub code: String,
175230

176231
/// User-friendly message
177232
#[serde(rename = "message")]
233+
#[validate(custom(function = "check_xss_string"))]
178234
pub message: String,
179235
}
180236

@@ -321,20 +377,25 @@ impl std::convert::TryFrom<HeaderValue> for header::IntoHeaderValue<CheckoutErro
321377
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
322378
pub struct Payment {
323379
#[serde(rename = "paymentMethod")]
380+
#[validate(nested)]
324381
pub payment_method: models::PaymentMethod,
325382

326383
#[serde(rename = "amount")]
384+
#[validate(nested)]
327385
pub amount: models::Amount,
328386

329387
#[serde(rename = "merchantAccount")]
388+
#[validate(custom(function = "check_xss_string"))]
330389
pub merchant_account: String,
331390

332391
#[serde(rename = "reference")]
392+
#[validate(custom(function = "check_xss_string"))]
333393
#[serde(skip_serializing_if = "Option::is_none")]
334394
pub reference: Option<String>,
335395

336396
/// Note: inline enums are not fully supported by openapi-generator
337397
#[serde(rename = "channel")]
398+
#[validate(custom(function = "check_xss_string"))]
338399
#[serde(skip_serializing_if = "Option::is_none")]
339400
pub channel: Option<String>,
340401
}
@@ -525,11 +586,13 @@ pub struct PaymentMethod {
525586
/// Name of the payment method
526587
/// Note: inline enums are not fully supported by openapi-generator
527588
#[serde(rename = "name")]
589+
#[validate(custom(function = "check_xss_string"))]
528590
#[serde(skip_serializing_if = "Option::is_none")]
529591
pub name: Option<String>,
530592

531593
/// Type of the payment method
532594
#[serde(rename = "type")]
595+
#[validate(custom(function = "check_xss_string"))]
533596
#[serde(skip_serializing_if = "Option::is_none")]
534597
pub r#type: Option<String>,
535598
}
@@ -675,11 +738,13 @@ impl std::convert::TryFrom<HeaderValue> for header::IntoHeaderValue<PaymentMetho
675738
pub struct PaymentResult {
676739
/// PSP ref
677740
#[serde(rename = "pspReference")]
741+
#[validate(custom(function = "check_xss_string"))]
678742
pub psp_reference: String,
679743

680744
/// Result code
681745
/// Note: inline enums are not fully supported by openapi-generator
682746
#[serde(rename = "resultCode")]
747+
#[validate(custom(function = "check_xss_string"))]
683748
pub result_code: String,
684749
}
685750

samples/server/petstore/rust-axum/output/apikey-auths/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ conversion = [
1717
]
1818

1919
[dependencies]
20+
ammonia = "4"
2021
async-trait = "0.1"
2122
axum = { version = "0.8", features = ["multipart"] }
2223
axum-extra = { version = "0.10", features = ["cookie", "query"] }

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

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,60 @@ use validator::Validate;
77
use crate::header;
88
use crate::{models, types::*};
99

10+
#[allow(dead_code)]
11+
pub fn check_xss_string(v: &str) -> std::result::Result<(), validator::ValidationError> {
12+
if ammonia::is_html(v) {
13+
std::result::Result::Err(validator::ValidationError::new("xss detected"))
14+
} else {
15+
std::result::Result::Ok(())
16+
}
17+
}
18+
19+
#[allow(dead_code)]
20+
pub fn check_xss_vec_string(v: &[String]) -> std::result::Result<(), validator::ValidationError> {
21+
if v.iter().any(|i| ammonia::is_html(i)) {
22+
std::result::Result::Err(validator::ValidationError::new("xss detected"))
23+
} else {
24+
std::result::Result::Ok(())
25+
}
26+
}
27+
28+
#[allow(dead_code)]
29+
pub fn check_xss_map_string(
30+
v: &std::collections::HashMap<String, String>,
31+
) -> std::result::Result<(), validator::ValidationError> {
32+
if v.keys().any(|k| ammonia::is_html(k)) || v.values().any(|v| ammonia::is_html(v)) {
33+
std::result::Result::Err(validator::ValidationError::new("xss detected"))
34+
} else {
35+
std::result::Result::Ok(())
36+
}
37+
}
38+
39+
#[allow(dead_code)]
40+
pub fn check_xss_map_nested<T>(
41+
v: &std::collections::HashMap<String, T>,
42+
) -> std::result::Result<(), validator::ValidationError>
43+
where
44+
T: validator::Validate,
45+
{
46+
if v.keys().any(|k| ammonia::is_html(k)) || v.values().any(|v| v.validate().is_err()) {
47+
std::result::Result::Err(validator::ValidationError::new("xss detected"))
48+
} else {
49+
std::result::Result::Ok(())
50+
}
51+
}
52+
53+
#[allow(dead_code)]
54+
pub fn check_xss_map<T>(
55+
v: &std::collections::HashMap<String, T>,
56+
) -> std::result::Result<(), validator::ValidationError> {
57+
if v.keys().any(|k| ammonia::is_html(k)) {
58+
std::result::Result::Err(validator::ValidationError::new("xss detected"))
59+
} else {
60+
std::result::Result::Ok(())
61+
}
62+
}
63+
1064
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
1165
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
1266
pub struct GetPaymentMethodByIdPathParams {
@@ -19,7 +73,7 @@ pub struct GetPaymentMethodByIdPathParams {
1973
pub struct Amount {
2074
/// The three-character [ISO currency code](https://docs.adyen.com/development-resources/currency-codes).
2175
#[serde(rename = "currency")]
22-
#[validate(length(min = 3, max = 3))]
76+
#[validate(length(min = 3, max = 3), custom(function = "check_xss_string"))]
2377
pub currency: String,
2478

2579
/// The amount of the transaction, in [minor units](https://docs.adyen.com/development-resources/currency-codes).
@@ -171,10 +225,12 @@ impl std::convert::TryFrom<HeaderValue> for header::IntoHeaderValue<Amount> {
171225
pub struct CheckoutError {
172226
/// Error code
173227
#[serde(rename = "code")]
228+
#[validate(custom(function = "check_xss_string"))]
174229
pub code: String,
175230

176231
/// User-friendly message
177232
#[serde(rename = "message")]
233+
#[validate(custom(function = "check_xss_string"))]
178234
pub message: String,
179235
}
180236

@@ -321,20 +377,25 @@ impl std::convert::TryFrom<HeaderValue> for header::IntoHeaderValue<CheckoutErro
321377
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
322378
pub struct Payment {
323379
#[serde(rename = "paymentMethod")]
380+
#[validate(nested)]
324381
pub payment_method: models::PaymentMethod,
325382

326383
#[serde(rename = "amount")]
384+
#[validate(nested)]
327385
pub amount: models::Amount,
328386

329387
#[serde(rename = "merchantAccount")]
388+
#[validate(custom(function = "check_xss_string"))]
330389
pub merchant_account: String,
331390

332391
#[serde(rename = "reference")]
392+
#[validate(custom(function = "check_xss_string"))]
333393
#[serde(skip_serializing_if = "Option::is_none")]
334394
pub reference: Option<String>,
335395

336396
/// Note: inline enums are not fully supported by openapi-generator
337397
#[serde(rename = "channel")]
398+
#[validate(custom(function = "check_xss_string"))]
338399
#[serde(skip_serializing_if = "Option::is_none")]
339400
pub channel: Option<String>,
340401
}
@@ -525,11 +586,13 @@ pub struct PaymentMethod {
525586
/// Name of the payment method
526587
/// Note: inline enums are not fully supported by openapi-generator
527588
#[serde(rename = "name")]
589+
#[validate(custom(function = "check_xss_string"))]
528590
#[serde(skip_serializing_if = "Option::is_none")]
529591
pub name: Option<String>,
530592

531593
/// Type of the payment method
532594
#[serde(rename = "type")]
595+
#[validate(custom(function = "check_xss_string"))]
533596
#[serde(skip_serializing_if = "Option::is_none")]
534597
pub r#type: Option<String>,
535598
}
@@ -675,11 +738,13 @@ impl std::convert::TryFrom<HeaderValue> for header::IntoHeaderValue<PaymentMetho
675738
pub struct PaymentResult {
676739
/// PSP ref
677740
#[serde(rename = "pspReference")]
741+
#[validate(custom(function = "check_xss_string"))]
678742
pub psp_reference: String,
679743

680744
/// Result code
681745
/// Note: inline enums are not fully supported by openapi-generator
682746
#[serde(rename = "resultCode")]
747+
#[validate(custom(function = "check_xss_string"))]
683748
pub result_code: String,
684749
}
685750

samples/server/petstore/rust-axum/output/multipart-v3/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ conversion = [
1717
]
1818

1919
[dependencies]
20+
ammonia = "4"
2021
async-trait = "0.1"
2122
axum = { version = "0.8", features = ["multipart"] }
2223
axum-extra = { version = "0.10", features = ["cookie", "query"] }

0 commit comments

Comments
 (0)