Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nullable fields in the Rust generator #2353

Merged
merged 2 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ pub struct {{{classname}}} {
/// {{{description}}}
{{/description}}
#[serde(rename = "{{{baseName}}}")]
pub {{{name}}}: {{^required}}Option<{{/required}}{{{dataType}}}{{^required}}>{{/required}},
pub {{{name}}}: {{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{^required}}Option<{{/required}}{{{dataType}}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^required}}>{{/required}},
{{/vars}}
}

impl {{{classname}}} {
{{#description}}
/// {{{description}}}
{{/description}}
pub fn new({{#requiredVars}}{{{name}}}: {{{dataType}}}{{^-last}}, {{/-last}}{{/requiredVars}}) -> {{{classname}}} {
pub fn new({{#requiredVars}}{{{name}}}: {{#isNullable}}Option<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}}{{^-last}}, {{/-last}}{{/requiredVars}}) -> {{{classname}}} {
{{{classname}}} {
{{#vars}}
{{{name}}}: {{#required}}{{{name}}}{{/required}}{{^required}}{{#isListContainer}}None{{/isListContainer}}{{#isMapContainer}}None{{/isMapContainer}}{{^isContainer}}None{{/isContainer}}{{/required}},
Expand Down
11 changes: 11 additions & 0 deletions samples/client/petstore/rust/docs/InlineObject.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# InlineObject

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**name** | **String** | Updated name of the pet | [optional]
**status** | **String** | Updated status of the pet | [optional]

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


11 changes: 11 additions & 0 deletions samples/client/petstore/rust/docs/InlineObject1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# InlineObject1

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**additional_metadata** | **String** | Additional data to pass to server | [optional]
**file** | [***&std::path::Path**](&std::path::Path.md) | file to upload | [optional]

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


32 changes: 32 additions & 0 deletions samples/client/petstore/rust/src/models/inline_object.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.
*
* OpenAPI spec version: 1.0.0
*
* Generated by: https://openapi-generator.tech
*/


#[allow(unused_imports)]
use serde_json::Value;

#[derive(Debug, Serialize, Deserialize)]
pub struct InlineObject {
/// Updated name of the pet
#[serde(rename = "name")]
pub name: Option<String>,
/// Updated status of the pet
#[serde(rename = "status")]
pub status: Option<String>,
}

impl InlineObject {
pub fn new() -> InlineObject {
InlineObject {
name: None,
status: None,
}
}
}
32 changes: 32 additions & 0 deletions samples/client/petstore/rust/src/models/inline_object_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.
*
* OpenAPI spec version: 1.0.0
*
* Generated by: https://openapi-generator.tech
*/


#[allow(unused_imports)]
use serde_json::Value;

#[derive(Debug, Serialize, Deserialize)]
pub struct InlineObject1 {
/// Additional data to pass to server
#[serde(rename = "additionalMetadata")]
pub additional_metadata: Option<String>,
/// file to upload
#[serde(rename = "file")]
pub file: Option<&std::path::Path>,
}

impl InlineObject1 {
pub fn new() -> InlineObject1 {
InlineObject1 {
additional_metadata: None,
file: None,
}
}
}