Skip to content

Commit

Permalink
[rust] Fix model constructor for required enum array (#14196)
Browse files Browse the repository at this point in the history
For a required enum array property the generated model constructor used
the type `RequiredEnums` instead of `Vec<RequiredEnums>`.
  • Loading branch information
tvrg authored Dec 27, 2022
1 parent 444d411 commit 63f6569
Show file tree
Hide file tree
Showing 27 changed files with 323 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl {{{classname}}} {
{{#description}}
/// {{{.}}}
{{/description}}
pub fn new({{#requiredVars}}{{{name}}}: {{#isNullable}}Option<{{/isNullable}}{{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}}>{{/isNullable}}{{^-last}}, {{/-last}}{{/requiredVars}}) -> {{{classname}}} {
pub fn new({{#requiredVars}}{{{name}}}: {{#isNullable}}Option<{{/isNullable}}{{#isEnum}}{{#isArray}}Vec<{{/isArray}}{{{enumName}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}}>{{/isNullable}}{{^-last}}, {{/-last}}{{/requiredVars}}) -> {{{classname}}} {
{{{classname}}} {
{{#vars}}
{{{name}}}{{^required}}{{#isArray}}: None{{/isArray}}{{#isMap}}: None{{/isMap}}{{^isContainer}}: None{{/isContainer}}{{/required}}{{#required}}{{#isModel}}: {{^isNullable}}Box::new({{{name}}}){{/isNullable}}{{#isNullable}}if let Some(x) = {{{name}}} {Some(Box::new(x))} else {None}{{/isNullable}}{{/isModel}}{{/required}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -877,4 +877,15 @@ components:
nullable: true
required_nullable:
type: string
nullable: true
nullable: true
EnumArrayTesting:
description: Test of enum array
type: object
required:
- required_enums
properties:
required_enums:
type: array
items:
type: string
enum: ["A", "B", "C"]
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ docs/ActionContainer.md
docs/ApiResponse.md
docs/Baz.md
docs/Category.md
docs/EnumArrayTesting.md
docs/FakeApi.md
docs/OptionalTesting.md
docs/Order.md
Expand Down Expand Up @@ -34,6 +35,7 @@ src/models/action_container.rs
src/models/api_response.rs
src/models/baz.rs
src/models/category.rs
src/models/enum_array_testing.rs
src/models/mod.rs
src/models/model_return.rs
src/models/optional_testing.rs
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/rust/hyper/petstore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Class | Method | HTTP request | Description
- [ApiResponse](docs/ApiResponse.md)
- [Baz](docs/Baz.md)
- [Category](docs/Category.md)
- [EnumArrayTesting](docs/EnumArrayTesting.md)
- [OptionalTesting](docs/OptionalTesting.md)
- [Order](docs/Order.md)
- [Pet](docs/Pet.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# EnumArrayTesting

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**required_enums** | **Vec<String>** | |

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


Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* OpenAPI Petstore
*
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
* Generated by: https://openapi-generator.tech
*/

/// EnumArrayTesting : Test of enum array


#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct EnumArrayTesting {
#[serde(rename = "required_enums")]
pub required_enums: Vec<RequiredEnums>,
}

impl EnumArrayTesting {
/// Test of enum array
pub fn new(required_enums: Vec<RequiredEnums>) -> EnumArrayTesting {
EnumArrayTesting {
required_enums,
}
}
}

///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum RequiredEnums {
#[serde(rename = "A")]
A,
#[serde(rename = "B")]
B,
#[serde(rename = "C")]
C,
}

impl Default for RequiredEnums {
fn default() -> RequiredEnums {
Self::A
}
}

2 changes: 2 additions & 0 deletions samples/client/petstore/rust/hyper/petstore/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub mod baz;
pub use self::baz::Baz;
pub mod category;
pub use self::category::Category;
pub mod enum_array_testing;
pub use self::enum_array_testing::EnumArrayTesting;
pub mod optional_testing;
pub use self::optional_testing::OptionalTesting;
pub mod order;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ docs/ActionContainer.md
docs/ApiResponse.md
docs/Baz.md
docs/Category.md
docs/EnumArrayTesting.md
docs/FakeApi.md
docs/OptionalTesting.md
docs/Order.md
Expand All @@ -32,6 +33,7 @@ src/models/action_container.rs
src/models/api_response.rs
src/models/baz.rs
src/models/category.rs
src/models/enum_array_testing.rs
src/models/mod.rs
src/models/model_return.rs
src/models/optional_testing.rs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Class | Method | HTTP request | Description
- [ApiResponse](docs/ApiResponse.md)
- [Baz](docs/Baz.md)
- [Category](docs/Category.md)
- [EnumArrayTesting](docs/EnumArrayTesting.md)
- [OptionalTesting](docs/OptionalTesting.md)
- [Order](docs/Order.md)
- [Pet](docs/Pet.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# EnumArrayTesting

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**required_enums** | **Vec<String>** | |

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


Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* OpenAPI Petstore
*
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
* Generated by: https://openapi-generator.tech
*/

/// EnumArrayTesting : Test of enum array


#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct EnumArrayTesting {
#[serde(rename = "required_enums")]
pub required_enums: Vec<RequiredEnums>,
}

impl EnumArrayTesting {
/// Test of enum array
pub fn new(required_enums: Vec<RequiredEnums>) -> EnumArrayTesting {
EnumArrayTesting {
required_enums,
}
}
}

///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum RequiredEnums {
#[serde(rename = "A")]
A,
#[serde(rename = "B")]
B,
#[serde(rename = "C")]
C,
}

impl Default for RequiredEnums {
fn default() -> RequiredEnums {
Self::A
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub mod baz;
pub use self::baz::Baz;
pub mod category;
pub use self::category::Category;
pub mod enum_array_testing;
pub use self::enum_array_testing::EnumArrayTesting;
pub mod optional_testing;
pub use self::optional_testing::OptionalTesting;
pub mod order;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ docs/ActionContainer.md
docs/ApiResponse.md
docs/Baz.md
docs/Category.md
docs/EnumArrayTesting.md
docs/FakeApi.md
docs/OptionalTesting.md
docs/Order.md
Expand All @@ -32,6 +33,7 @@ src/models/action_container.rs
src/models/api_response.rs
src/models/baz.rs
src/models/category.rs
src/models/enum_array_testing.rs
src/models/mod.rs
src/models/model_return.rs
src/models/optional_testing.rs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Class | Method | HTTP request | Description
- [ApiResponse](docs/ApiResponse.md)
- [Baz](docs/Baz.md)
- [Category](docs/Category.md)
- [EnumArrayTesting](docs/EnumArrayTesting.md)
- [OptionalTesting](docs/OptionalTesting.md)
- [Order](docs/Order.md)
- [Pet](docs/Pet.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# EnumArrayTesting

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**required_enums** | **Vec<String>** | |

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


Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* OpenAPI Petstore
*
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
* Generated by: https://openapi-generator.tech
*/

/// EnumArrayTesting : Test of enum array


#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct EnumArrayTesting {
#[serde(rename = "required_enums")]
pub required_enums: Vec<RequiredEnums>,
}

impl EnumArrayTesting {
/// Test of enum array
pub fn new(required_enums: Vec<RequiredEnums>) -> EnumArrayTesting {
EnumArrayTesting {
required_enums,
}
}
}

///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum RequiredEnums {
#[serde(rename = "A")]
A,
#[serde(rename = "B")]
B,
#[serde(rename = "C")]
C,
}

impl Default for RequiredEnums {
fn default() -> RequiredEnums {
Self::A
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub mod baz;
pub use self::baz::Baz;
pub mod category;
pub use self::category::Category;
pub mod enum_array_testing;
pub use self::enum_array_testing::EnumArrayTesting;
pub mod optional_testing;
pub use self::optional_testing::OptionalTesting;
pub mod order;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ docs/ActionContainer.md
docs/ApiResponse.md
docs/Baz.md
docs/Category.md
docs/EnumArrayTesting.md
docs/FakeApi.md
docs/OptionalTesting.md
docs/Order.md
Expand All @@ -32,6 +33,7 @@ src/models/action_container.rs
src/models/api_response.rs
src/models/baz.rs
src/models/category.rs
src/models/enum_array_testing.rs
src/models/mod.rs
src/models/model_return.rs
src/models/optional_testing.rs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Class | Method | HTTP request | Description
- [ApiResponse](docs/ApiResponse.md)
- [Baz](docs/Baz.md)
- [Category](docs/Category.md)
- [EnumArrayTesting](docs/EnumArrayTesting.md)
- [OptionalTesting](docs/OptionalTesting.md)
- [Order](docs/Order.md)
- [Pet](docs/Pet.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# EnumArrayTesting

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**required_enums** | **Vec<String>** | |

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


Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* OpenAPI Petstore
*
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
* Generated by: https://openapi-generator.tech
*/

/// EnumArrayTesting : Test of enum array


#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct EnumArrayTesting {
#[serde(rename = "required_enums")]
pub required_enums: Vec<RequiredEnums>,
}

impl EnumArrayTesting {
/// Test of enum array
pub fn new(required_enums: Vec<RequiredEnums>) -> EnumArrayTesting {
EnumArrayTesting {
required_enums,
}
}
}

///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum RequiredEnums {
#[serde(rename = "A")]
A,
#[serde(rename = "B")]
B,
#[serde(rename = "C")]
C,
}

impl Default for RequiredEnums {
fn default() -> RequiredEnums {
Self::A
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub mod baz;
pub use self::baz::Baz;
pub mod category;
pub use self::category::Category;
pub mod enum_array_testing;
pub use self::enum_array_testing::EnumArrayTesting;
pub mod optional_testing;
pub use self::optional_testing::OptionalTesting;
pub mod order;
Expand Down
Loading

0 comments on commit 63f6569

Please sign in to comment.