forked from loafle/openapi-generator-original
Support nullable fields in the Rust generator (#2353)
* Use Option for nullable fields in Rust (closes #2337) * Update Rust's petstore
This commit is contained in:
parent
d2ce584a3a
commit
a0d907cf27
@ -15,7 +15,7 @@ pub struct {{{classname}}} {
|
|||||||
/// {{{description}}}
|
/// {{{description}}}
|
||||||
{{/description}}
|
{{/description}}
|
||||||
#[serde(rename = "{{{baseName}}}")]
|
#[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}}
|
{{/vars}}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ impl {{{classname}}} {
|
|||||||
{{#description}}
|
{{#description}}
|
||||||
/// {{{description}}}
|
/// {{{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}}} {
|
{{{classname}}} {
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
{{{name}}}: {{#required}}{{{name}}}{{/required}}{{^required}}{{#isListContainer}}None{{/isListContainer}}{{#isMapContainer}}None{{/isMapContainer}}{{^isContainer}}None{{/isContainer}}{{/required}},
|
{{{name}}}: {{#required}}{{{name}}}{{/required}}{{^required}}{{#isListContainer}}None{{/isListContainer}}{{#isMapContainer}}None{{/isMapContainer}}{{^isContainer}}None{{/isContainer}}{{/required}},
|
||||||
|
11
samples/client/petstore/rust/docs/InlineObject.md
Normal file
11
samples/client/petstore/rust/docs/InlineObject.md
Normal file
@ -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
samples/client/petstore/rust/docs/InlineObject1.md
Normal file
11
samples/client/petstore/rust/docs/InlineObject1.md
Normal file
@ -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
samples/client/petstore/rust/src/models/inline_object.rs
Normal file
32
samples/client/petstore/rust/src/models/inline_object.rs
Normal file
@ -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
samples/client/petstore/rust/src/models/inline_object_1.rs
Normal file
32
samples/client/petstore/rust/src/models/inline_object_1.rs
Normal file
@ -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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user