feat(rust,client): derive Default for operation parameter structs (#10432)

* feat(rust,client): derive Default for model & api structs

This makes operations with many parameters easier to work with.

* chore(rust,client): capture sample changes: derive Default
This commit is contained in:
Pi Delport 2021-09-23 05:31:09 +02:00 committed by GitHub
parent 7c133be617
commit 31342580cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 38 additions and 38 deletions

View File

@ -56,7 +56,7 @@ pub enum {{{classname}}} {
{{!-- for non-enum schemas --}} {{!-- for non-enum schemas --}}
{{^isEnum}} {{^isEnum}}
{{^discriminator}} {{^discriminator}}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct {{{classname}}} { pub struct {{{classname}}} {
{{#vars}} {{#vars}}
{{#description}} {{#description}}

View File

@ -11,7 +11,7 @@ use super::{Error, configuration};
{{#allParams}} {{#allParams}}
{{#-first}} {{#-first}}
/// struct for passing parameters to the method `{{operationId}}` /// struct for passing parameters to the method `{{operationId}}`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct {{{operationIdCamelCase}}}Params { pub struct {{{operationIdCamelCase}}}Params {
{{/-first}} {{/-first}}
{{#description}} {{#description}}

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct ApiResponse { pub struct ApiResponse {
#[serde(rename = "code", skip_serializing_if = "Option::is_none")] #[serde(rename = "code", skip_serializing_if = "Option::is_none")]
pub code: Option<i32>, pub code: Option<i32>,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Category { pub struct Category {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")] #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>, pub id: Option<i64>,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Order { pub struct Order {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")] #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>, pub id: Option<i64>,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Pet { pub struct Pet {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")] #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>, pub id: Option<i64>,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Tag { pub struct Tag {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")] #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>, pub id: Option<i64>,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct User { pub struct User {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")] #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>, pub id: Option<i64>,

View File

@ -15,14 +15,14 @@ use crate::apis::ResponseContent;
use super::{Error, configuration}; use super::{Error, configuration};
/// struct for passing parameters to the method `add_pet` /// struct for passing parameters to the method `add_pet`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct AddPetParams { pub struct AddPetParams {
/// Pet object that needs to be added to the store /// Pet object that needs to be added to the store
pub pet: crate::models::Pet pub pet: crate::models::Pet
} }
/// struct for passing parameters to the method `delete_pet` /// struct for passing parameters to the method `delete_pet`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct DeletePetParams { pub struct DeletePetParams {
/// Pet id to delete /// Pet id to delete
pub pet_id: i64, pub pet_id: i64,
@ -30,35 +30,35 @@ pub struct DeletePetParams {
} }
/// struct for passing parameters to the method `find_pets_by_status` /// struct for passing parameters to the method `find_pets_by_status`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct FindPetsByStatusParams { pub struct FindPetsByStatusParams {
/// Status values that need to be considered for filter /// Status values that need to be considered for filter
pub status: Vec<String> pub status: Vec<String>
} }
/// struct for passing parameters to the method `find_pets_by_tags` /// struct for passing parameters to the method `find_pets_by_tags`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct FindPetsByTagsParams { pub struct FindPetsByTagsParams {
/// Tags to filter by /// Tags to filter by
pub tags: Vec<String> pub tags: Vec<String>
} }
/// struct for passing parameters to the method `get_pet_by_id` /// struct for passing parameters to the method `get_pet_by_id`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct GetPetByIdParams { pub struct GetPetByIdParams {
/// ID of pet to return /// ID of pet to return
pub pet_id: i64 pub pet_id: i64
} }
/// struct for passing parameters to the method `update_pet` /// struct for passing parameters to the method `update_pet`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct UpdatePetParams { pub struct UpdatePetParams {
/// Pet object that needs to be added to the store /// Pet object that needs to be added to the store
pub pet: crate::models::Pet pub pet: crate::models::Pet
} }
/// struct for passing parameters to the method `update_pet_with_form` /// struct for passing parameters to the method `update_pet_with_form`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct UpdatePetWithFormParams { pub struct UpdatePetWithFormParams {
/// ID of pet that needs to be updated /// ID of pet that needs to be updated
pub pet_id: i64, pub pet_id: i64,
@ -69,7 +69,7 @@ pub struct UpdatePetWithFormParams {
} }
/// struct for passing parameters to the method `upload_file` /// struct for passing parameters to the method `upload_file`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct UploadFileParams { pub struct UploadFileParams {
/// ID of pet to update /// ID of pet to update
pub pet_id: i64, pub pet_id: i64,

View File

@ -15,21 +15,21 @@ use crate::apis::ResponseContent;
use super::{Error, configuration}; use super::{Error, configuration};
/// struct for passing parameters to the method `delete_order` /// struct for passing parameters to the method `delete_order`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct DeleteOrderParams { pub struct DeleteOrderParams {
/// ID of the order that needs to be deleted /// ID of the order that needs to be deleted
pub order_id: String pub order_id: String
} }
/// struct for passing parameters to the method `get_order_by_id` /// struct for passing parameters to the method `get_order_by_id`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct GetOrderByIdParams { pub struct GetOrderByIdParams {
/// ID of pet that needs to be fetched /// ID of pet that needs to be fetched
pub order_id: i64 pub order_id: i64
} }
/// struct for passing parameters to the method `place_order` /// struct for passing parameters to the method `place_order`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct PlaceOrderParams { pub struct PlaceOrderParams {
/// order placed for purchasing the pet /// order placed for purchasing the pet
pub order: crate::models::Order pub order: crate::models::Order

View File

@ -15,42 +15,42 @@ use crate::apis::ResponseContent;
use super::{Error, configuration}; use super::{Error, configuration};
/// struct for passing parameters to the method `create_user` /// struct for passing parameters to the method `create_user`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct CreateUserParams { pub struct CreateUserParams {
/// Created user object /// Created user object
pub user: crate::models::User pub user: crate::models::User
} }
/// struct for passing parameters to the method `create_users_with_array_input` /// struct for passing parameters to the method `create_users_with_array_input`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct CreateUsersWithArrayInputParams { pub struct CreateUsersWithArrayInputParams {
/// List of user object /// List of user object
pub user: Vec<crate::models::User> pub user: Vec<crate::models::User>
} }
/// struct for passing parameters to the method `create_users_with_list_input` /// struct for passing parameters to the method `create_users_with_list_input`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct CreateUsersWithListInputParams { pub struct CreateUsersWithListInputParams {
/// List of user object /// List of user object
pub user: Vec<crate::models::User> pub user: Vec<crate::models::User>
} }
/// struct for passing parameters to the method `delete_user` /// struct for passing parameters to the method `delete_user`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct DeleteUserParams { pub struct DeleteUserParams {
/// The name that needs to be deleted /// The name that needs to be deleted
pub username: String pub username: String
} }
/// struct for passing parameters to the method `get_user_by_name` /// struct for passing parameters to the method `get_user_by_name`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct GetUserByNameParams { pub struct GetUserByNameParams {
/// The name that needs to be fetched. Use user1 for testing. /// The name that needs to be fetched. Use user1 for testing.
pub username: String pub username: String
} }
/// struct for passing parameters to the method `login_user` /// struct for passing parameters to the method `login_user`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct LoginUserParams { pub struct LoginUserParams {
/// The user name for login /// The user name for login
pub username: String, pub username: String,
@ -59,7 +59,7 @@ pub struct LoginUserParams {
} }
/// struct for passing parameters to the method `update_user` /// struct for passing parameters to the method `update_user`
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct UpdateUserParams { pub struct UpdateUserParams {
/// name that need to be deleted /// name that need to be deleted
pub username: String, pub username: String,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct ApiResponse { pub struct ApiResponse {
#[serde(rename = "code", skip_serializing_if = "Option::is_none")] #[serde(rename = "code", skip_serializing_if = "Option::is_none")]
pub code: Option<i32>, pub code: Option<i32>,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Category { pub struct Category {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")] #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>, pub id: Option<i64>,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Order { pub struct Order {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")] #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>, pub id: Option<i64>,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Pet { pub struct Pet {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")] #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>, pub id: Option<i64>,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Tag { pub struct Tag {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")] #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>, pub id: Option<i64>,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct User { pub struct User {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")] #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>, pub id: Option<i64>,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct ApiResponse { pub struct ApiResponse {
#[serde(rename = "code", skip_serializing_if = "Option::is_none")] #[serde(rename = "code", skip_serializing_if = "Option::is_none")]
pub code: Option<i32>, pub code: Option<i32>,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Category { pub struct Category {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")] #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>, pub id: Option<i64>,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Order { pub struct Order {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")] #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>, pub id: Option<i64>,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Pet { pub struct Pet {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")] #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>, pub id: Option<i64>,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Tag { pub struct Tag {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")] #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>, pub id: Option<i64>,

View File

@ -12,7 +12,7 @@
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct User { pub struct User {
#[serde(rename = "id", skip_serializing_if = "Option::is_none")] #[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<i64>, pub id: Option<i64>,