Add tests for max,min items in array (rust-server) (#17215)

* add tests for max,min items in array (rust server)

* fix both min, max items
This commit is contained in:
William Cheng
2023-11-29 16:21:54 +08:00
committed by GitHub
parent 14c12fc617
commit 46dd87525e
5 changed files with 93 additions and 1 deletions

View File

@@ -298,7 +298,7 @@ pub struct {{{classname}}} {
{{/minimum}}
{{#maxItems}}
{{#minItems}}
length(min = {{minItems}}, max = {{maxLength}}),
length(min = {{minItems}}, max = {{maxItems}}),
{{/minItems}}
{{^minItems}}
length(max = {{maxItems}}),

View File

@@ -639,6 +639,22 @@ components:
items:
type: string
nullable: true
min_item_test:
type: array
items:
type: integer
minItems: 1
max_item_test:
type: array
items:
type: integer
maxItems: 2
min_max_item_test:
type: array
items:
type: integer
minItems: 1
maxItems: 3
StringEnum:
type: string
enum:

View File

@@ -654,6 +654,22 @@ components:
type: string
nullable: true
type: array
min_item_test:
items:
type: integer
minItems: 1
type: array
max_item_test:
items:
type: integer
maxItems: 2
type: array
min_max_item_test:
items:
type: integer
maxItems: 3
minItems: 1
type: array
required:
- nullable
type: object

View File

@@ -8,6 +8,9 @@ Name | Type | Description | Notes
**nullable_with_present_default** | **String** | | [optional] [default to Some(swagger::Nullable::Present("default".to_string()))]
**nullable_with_no_default** | **String** | | [optional] [default to None]
**nullable_array** | **Vec<String>** | | [optional] [default to None]
**min_item_test** | **Vec<i32>** | | [optional] [default to None]
**max_item_test** | **Vec<i32>** | | [optional] [default to None]
**min_max_item_test** | **Vec<i32>** | | [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)

View File

@@ -1546,6 +1546,27 @@ pub struct NullableTest {
#[serde(skip_serializing_if="Option::is_none")]
pub nullable_array: Option<swagger::Nullable<Vec<String>>>,
#[serde(rename = "min_item_test")]
#[validate(
length(min = 1),
)]
#[serde(skip_serializing_if="Option::is_none")]
pub min_item_test: Option<Vec<i32>>,
#[serde(rename = "max_item_test")]
#[validate(
length(max = 2),
)]
#[serde(skip_serializing_if="Option::is_none")]
pub max_item_test: Option<Vec<i32>>,
#[serde(rename = "min_max_item_test")]
#[validate(
length(min = 1, max = 3),
)]
#[serde(skip_serializing_if="Option::is_none")]
pub min_max_item_test: Option<Vec<i32>>,
}
@@ -1558,6 +1579,9 @@ impl NullableTest {
nullable_with_present_default: Some(swagger::Nullable::Present("default".to_string())),
nullable_with_no_default: None,
nullable_array: None,
min_item_test: None,
max_item_test: None,
min_max_item_test: None,
}
}
}
@@ -1604,6 +1628,30 @@ impl std::string::ToString for NullableTest {
].join(",")
}),
self.min_item_test.as_ref().map(|min_item_test| {
[
"min_item_test".to_string(),
min_item_test.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(","),
].join(",")
}),
self.max_item_test.as_ref().map(|max_item_test| {
[
"max_item_test".to_string(),
max_item_test.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(","),
].join(",")
}),
self.min_max_item_test.as_ref().map(|min_max_item_test| {
[
"min_max_item_test".to_string(),
min_max_item_test.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(","),
].join(",")
}),
];
params.into_iter().flatten().collect::<Vec<_>>().join(",")
@@ -1626,6 +1674,9 @@ impl std::str::FromStr for NullableTest {
pub nullable_with_present_default: Vec<String>,
pub nullable_with_no_default: Vec<String>,
pub nullable_array: Vec<Vec<String>>,
pub min_item_test: Vec<Vec<i32>>,
pub max_item_test: Vec<Vec<i32>>,
pub min_max_item_test: Vec<Vec<i32>>,
}
let mut intermediate_rep = IntermediateRep::default();
@@ -1648,6 +1699,9 @@ impl std::str::FromStr for NullableTest {
"nullableWithPresentDefault" => return std::result::Result::Err("Parsing a nullable type in this style is not supported in NullableTest".to_string()),
"nullableWithNoDefault" => return std::result::Result::Err("Parsing a nullable type in this style is not supported in NullableTest".to_string()),
"nullableArray" => return std::result::Result::Err("Parsing a container in this style is not supported in NullableTest".to_string()),
"min_item_test" => return std::result::Result::Err("Parsing a container in this style is not supported in NullableTest".to_string()),
"max_item_test" => return std::result::Result::Err("Parsing a container in this style is not supported in NullableTest".to_string()),
"min_max_item_test" => return std::result::Result::Err("Parsing a container in this style is not supported in NullableTest".to_string()),
_ => return std::result::Result::Err("Unexpected key while parsing NullableTest".to_string())
}
}
@@ -1663,6 +1717,9 @@ impl std::str::FromStr for NullableTest {
nullable_with_present_default: std::result::Result::Err("Nullable types not supported in NullableTest".to_string())?,
nullable_with_no_default: std::result::Result::Err("Nullable types not supported in NullableTest".to_string())?,
nullable_array: std::result::Result::Err("Nullable types not supported in NullableTest".to_string())?,
min_item_test: intermediate_rep.min_item_test.into_iter().next(),
max_item_test: intermediate_rep.max_item_test.into_iter().next(),
min_max_item_test: intermediate_rep.min_max_item_test.into_iter().next(),
})
}
}