Skip to content

Commit

Permalink
[BUGFIX][Rust] Array with unique enum items no longer causes mismatch…
Browse files Browse the repository at this point in the history
…ed types error (OpenAPITools#17197)

* check args to fn new for uniqueItems

* Added model with unique items for template testing

* build the project and update samples

* Removed testcase from fake petstore spec
  • Loading branch information
SAIA-Basseldonk authored Nov 30, 2023
1 parent f033b11 commit 8911740
Show file tree
Hide file tree
Showing 27 changed files with 332 additions and 1 deletion.
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}}{{#isArray}}Vec<{{/isArray}}{{{enumName}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}}>{{/isNullable}}{{^-last}}, {{/-last}}{{/requiredVars}}) -> {{{classname}}} {
pub fn new({{#requiredVars}}{{{name}}}: {{#isNullable}}Option<{{/isNullable}}{{#isEnum}}{{#isArray}}{{#uniqueItems}}std::collections::HashSet<{{/uniqueItems}}{{^uniqueItems}}Vec<{{/uniqueItems}}{{/isArray}}{{{enumName}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}}>{{/isNullable}}{{^-last}}, {{/-last}}{{/requiredVars}}) -> {{{classname}}} {
{{{classname}}} {
{{#vars}}
{{{name}}}{{^required}}{{#isContainer}}{{#isArray}}: None{{/isArray}}{{#isMap}}: None{{/isMap}}{{^isArray}}{{^isMap}}{{#isNullable}}: None{{/isNullable}}{{/isMap}}{{/isArray}}{{/isContainer}}{{^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 @@ -898,6 +898,22 @@ components:
items:
type: string
enum: ["A", "B", "C"]
UniqueItemArrayTesting:
description: Test handling of enum array with unique items
type: object
required:
- unique_item_array
properties:
unique_item_array:
type: array
description: Helper object for the unique item array test
uniqueItems: true
items:
type: string
enum:
- unique_item_1
- unique_item_2
- unique_item_3
ArrayRefItem:
description: Helper object for the array item ref test
type: array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ docs/StoreApi.md
docs/Tag.md
docs/TestingApi.md
docs/TypeTesting.md
docs/UniqueItemArrayTesting.md
docs/User.md
docs/UserApi.md
git_push.sh
Expand Down Expand Up @@ -48,4 +49,5 @@ src/models/pet.rs
src/models/property_test.rs
src/models/tag.rs
src/models/type_testing.rs
src/models/unique_item_array_testing.rs
src/models/user.rs
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 @@ -66,6 +66,7 @@ Class | Method | HTTP request | Description
- [Return](docs/Return.md)
- [Tag](docs/Tag.md)
- [TypeTesting](docs/TypeTesting.md)
- [UniqueItemArrayTesting](docs/UniqueItemArrayTesting.md)
- [User](docs/User.md)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# UniqueItemArrayTesting

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**unique_item_array** | **Vec<String>** | Helper object for the unique item array test |

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


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 @@ -26,5 +26,7 @@ pub mod tag;
pub use self::tag::Tag;
pub mod type_testing;
pub use self::type_testing::TypeTesting;
pub mod unique_item_array_testing;
pub use self::unique_item_array_testing::UniqueItemArrayTesting;
pub mod user;
pub use self::user::User;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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
*/

/// UniqueItemArrayTesting : Test handling of enum array with unique items



#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct UniqueItemArrayTesting {
/// Helper object for the unique item array test
#[serde(rename = "unique_item_array")]
pub unique_item_array: std::collections::HashSet<UniqueItemArray>,
}

impl UniqueItemArrayTesting {
/// Test handling of enum array with unique items
pub fn new(unique_item_array: std::collections::HashSet<UniqueItemArray>) -> UniqueItemArrayTesting {
UniqueItemArrayTesting {
unique_item_array,
}
}
}

/// Helper object for the unique item array test
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum UniqueItemArray {
#[serde(rename = "unique_item_1")]
Variant1,
#[serde(rename = "unique_item_2")]
Variant2,
#[serde(rename = "unique_item_3")]
Variant3,
}

impl Default for UniqueItemArray {
fn default() -> UniqueItemArray {
Self::Variant1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ docs/StoreApi.md
docs/Tag.md
docs/TestingApi.md
docs/TypeTesting.md
docs/UniqueItemArrayTesting.md
docs/User.md
docs/UserApi.md
git_push.sh
Expand All @@ -46,4 +47,5 @@ src/models/pet.rs
src/models/property_test.rs
src/models/tag.rs
src/models/type_testing.rs
src/models/unique_item_array_testing.rs
src/models/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Class | Method | HTTP request | Description
- [Return](docs/Return.md)
- [Tag](docs/Tag.md)
- [TypeTesting](docs/TypeTesting.md)
- [UniqueItemArrayTesting](docs/UniqueItemArrayTesting.md)
- [User](docs/User.md)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# UniqueItemArrayTesting

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**unique_item_array** | **Vec<String>** | Helper object for the unique item array test |

[[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
Expand Up @@ -26,5 +26,7 @@ pub mod tag;
pub use self::tag::Tag;
pub mod type_testing;
pub use self::type_testing::TypeTesting;
pub mod unique_item_array_testing;
pub use self::unique_item_array_testing::UniqueItemArrayTesting;
pub mod user;
pub use self::user::User;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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
*/

/// UniqueItemArrayTesting : Test handling of enum array with unique items



#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct UniqueItemArrayTesting {
/// Helper object for the unique item array test
#[serde(rename = "unique_item_array")]
pub unique_item_array: std::collections::HashSet<UniqueItemArray>,
}

impl UniqueItemArrayTesting {
/// Test handling of enum array with unique items
pub fn new(unique_item_array: std::collections::HashSet<UniqueItemArray>) -> UniqueItemArrayTesting {
UniqueItemArrayTesting {
unique_item_array,
}
}
}

/// Helper object for the unique item array test
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum UniqueItemArray {
#[serde(rename = "unique_item_1")]
Variant1,
#[serde(rename = "unique_item_2")]
Variant2,
#[serde(rename = "unique_item_3")]
Variant3,
}

impl Default for UniqueItemArray {
fn default() -> UniqueItemArray {
Self::Variant1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ docs/StoreApi.md
docs/Tag.md
docs/TestingApi.md
docs/TypeTesting.md
docs/UniqueItemArrayTesting.md
docs/User.md
docs/UserApi.md
git_push.sh
Expand All @@ -46,4 +47,5 @@ src/models/pet.rs
src/models/property_test.rs
src/models/tag.rs
src/models/type_testing.rs
src/models/unique_item_array_testing.rs
src/models/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Class | Method | HTTP request | Description
- [Return](docs/Return.md)
- [Tag](docs/Tag.md)
- [TypeTesting](docs/TypeTesting.md)
- [UniqueItemArrayTesting](docs/UniqueItemArrayTesting.md)
- [User](docs/User.md)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# UniqueItemArrayTesting

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**unique_item_array** | **Vec<String>** | Helper object for the unique item array test |

[[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
Expand Up @@ -26,5 +26,7 @@ pub mod tag;
pub use self::tag::Tag;
pub mod type_testing;
pub use self::type_testing::TypeTesting;
pub mod unique_item_array_testing;
pub use self::unique_item_array_testing::UniqueItemArrayTesting;
pub mod user;
pub use self::user::User;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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
*/

/// UniqueItemArrayTesting : Test handling of enum array with unique items



#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct UniqueItemArrayTesting {
/// Helper object for the unique item array test
#[serde(rename = "unique_item_array")]
pub unique_item_array: std::collections::HashSet<UniqueItemArray>,
}

impl UniqueItemArrayTesting {
/// Test handling of enum array with unique items
pub fn new(unique_item_array: std::collections::HashSet<UniqueItemArray>) -> UniqueItemArrayTesting {
UniqueItemArrayTesting {
unique_item_array,
}
}
}

/// Helper object for the unique item array test
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum UniqueItemArray {
#[serde(rename = "unique_item_1")]
Variant1,
#[serde(rename = "unique_item_2")]
Variant2,
#[serde(rename = "unique_item_3")]
Variant3,
}

impl Default for UniqueItemArray {
fn default() -> UniqueItemArray {
Self::Variant1
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ docs/StoreApi.md
docs/Tag.md
docs/TestingApi.md
docs/TypeTesting.md
docs/UniqueItemArrayTesting.md
docs/User.md
docs/UserApi.md
git_push.sh
Expand All @@ -46,4 +47,5 @@ src/models/pet.rs
src/models/property_test.rs
src/models/tag.rs
src/models/type_testing.rs
src/models/unique_item_array_testing.rs
src/models/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Class | Method | HTTP request | Description
- [Return](docs/Return.md)
- [Tag](docs/Tag.md)
- [TypeTesting](docs/TypeTesting.md)
- [UniqueItemArrayTesting](docs/UniqueItemArrayTesting.md)
- [User](docs/User.md)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# UniqueItemArrayTesting

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**unique_item_array** | **Vec<String>** | Helper object for the unique item array test |

[[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
Expand Up @@ -26,5 +26,7 @@ pub mod tag;
pub use self::tag::Tag;
pub mod type_testing;
pub use self::type_testing::TypeTesting;
pub mod unique_item_array_testing;
pub use self::unique_item_array_testing::UniqueItemArrayTesting;
pub mod user;
pub use self::user::User;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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
*/

/// UniqueItemArrayTesting : Test handling of enum array with unique items



#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct UniqueItemArrayTesting {
/// Helper object for the unique item array test
#[serde(rename = "unique_item_array")]
pub unique_item_array: std::collections::HashSet<UniqueItemArray>,
}

impl UniqueItemArrayTesting {
/// Test handling of enum array with unique items
pub fn new(unique_item_array: std::collections::HashSet<UniqueItemArray>) -> UniqueItemArrayTesting {
UniqueItemArrayTesting {
unique_item_array,
}
}
}

/// Helper object for the unique item array test
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum UniqueItemArray {
#[serde(rename = "unique_item_1")]
Variant1,
#[serde(rename = "unique_item_2")]
Variant2,
#[serde(rename = "unique_item_3")]
Variant3,
}

impl Default for UniqueItemArray {
fn default() -> UniqueItemArray {
Self::Variant1
}
}

Loading

0 comments on commit 8911740

Please sign in to comment.