Skip to content

Commit c34d593

Browse files
authored
fix: Fix rust-server model generation following serde_valid upgrade (#22737)
1 parent 9a0d711 commit c34d593

File tree

5 files changed

+75
-28
lines changed

5 files changed

+75
-28
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ impl std::ops::DerefMut for {{{classname}}} {
106106
}
107107
}
108108
109+
{{^hasConflictingModelNames}}
110+
#[cfg(feature = "validate")]
111+
impl serde_valid::validation::ValidateCompositedMinLength for {{{classname}}} {
112+
fn validate_composited_min_length(
113+
&self,
114+
_min_length: usize,
115+
) -> Result<(), serde_valid::validation::Composited<serde_valid::validation::error::MinLengthError>> {
116+
Ok(())
117+
}
118+
}
119+
{{/hasConflictingModelNames}}
109120
{{#exts.x-to-string-support}}
110121
{{#exts.x-is-string}}
111122
impl std::fmt::Display for {{{classname}}} {
@@ -364,23 +375,24 @@ pub struct {{{classname}}} {
364375
)]
365376
{{/hasConflictingModelNames}}
366377
{{/hasValidation}}
378+
{{#required}}
367379
{{^hasConflictingModelNames}}{{>validate}}{{/hasConflictingModelNames}}
368380
{{^hasConflictingModelNames}}
369381
{{#exts.x-needs-nested-validation}}
370-
#[cfg_attr(feature = "validate", validate)]
382+
{{^minLength}}{{^maxLength}}{{^minItems}}{{^maxItems}}#[cfg_attr(feature = "validate", validate)]{{/maxItems}}{{/minItems}}{{/maxLength}}{{/minLength}}
371383
{{/exts.x-needs-nested-validation}}
372384
{{/hasConflictingModelNames}}
373-
{{#required}}
374385
pub {{{name}}}: {{{dataType}}},
375386
{{/required}}
376387
{{^required}}
377388
{{#isNullable}}
378389
#[serde(deserialize_with = "swagger::nullable_format::deserialize_optional_nullable")]
379390
#[serde(default = "swagger::nullable_format::default_optional_nullable")]
380391
{{/isNullable}}
392+
{{^hasConflictingModelNames}}{{>validate}}{{/hasConflictingModelNames}}
381393
{{^hasConflictingModelNames}}
382394
{{#exts.x-needs-nested-validation}}
383-
#[cfg_attr(feature = "validate", validate)]
395+
{{^minLength}}{{^maxLength}}{{^minItems}}{{^maxItems}}#[cfg_attr(feature = "validate", validate)]{{/maxItems}}{{/minItems}}{{/maxLength}}{{/minLength}}
384396
{{/exts.x-needs-nested-validation}}
385397
{{/hasConflictingModelNames}}
386398
#[serde(skip_serializing_if="Option::is_none")]

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use serde_valid::Validate;
1313
pub struct MultipartRelatedRequest {
1414
#[serde(rename = "object_field")]
1515

16-
#[cfg_attr(feature = "validate", validate)]
1716
#[cfg_attr(feature = "validate", validate)]
1817
#[serde(skip_serializing_if="Option::is_none")]
1918
pub object_field: Option<models::MultipartRequestObjectField>,

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ impl AdditionalPropertiesWithList {
290290
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
291291
pub struct AdditionalPropertiesWithNullable {
292292
#[serde(rename = "nullableString")]
293-
294293
#[serde(deserialize_with = "swagger::nullable_format::deserialize_optional_nullable")]
295294
#[serde(default = "swagger::nullable_format::default_optional_nullable")]
295+
296296
#[serde(skip_serializing_if="Option::is_none")]
297297
pub nullable_string: Option<swagger::Nullable<String>>,
298298

@@ -3446,30 +3446,30 @@ pub struct NullableTest {
34463446
pub nullable: swagger::Nullable<String>,
34473447

34483448
#[serde(rename = "nullableWithNullDefault")]
3449-
34503449
#[serde(deserialize_with = "swagger::nullable_format::deserialize_optional_nullable")]
34513450
#[serde(default = "swagger::nullable_format::default_optional_nullable")]
3451+
34523452
#[serde(skip_serializing_if="Option::is_none")]
34533453
pub nullable_with_null_default: Option<swagger::Nullable<String>>,
34543454

34553455
#[serde(rename = "nullableWithPresentDefault")]
3456-
34573456
#[serde(deserialize_with = "swagger::nullable_format::deserialize_optional_nullable")]
34583457
#[serde(default = "swagger::nullable_format::default_optional_nullable")]
3458+
34593459
#[serde(skip_serializing_if="Option::is_none")]
34603460
pub nullable_with_present_default: Option<swagger::Nullable<String>>,
34613461

34623462
#[serde(rename = "nullableWithNoDefault")]
3463-
34643463
#[serde(deserialize_with = "swagger::nullable_format::deserialize_optional_nullable")]
34653464
#[serde(default = "swagger::nullable_format::default_optional_nullable")]
3465+
34663466
#[serde(skip_serializing_if="Option::is_none")]
34673467
pub nullable_with_no_default: Option<swagger::Nullable<String>>,
34683468

34693469
#[serde(rename = "nullableArray")]
3470-
34713470
#[serde(deserialize_with = "swagger::nullable_format::deserialize_optional_nullable")]
34723471
#[serde(default = "swagger::nullable_format::default_optional_nullable")]
3472+
34733473
#[serde(skip_serializing_if="Option::is_none")]
34743474
pub nullable_array: Option<swagger::Nullable<Vec<String>>>,
34753475

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

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,14 +1096,12 @@ pub struct ArrayTest {
10961096

10971097
#[serde(rename = "array_array_of_model")]
10981098

1099-
#[cfg_attr(feature = "validate", validate)]
11001099
#[cfg_attr(feature = "validate", validate)]
11011100
#[serde(skip_serializing_if="Option::is_none")]
11021101
pub array_array_of_model: Option<Vec<Vec<models::ReadOnlyFirst>>>,
11031102

11041103
#[serde(rename = "array_of_enum")]
11051104

1106-
#[cfg_attr(feature = "validate", validate)]
11071105
#[cfg_attr(feature = "validate", validate)]
11081106
#[serde(skip_serializing_if="Option::is_none")]
11091107
pub array_of_enum: Option<Vec<models::MapTestMapMapOfEnumValueValue>>,
@@ -2641,21 +2639,18 @@ impl DollarSpecialLeftSquareBracketModelNameRightSquareBracket {
26412639
pub struct EnumArrays {
26422640
#[serde(rename = "just_symbol")]
26432641

2644-
#[cfg_attr(feature = "validate", validate)]
26452642
#[cfg_attr(feature = "validate", validate)]
26462643
#[serde(skip_serializing_if="Option::is_none")]
26472644
pub just_symbol: Option<models::EnumArraysJustSymbol>,
26482645

26492646
#[serde(rename = "array_enum")]
26502647

2651-
#[cfg_attr(feature = "validate", validate)]
26522648
#[cfg_attr(feature = "validate", validate)]
26532649
#[serde(skip_serializing_if="Option::is_none")]
26542650
pub array_enum: Option<Vec<models::EnumArraysArrayEnumInner>>,
26552651

26562652
#[serde(rename = "array_array_enum")]
26572653

2658-
#[cfg_attr(feature = "validate", validate)]
26592654
#[cfg_attr(feature = "validate", validate)]
26602655
#[serde(skip_serializing_if="Option::is_none")]
26612656
pub array_array_enum: Option<Vec<Vec<models::EnumArraysArrayArrayEnumInnerInner>>>,
@@ -3329,7 +3324,6 @@ impl EnumClass {
33293324
pub struct EnumTest {
33303325
#[serde(rename = "enum_string")]
33313326

3332-
#[cfg_attr(feature = "validate", validate)]
33333327
#[cfg_attr(feature = "validate", validate)]
33343328
#[serde(skip_serializing_if="Option::is_none")]
33353329
pub enum_string: Option<models::EnumTestEnumString>,
@@ -3341,21 +3335,18 @@ pub struct EnumTest {
33413335

33423336
#[serde(rename = "enum_integer")]
33433337

3344-
#[cfg_attr(feature = "validate", validate)]
33453338
#[cfg_attr(feature = "validate", validate)]
33463339
#[serde(skip_serializing_if="Option::is_none")]
33473340
pub enum_integer: Option<models::EnumTestEnumInteger>,
33483341

33493342
#[serde(rename = "enum_number")]
33503343

3351-
#[cfg_attr(feature = "validate", validate)]
33523344
#[cfg_attr(feature = "validate", validate)]
33533345
#[serde(skip_serializing_if="Option::is_none")]
33543346
pub enum_number: Option<models::TestEnumParametersEnumQueryDoubleParameter>,
33553347

33563348
#[serde(rename = "outerEnum")]
33573349

3358-
#[cfg_attr(feature = "validate", validate)]
33593350
#[cfg_attr(feature = "validate", validate)]
33603351
#[serde(skip_serializing_if="Option::is_none")]
33613352
pub outer_enum: Option<models::OuterEnum>,
@@ -4663,14 +4654,12 @@ pub struct MapTest {
46634654

46644655
#[serde(rename = "map_map_of_enum")]
46654656

4666-
#[cfg_attr(feature = "validate", validate)]
46674657
#[cfg_attr(feature = "validate", validate)]
46684658
#[serde(skip_serializing_if="Option::is_none")]
46694659
pub map_map_of_enum: Option<std::collections::HashMap<String, std::collections::HashMap<String, models::MapTestMapMapOfEnumValueValue>>>,
46704660

46714661
#[serde(rename = "map_of_enum_string")]
46724662

4673-
#[cfg_attr(feature = "validate", validate)]
46744663
#[cfg_attr(feature = "validate", validate)]
46754664
#[serde(skip_serializing_if="Option::is_none")]
46764665
pub map_of_enum_string: Option<std::collections::HashMap<String, models::MapTestMapMapOfEnumValueValue>>,
@@ -4980,7 +4969,6 @@ pub struct MixedPropertiesAndAdditionalPropertiesClass {
49804969

49814970
#[serde(rename = "map")]
49824971

4983-
#[cfg_attr(feature = "validate", validate)]
49844972
#[cfg_attr(feature = "validate", validate)]
49854973
#[serde(skip_serializing_if="Option::is_none")]
49864974
pub map: Option<std::collections::HashMap<String, models::Animal>>,
@@ -5735,7 +5723,6 @@ impl NumberOnly {
57355723
pub struct ObjectContainingObjectWithOnlyAdditionalProperties {
57365724
#[serde(rename = "inner")]
57375725

5738-
#[cfg_attr(feature = "validate", validate)]
57395726
#[cfg_attr(feature = "validate", validate)]
57405727
#[serde(skip_serializing_if="Option::is_none")]
57415728
pub inner: Option<models::ObjectWithOnlyAdditionalProperties>,
@@ -5930,6 +5917,15 @@ impl std::ops::DerefMut for ObjectWithOnlyAdditionalProperties {
59305917
}
59315918
}
59325919

5920+
#[cfg(feature = "validate")]
5921+
impl serde_valid::validation::ValidateCompositedMinLength for ObjectWithOnlyAdditionalProperties {
5922+
fn validate_composited_min_length(
5923+
&self,
5924+
_min_length: usize,
5925+
) -> Result<(), serde_valid::validation::Composited<serde_valid::validation::error::MinLengthError>> {
5926+
Ok(())
5927+
}
5928+
}
59335929
/// Converts the ObjectWithOnlyAdditionalProperties value to the Query Parameters representation (style=form, explode=false)
59345930
/// specified in <https://swagger.io/docs/specification/serialization/>
59355931
/// Should be implemented in a serde serializer
@@ -6064,7 +6060,6 @@ pub struct Order {
60646060

60656061
#[serde(rename = "status")]
60666062

6067-
#[cfg_attr(feature = "validate", validate)]
60686063
#[cfg_attr(feature = "validate", validate)]
60696064
#[serde(skip_serializing_if="Option::is_none")]
60706065
pub status: Option<models::OrderStatus>,
@@ -6442,6 +6437,15 @@ impl std::ops::DerefMut for OuterBoolean {
64426437
}
64436438
}
64446439

6440+
#[cfg(feature = "validate")]
6441+
impl serde_valid::validation::ValidateCompositedMinLength for OuterBoolean {
6442+
fn validate_composited_min_length(
6443+
&self,
6444+
_min_length: usize,
6445+
) -> Result<(), serde_valid::validation::Composited<serde_valid::validation::error::MinLengthError>> {
6446+
Ok(())
6447+
}
6448+
}
64456449
/// Converts the OuterBoolean value to the Query Parameters representation (style=form, explode=false)
64466450
/// specified in <https://swagger.io/docs/specification/serialization/>
64476451
/// Should be implemented in a serde serializer
@@ -6914,6 +6918,15 @@ impl std::ops::DerefMut for OuterNumber {
69146918
}
69156919
}
69166920

6921+
#[cfg(feature = "validate")]
6922+
impl serde_valid::validation::ValidateCompositedMinLength for OuterNumber {
6923+
fn validate_composited_min_length(
6924+
&self,
6925+
_min_length: usize,
6926+
) -> Result<(), serde_valid::validation::Composited<serde_valid::validation::error::MinLengthError>> {
6927+
Ok(())
6928+
}
6929+
}
69176930
/// Converts the OuterNumber value to the Query Parameters representation (style=form, explode=false)
69186931
/// specified in <https://swagger.io/docs/specification/serialization/>
69196932
/// Should be implemented in a serde serializer
@@ -7056,6 +7069,15 @@ impl std::ops::DerefMut for OuterString {
70567069
}
70577070
}
70587071

7072+
#[cfg(feature = "validate")]
7073+
impl serde_valid::validation::ValidateCompositedMinLength for OuterString {
7074+
fn validate_composited_min_length(
7075+
&self,
7076+
_min_length: usize,
7077+
) -> Result<(), serde_valid::validation::Composited<serde_valid::validation::error::MinLengthError>> {
7078+
Ok(())
7079+
}
7080+
}
70597081
impl std::fmt::Display for OuterString {
70607082
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
70617083
write!(f, "{}", self.0.clone())
@@ -7167,7 +7189,6 @@ pub struct Pet {
71677189

71687190
#[serde(rename = "category")]
71697191

7170-
#[cfg_attr(feature = "validate", validate)]
71717192
#[cfg_attr(feature = "validate", validate)]
71727193
#[serde(skip_serializing_if="Option::is_none")]
71737194
pub category: Option<models::Category>,
@@ -7182,14 +7203,12 @@ pub struct Pet {
71827203

71837204
#[serde(rename = "tags")]
71847205

7185-
#[cfg_attr(feature = "validate", validate)]
71867206
#[cfg_attr(feature = "validate", validate)]
71877207
#[serde(skip_serializing_if="Option::is_none")]
71887208
pub tags: Option<Vec<models::Tag>>,
71897209

71907210
#[serde(rename = "status")]
71917211

7192-
#[cfg_attr(feature = "validate", validate)]
71937212
#[cfg_attr(feature = "validate", validate)]
71947213
#[serde(skip_serializing_if="Option::is_none")]
71957214
pub status: Option<models::PetStatus>,

samples/server/petstore/rust-server/output/rust-server-test/src/models.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use serde_valid::Validate;
1212
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
1313
pub struct ANullableContainer {
1414
#[serde(rename = "NullableThing")]
15-
1615
#[serde(deserialize_with = "swagger::nullable_format::deserialize_optional_nullable")]
1716
#[serde(default = "swagger::nullable_format::default_optional_nullable")]
17+
1818
#[serde(skip_serializing_if="Option::is_none")]
1919
pub nullable_thing: Option<swagger::Nullable<String>>,
2020

@@ -214,6 +214,15 @@ impl std::ops::DerefMut for AdditionalPropertiesObject {
214214
}
215215
}
216216

217+
#[cfg(feature = "validate")]
218+
impl serde_valid::validation::ValidateCompositedMinLength for AdditionalPropertiesObject {
219+
fn validate_composited_min_length(
220+
&self,
221+
_min_length: usize,
222+
) -> Result<(), serde_valid::validation::Composited<serde_valid::validation::error::MinLengthError>> {
223+
Ok(())
224+
}
225+
}
217226
/// Converts the AdditionalPropertiesObject value to the Query Parameters representation (style=form, explode=false)
218227
/// specified in <https://swagger.io/docs/specification/serialization/>
219228
/// Should be implemented in a serde serializer
@@ -996,7 +1005,6 @@ impl std::convert::TryFrom<hyper::header::HeaderValue> for header::IntoHeaderVal
9961005
pub struct ObjectOfObjects {
9971006
#[serde(rename = "inner")]
9981007

999-
#[cfg_attr(feature = "validate", validate)]
10001008
#[cfg_attr(feature = "validate", validate)]
10011009
#[serde(skip_serializing_if="Option::is_none")]
10021010
pub inner: Option<models::ObjectOfObjectsInner>,
@@ -1525,6 +1533,15 @@ impl std::ops::DerefMut for UnnamedReference {
15251533
}
15261534
}
15271535

1536+
#[cfg(feature = "validate")]
1537+
impl serde_valid::validation::ValidateCompositedMinLength for UnnamedReference {
1538+
fn validate_composited_min_length(
1539+
&self,
1540+
_min_length: usize,
1541+
) -> Result<(), serde_valid::validation::Composited<serde_valid::validation::error::MinLengthError>> {
1542+
Ok(())
1543+
}
1544+
}
15281545
/// Converts the UnnamedReference value to the Query Parameters representation (style=form, explode=false)
15291546
/// specified in <https://swagger.io/docs/specification/serialization/>
15301547
/// Should be implemented in a serde serializer

0 commit comments

Comments
 (0)