Skip to content

Commit 5daef3e

Browse files
authored
fix: Resolve issue21805 rust-server compilation failure with large maximums by handling minimum and maximum using BigInt instead of longValue. (OpenAPITools#21875)
1 parent 6e443f1 commit 5daef3e

File tree

10 files changed

+35
-20
lines changed

10 files changed

+35
-20
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,15 +1941,15 @@ private static void setNumericValidations(Schema schema, BigDecimal multipleOf,
19411941
if (multipleOf != null) target.setMultipleOf(multipleOf);
19421942
if (minimum != null) {
19431943
if (isIntegerSchema(schema)) {
1944-
target.setMinimum(String.valueOf(minimum.longValue()));
1944+
target.setMinimum(String.valueOf(minimum.toBigInteger()));
19451945
} else {
19461946
target.setMinimum(String.valueOf(minimum));
19471947
}
19481948
if (exclusiveMinimum != null) target.setExclusiveMinimum(exclusiveMinimum);
19491949
}
19501950
if (maximum != null) {
19511951
if (isIntegerSchema(schema)) {
1952-
target.setMaximum(String.valueOf(maximum.longValue()));
1952+
target.setMaximum(String.valueOf(maximum.toBigInteger()));
19531953
} else {
19541954
target.setMaximum(String.valueOf(maximum));
19551955
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,15 @@ pub struct {{{classname}}} {
312312
{{/pattern}}
313313
{{#maximum}}
314314
{{#minimum}}
315-
range(min = {{minimum}}, max = {{maximum}}),
315+
range(min = {{minimum}}{{dataType}}, max = {{maximum}}{{dataType}}),
316316
{{/minimum}}
317317
{{^minimum}}
318-
range(max = {{maximum}}),
318+
range(max = {{maximum}}{{dataType}}),
319319
{{/minimum}}
320320
{{/maximum}}
321321
{{#minimum}}
322322
{{^maximum}}
323-
range(min = {{minimum}}),
323+
range(min = {{minimum}}{{dataType}}),
324324
{{/maximum}}
325325
{{/minimum}}
326326
{{#maxItems}}

modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,9 @@ components:
693693
type: boolean
694694
optionalParam:
695695
type: integer
696+
minimum: 1
697+
maximum: 10000000000000000000
698+
example: 100
696699
ObjectHeader:
697700
type: object
698701
required:

samples/server/petstore/rust-server-deprecated/output/openapi-v3/api/openapi.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,11 +735,14 @@ components:
735735
ObjectParam:
736736
example:
737737
requiredParam: true
738-
optionalParam: 0
738+
optionalParam: 100
739739
properties:
740740
requiredParam:
741741
type: boolean
742742
optionalParam:
743+
example: 100
744+
maximum: 10000000000000000000
745+
minimum: 1
743746
type: integer
744747
required:
745748
- requiredParam

samples/server/petstore/rust-server-deprecated/output/openapi-v3/docs/ObjectParam.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
66
**required_param** | **bool** | |
7-
**optional_param** | **i32** | | [optional] [default to None]
7+
**optional_param** | **u64** | | [optional] [default to None]
88

99
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
1010

samples/server/petstore/rust-server-deprecated/output/openapi-v3/src/models.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3597,8 +3597,11 @@ pub struct ObjectParam {
35973597
pub required_param: bool,
35983598

35993599
#[serde(rename = "optionalParam")]
3600+
#[validate(
3601+
range(min = 1, max = 10000000000000000000),
3602+
)]
36003603
#[serde(skip_serializing_if="Option::is_none")]
3601-
pub optional_param: Option<i32>,
3604+
pub optional_param: Option<u64>,
36023605

36033606
}
36043607

@@ -3645,7 +3648,7 @@ impl std::str::FromStr for ObjectParam {
36453648
#[allow(dead_code)]
36463649
struct IntermediateRep {
36473650
pub required_param: Vec<bool>,
3648-
pub optional_param: Vec<i32>,
3651+
pub optional_param: Vec<u64>,
36493652
}
36503653

36513654
let mut intermediate_rep = IntermediateRep::default();
@@ -3666,7 +3669,7 @@ impl std::str::FromStr for ObjectParam {
36663669
#[allow(clippy::redundant_clone)]
36673670
"requiredParam" => intermediate_rep.required_param.push(<bool as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?),
36683671
#[allow(clippy::redundant_clone)]
3669-
"optionalParam" => intermediate_rep.optional_param.push(<i32 as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?),
3672+
"optionalParam" => intermediate_rep.optional_param.push(<u64 as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?),
36703673
_ => return std::result::Result::Err("Unexpected key while parsing ObjectParam".to_string())
36713674
}
36723675
}

samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,11 +735,14 @@ components:
735735
ObjectParam:
736736
example:
737737
requiredParam: true
738-
optionalParam: 0
738+
optionalParam: 100
739739
properties:
740740
requiredParam:
741741
type: boolean
742742
optionalParam:
743+
example: 100
744+
maximum: 10000000000000000000
745+
minimum: 1
743746
type: integer
744747
required:
745748
- requiredParam

samples/server/petstore/rust-server/output/openapi-v3/docs/ObjectParam.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
66
**required_param** | **bool** | |
7-
**optional_param** | **i32** | | [optional] [default to None]
7+
**optional_param** | **u64** | | [optional] [default to None]
88

99
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
1010

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3597,8 +3597,11 @@ pub struct ObjectParam {
35973597
pub required_param: bool,
35983598

35993599
#[serde(rename = "optionalParam")]
3600+
#[validate(
3601+
range(min = 1u64, max = 10000000000000000000u64),
3602+
)]
36003603
#[serde(skip_serializing_if="Option::is_none")]
3601-
pub optional_param: Option<i32>,
3604+
pub optional_param: Option<u64>,
36023605

36033606
}
36043607

@@ -3645,7 +3648,7 @@ impl std::str::FromStr for ObjectParam {
36453648
#[allow(dead_code)]
36463649
struct IntermediateRep {
36473650
pub required_param: Vec<bool>,
3648-
pub optional_param: Vec<i32>,
3651+
pub optional_param: Vec<u64>,
36493652
}
36503653

36513654
let mut intermediate_rep = IntermediateRep::default();
@@ -3666,7 +3669,7 @@ impl std::str::FromStr for ObjectParam {
36663669
#[allow(clippy::redundant_clone)]
36673670
"requiredParam" => intermediate_rep.required_param.push(<bool as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?),
36683671
#[allow(clippy::redundant_clone)]
3669-
"optionalParam" => intermediate_rep.optional_param.push(<i32 as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?),
3672+
"optionalParam" => intermediate_rep.optional_param.push(<u64 as std::str::FromStr>::from_str(val).map_err(|x| x.to_string())?),
36703673
_ => return std::result::Result::Err("Unexpected key while parsing ObjectParam".to_string())
36713674
}
36723675
}

samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3857,14 +3857,14 @@ impl FindPetsByStatusStatusParameterInner {
38573857
pub struct FormatTest {
38583858
#[serde(rename = "integer")]
38593859
#[validate(
3860-
range(min = 10, max = 100),
3860+
range(min = 10u8, max = 100u8),
38613861
)]
38623862
#[serde(skip_serializing_if="Option::is_none")]
38633863
pub integer: Option<u8>,
38643864

38653865
#[serde(rename = "int32")]
38663866
#[validate(
3867-
range(min = 20, max = 200),
3867+
range(min = 20u32, max = 200u32),
38683868
)]
38693869
#[serde(skip_serializing_if="Option::is_none")]
38703870
pub int32: Option<u32>,
@@ -3875,20 +3875,20 @@ pub struct FormatTest {
38753875

38763876
#[serde(rename = "number")]
38773877
#[validate(
3878-
range(min = 32.1, max = 543.2),
3878+
range(min = 32.1f64, max = 543.2f64),
38793879
)]
38803880
pub number: f64,
38813881

38823882
#[serde(rename = "float")]
38833883
#[validate(
3884-
range(min = 54.3, max = 987.6),
3884+
range(min = 54.3f32, max = 987.6f32),
38853885
)]
38863886
#[serde(skip_serializing_if="Option::is_none")]
38873887
pub float: Option<f32>,
38883888

38893889
#[serde(rename = "double")]
38903890
#[validate(
3891-
range(min = 67.8, max = 123.4),
3891+
range(min = 67.8f64, max = 123.4f64),
38923892
)]
38933893
#[serde(skip_serializing_if="Option::is_none")]
38943894
pub double: Option<f64>,

0 commit comments

Comments
 (0)