From 061d574b4ab201f5d28351b3f8a29271d8b019a3 Mon Sep 17 00:00:00 2001 From: David Steele Date: Wed, 3 Sep 2025 09:08:18 +0100 Subject: [PATCH] fix: Resolve issue21805 rust-server compilation failure with large maximums by handling minimum and maximum using BigInt instead of longValue. --- .../org/openapitools/codegen/utils/ModelUtils.java | 4 ++-- .../src/main/resources/rust-server/models.mustache | 6 +++--- .../src/test/resources/3_0/rust-server/openapi-v3.yaml | 3 +++ .../output/openapi-v3/api/openapi.yaml | 5 ++++- .../output/openapi-v3/docs/ObjectParam.md | 2 +- .../output/openapi-v3/src/models.rs | 9 ++++++--- .../rust-server/output/openapi-v3/api/openapi.yaml | 5 ++++- .../rust-server/output/openapi-v3/docs/ObjectParam.md | 2 +- .../rust-server/output/openapi-v3/src/models.rs | 9 ++++++--- .../src/models.rs | 10 +++++----- 10 files changed, 35 insertions(+), 20 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java index 82ba131f2b14..7fccbeefc0ec 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java @@ -1941,7 +1941,7 @@ private static void setNumericValidations(Schema schema, BigDecimal multipleOf, if (multipleOf != null) target.setMultipleOf(multipleOf); if (minimum != null) { if (isIntegerSchema(schema)) { - target.setMinimum(String.valueOf(minimum.longValue())); + target.setMinimum(String.valueOf(minimum.toBigInteger())); } else { target.setMinimum(String.valueOf(minimum)); } @@ -1949,7 +1949,7 @@ private static void setNumericValidations(Schema schema, BigDecimal multipleOf, } if (maximum != null) { if (isIntegerSchema(schema)) { - target.setMaximum(String.valueOf(maximum.longValue())); + target.setMaximum(String.valueOf(maximum.toBigInteger())); } else { target.setMaximum(String.valueOf(maximum)); } diff --git a/modules/openapi-generator/src/main/resources/rust-server/models.mustache b/modules/openapi-generator/src/main/resources/rust-server/models.mustache index b56876d6eb47..6ea7302dd1a9 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/models.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/models.mustache @@ -312,15 +312,15 @@ pub struct {{{classname}}} { {{/pattern}} {{#maximum}} {{#minimum}} - range(min = {{minimum}}, max = {{maximum}}), + range(min = {{minimum}}{{dataType}}, max = {{maximum}}{{dataType}}), {{/minimum}} {{^minimum}} - range(max = {{maximum}}), + range(max = {{maximum}}{{dataType}}), {{/minimum}} {{/maximum}} {{#minimum}} {{^maximum}} - range(min = {{minimum}}), + range(min = {{minimum}}{{dataType}}), {{/maximum}} {{/minimum}} {{#maxItems}} diff --git a/modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml b/modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml index a785ca8bb030..cad4929930ea 100644 --- a/modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml @@ -693,6 +693,9 @@ components: type: boolean optionalParam: type: integer + minimum: 1 + maximum: 10000000000000000000 + example: 100 ObjectHeader: type: object required: diff --git a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/api/openapi.yaml b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/api/openapi.yaml index 326b81e29b6f..3be49f8eb8d7 100644 --- a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/api/openapi.yaml +++ b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/api/openapi.yaml @@ -735,11 +735,14 @@ components: ObjectParam: example: requiredParam: true - optionalParam: 0 + optionalParam: 100 properties: requiredParam: type: boolean optionalParam: + example: 100 + maximum: 10000000000000000000 + minimum: 1 type: integer required: - requiredParam diff --git a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/docs/ObjectParam.md b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/docs/ObjectParam.md index caac197917ab..421fdc547557 100644 --- a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/docs/ObjectParam.md +++ b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/docs/ObjectParam.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **required_param** | **bool** | | -**optional_param** | **i32** | | [optional] [default to None] +**optional_param** | **u64** | | [optional] [default to None] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/models.rs b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/models.rs index 84f8141a3cbc..e98c13654e73 100644 --- a/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/models.rs +++ b/samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/models.rs @@ -3597,8 +3597,11 @@ pub struct ObjectParam { pub required_param: bool, #[serde(rename = "optionalParam")] + #[validate( + range(min = 1, max = 10000000000000000000), + )] #[serde(skip_serializing_if="Option::is_none")] - pub optional_param: Option, + pub optional_param: Option, } @@ -3645,7 +3648,7 @@ impl std::str::FromStr for ObjectParam { #[allow(dead_code)] struct IntermediateRep { pub required_param: Vec, - pub optional_param: Vec, + pub optional_param: Vec, } let mut intermediate_rep = IntermediateRep::default(); @@ -3666,7 +3669,7 @@ impl std::str::FromStr for ObjectParam { #[allow(clippy::redundant_clone)] "requiredParam" => intermediate_rep.required_param.push(::from_str(val).map_err(|x| x.to_string())?), #[allow(clippy::redundant_clone)] - "optionalParam" => intermediate_rep.optional_param.push(::from_str(val).map_err(|x| x.to_string())?), + "optionalParam" => intermediate_rep.optional_param.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing ObjectParam".to_string()) } } diff --git a/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml b/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml index 326b81e29b6f..3be49f8eb8d7 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml +++ b/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml @@ -735,11 +735,14 @@ components: ObjectParam: example: requiredParam: true - optionalParam: 0 + optionalParam: 100 properties: requiredParam: type: boolean optionalParam: + example: 100 + maximum: 10000000000000000000 + minimum: 1 type: integer required: - requiredParam diff --git a/samples/server/petstore/rust-server/output/openapi-v3/docs/ObjectParam.md b/samples/server/petstore/rust-server/output/openapi-v3/docs/ObjectParam.md index caac197917ab..421fdc547557 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/docs/ObjectParam.md +++ b/samples/server/petstore/rust-server/output/openapi-v3/docs/ObjectParam.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **required_param** | **bool** | | -**optional_param** | **i32** | | [optional] [default to None] +**optional_param** | **u64** | | [optional] [default to None] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/models.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/models.rs index c24dfb69f4c5..7c9622b88606 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/models.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/models.rs @@ -3597,8 +3597,11 @@ pub struct ObjectParam { pub required_param: bool, #[serde(rename = "optionalParam")] + #[validate( + range(min = 1u64, max = 10000000000000000000u64), + )] #[serde(skip_serializing_if="Option::is_none")] - pub optional_param: Option, + pub optional_param: Option, } @@ -3645,7 +3648,7 @@ impl std::str::FromStr for ObjectParam { #[allow(dead_code)] struct IntermediateRep { pub required_param: Vec, - pub optional_param: Vec, + pub optional_param: Vec, } let mut intermediate_rep = IntermediateRep::default(); @@ -3666,7 +3669,7 @@ impl std::str::FromStr for ObjectParam { #[allow(clippy::redundant_clone)] "requiredParam" => intermediate_rep.required_param.push(::from_str(val).map_err(|x| x.to_string())?), #[allow(clippy::redundant_clone)] - "optionalParam" => intermediate_rep.optional_param.push(::from_str(val).map_err(|x| x.to_string())?), + "optionalParam" => intermediate_rep.optional_param.push(::from_str(val).map_err(|x| x.to_string())?), _ => return std::result::Result::Err("Unexpected key while parsing ObjectParam".to_string()) } } diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs index be2a06d7643e..c868af7c03d1 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs @@ -3857,14 +3857,14 @@ impl FindPetsByStatusStatusParameterInner { pub struct FormatTest { #[serde(rename = "integer")] #[validate( - range(min = 10, max = 100), + range(min = 10u8, max = 100u8), )] #[serde(skip_serializing_if="Option::is_none")] pub integer: Option, #[serde(rename = "int32")] #[validate( - range(min = 20, max = 200), + range(min = 20u32, max = 200u32), )] #[serde(skip_serializing_if="Option::is_none")] pub int32: Option, @@ -3875,20 +3875,20 @@ pub struct FormatTest { #[serde(rename = "number")] #[validate( - range(min = 32.1, max = 543.2), + range(min = 32.1f64, max = 543.2f64), )] pub number: f64, #[serde(rename = "float")] #[validate( - range(min = 54.3, max = 987.6), + range(min = 54.3f32, max = 987.6f32), )] #[serde(skip_serializing_if="Option::is_none")] pub float: Option, #[serde(rename = "double")] #[validate( - range(min = 67.8, max = 123.4), + range(min = 67.8f64, max = 123.4f64), )] #[serde(skip_serializing_if="Option::is_none")] pub double: Option,