[rust] Fix generation for optional and nullable fields (double option pattern) (#13177)

* Fix generation for optional and nullable fields (double option pattern)

* Only import serde_with if necessary
This commit is contained in:
Jacob Halsey
2022-10-17 08:44:18 +01:00
committed by GitHub
parent 53dc385fc6
commit c1c9cb2192
31 changed files with 343 additions and 15 deletions

View File

@@ -7,6 +7,7 @@ docs/ApiResponse.md
docs/Baz.md
docs/Category.md
docs/FakeApi.md
docs/OptionalTesting.md
docs/Order.md
docs/Pet.md
docs/PetApi.md
@@ -35,6 +36,7 @@ src/models/baz.rs
src/models/category.rs
src/models/mod.rs
src/models/model_return.rs
src/models/optional_testing.rs
src/models/order.rs
src/models/pet.rs
src/models/property_test.rs

View File

@@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
serde = "^1.0"
serde_derive = "^1.0"
serde_with = "^2.0"
serde_json = "^1.0"
url = "^2.2"
uuid = { version = "^1.0", features = ["serde"] }

View File

@@ -56,6 +56,7 @@ Class | Method | HTTP request | Description
- [ApiResponse](docs/ApiResponse.md)
- [Baz](docs/Baz.md)
- [Category](docs/Category.md)
- [OptionalTesting](docs/OptionalTesting.md)
- [Order](docs/Order.md)
- [Pet](docs/Pet.md)
- [PropertyTest](docs/PropertyTest.md)

View File

@@ -0,0 +1,14 @@
# OptionalTesting
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**optional_nonnull** | Option<**String**> | | [optional]
**required_nonnull** | **String** | |
**optional_nullable** | Option<**String**> | | [optional]
**required_nullable** | Option<**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)

View File

@@ -6,6 +6,8 @@ pub mod baz;
pub use self::baz::Baz;
pub mod category;
pub use self::category::Category;
pub mod optional_testing;
pub use self::optional_testing::OptionalTesting;
pub mod order;
pub use self::order::Order;
pub mod pet;

View File

@@ -0,0 +1,39 @@
/*
* 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
*/
/// OptionalTesting : Test handling of optional and nullable fields
#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct OptionalTesting {
#[serde(rename = "optional_nonnull", skip_serializing_if = "Option::is_none")]
pub optional_nonnull: Option<String>,
#[serde(rename = "required_nonnull")]
pub required_nonnull: String,
#[serde(rename = "optional_nullable", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub optional_nullable: Option<Option<String>>,
#[serde(rename = "required_nullable", deserialize_with = "Option::deserialize")]
pub required_nullable: Option<String>,
}
impl OptionalTesting {
/// Test handling of optional and nullable fields
pub fn new(required_nonnull: String, required_nullable: Option<String>) -> OptionalTesting {
OptionalTesting {
optional_nonnull: None,
required_nonnull,
optional_nullable: None,
required_nullable,
}
}
}