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 3edf610cbf5..d05c7f7d5ef 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/models.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/models.mustache @@ -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}} 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 2ff7fa15bcf..d67a47a8930 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 @@ -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: diff --git a/samples/server/petstore/rust-server/output/openapi-v3/README.md b/samples/server/petstore/rust-server/output/openapi-v3/README.md index a3488bae6e5..4e5bf34fbbf 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/README.md +++ b/samples/server/petstore/rust-server/output/openapi-v3/README.md @@ -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) 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 52dbcc0ef05..cc86611971e 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 @@ -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' diff --git a/samples/server/petstore/rust-server/output/openapi-v3/docs/ObjectWithArrayOfObjects.md b/samples/server/petstore/rust-server/output/openapi-v3/docs/ObjectWithArrayOfObjects.md new file mode 100644 index 00000000000..6801b3966ec --- /dev/null +++ b/samples/server/petstore/rust-server/output/openapi-v3/docs/ObjectWithArrayOfObjects.md @@ -0,0 +1,10 @@ +# ObjectWithArrayOfObjects + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**object_array** | **Vec** | | [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/docs/StringObject.md b/samples/server/petstore/rust-server/output/openapi-v3/docs/StringObject.md new file mode 100644 index 00000000000..2b822551043 --- /dev/null +++ b/samples/server/petstore/rust-server/output/openapi-v3/docs/StringObject.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) + + 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 9b1cd6ab2c4..f307404fbeb 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 @@ -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>, + +} + +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 for StringObject { + fn from(x: String) -> Self { + StringObject(x) + } +} + +impl std::str::FromStr for StringObject { + type Err = ParseError; + fn from_str(x: &str) -> Result { + Ok(StringObject(x.to_string())) + } +} + +impl ::std::convert::From 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))]