forked from loafle/openapi-generator-original
[Rust Server] Handle array of objects inside an object correctly (#5044)
Use correct data type for arrays inside objects. Add test for arrays of objects Update samples
This commit is contained in:
parent
2714af4922
commit
52e09e2ffa
@ -183,7 +183,7 @@ pub struct {{{classname}}} {
|
||||
#[serde(deserialize_with = "swagger::nullable_format::deserialize_optional_nullable")]
|
||||
#[serde(default = "swagger::nullable_format::default_optional_nullable")]{{/isNullable}}
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub {{{name}}}: Option<{{#isNullable}}swagger::Nullable<{{/isNullable}}{{#isListContainer}}Vec<{{#items}}{{{dataType}}}{{/items}}>{{/isListContainer}}{{^isListContainer}}{{{dataType}}}{{/isListContainer}}{{#isNullable}}>{{/isNullable}}>,
|
||||
pub {{{name}}}: Option<{{#isNullable}}swagger::Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}}>,
|
||||
{{/required}}
|
||||
|
||||
{{/vars}}
|
||||
|
@ -267,6 +267,15 @@ components:
|
||||
xml:
|
||||
name: snake_another_xml_object
|
||||
namespace: http://foo.bar
|
||||
ObjectWithArrayOfObjects:
|
||||
type: object
|
||||
properties:
|
||||
objectArray:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/StringObject'
|
||||
StringObject:
|
||||
type: string
|
||||
MyIDList:
|
||||
type: array
|
||||
items:
|
||||
|
@ -128,6 +128,8 @@ Method | HTTP request | Description
|
||||
- [InlineResponse201](docs/InlineResponse201.md)
|
||||
- [MyId](docs/MyId.md)
|
||||
- [MyIdList](docs/MyIdList.md)
|
||||
- [ObjectWithArrayOfObjects](docs/ObjectWithArrayOfObjects.md)
|
||||
- [StringObject](docs/StringObject.md)
|
||||
- [UuidObject](docs/UuidObject.md)
|
||||
- [XmlArray](docs/XmlArray.md)
|
||||
- [XmlInner](docs/XmlInner.md)
|
||||
|
@ -249,6 +249,15 @@ components:
|
||||
xml:
|
||||
name: snake_another_xml_object
|
||||
namespace: http://foo.bar
|
||||
ObjectWithArrayOfObjects:
|
||||
properties:
|
||||
objectArray:
|
||||
items:
|
||||
$ref: '#/components/schemas/StringObject'
|
||||
type: array
|
||||
type: object
|
||||
StringObject:
|
||||
type: string
|
||||
MyIDList:
|
||||
items:
|
||||
$ref: '#/components/schemas/MyID'
|
||||
|
@ -0,0 +1,10 @@
|
||||
# ObjectWithArrayOfObjects
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**object_array** | **Vec<models::StringObject>** | | [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)
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
# StringObject
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
@ -403,6 +403,78 @@ impl MyIdList {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
|
||||
pub struct ObjectWithArrayOfObjects {
|
||||
#[serde(rename = "objectArray")]
|
||||
#[serde(skip_serializing_if="Option::is_none")]
|
||||
pub object_array: Option<Vec<models::StringObject>>,
|
||||
|
||||
}
|
||||
|
||||
impl ObjectWithArrayOfObjects {
|
||||
pub fn new() -> ObjectWithArrayOfObjects {
|
||||
ObjectWithArrayOfObjects {
|
||||
object_array: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectWithArrayOfObjects {
|
||||
/// Helper function to allow us to convert this model to an XML string.
|
||||
/// Will panic if serialisation fails.
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn to_xml(&self) -> String {
|
||||
serde_xml_rs::to_string(&self).expect("impossible to fail to serialize")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
|
||||
pub struct StringObject(String);
|
||||
|
||||
impl ::std::convert::From<String> for StringObject {
|
||||
fn from(x: String) -> Self {
|
||||
StringObject(x)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for StringObject {
|
||||
type Err = ParseError;
|
||||
fn from_str(x: &str) -> Result<Self, Self::Err> {
|
||||
Ok(StringObject(x.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::convert::From<StringObject> for String {
|
||||
fn from(x: StringObject) -> Self {
|
||||
x.0
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::ops::Deref for StringObject {
|
||||
type Target = String;
|
||||
fn deref(&self) -> &String {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::ops::DerefMut for StringObject {
|
||||
fn deref_mut(&mut self) -> &mut String {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl StringObject {
|
||||
/// Helper function to allow us to convert this model to an XML string.
|
||||
/// Will panic if serialisation fails.
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn to_xml(&self) -> String {
|
||||
serde_xml_rs::to_string(&self).expect("impossible to fail to serialize")
|
||||
}
|
||||
}
|
||||
|
||||
/// Test a model containing a UUID
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "conversion", derive(LabelledGeneric))]
|
||||
|
Loading…
x
Reference in New Issue
Block a user