Make the Rust codegen compile. (#6411)

* Use the right package name for the Rust crate.

* Change getters on models to return Option for non-required fields.

* Cleanup Rust generation and get example compiling again.

* Use underscore names for functions.
This commit is contained in:
Ahmed Charles
2017-09-01 09:06:55 -07:00
committed by wing328
parent adf5d643d5
commit 60766c6210
22 changed files with 346 additions and 399 deletions

View File

@@ -12,9 +12,12 @@
#[derive(Debug, Serialize, Deserialize)]
pub struct ApiResponse {
#[serde(rename = "code")] code: Option<i32>,
#[serde(rename = "type")] _type: Option<String>,
#[serde(rename = "message")] message: Option<String>
#[serde(rename = "code")]
code: Option<i32>,
#[serde(rename = "type")]
_type: Option<String>,
#[serde(rename = "message")]
message: Option<String>
}
impl ApiResponse {
@@ -36,8 +39,12 @@ impl ApiResponse {
self
}
pub fn code(&self) -> &i32 {
&self.code
pub fn code(&self) -> Option<&i32> {
self.code.as_ref()
}
pub fn reset_code(&mut self) {
self.code = None;
}
pub fn set__type(&mut self, _type: String) {
@@ -49,8 +56,12 @@ impl ApiResponse {
self
}
pub fn _type(&self) -> &String {
&self._type
pub fn _type(&self) -> Option<&String> {
self._type.as_ref()
}
pub fn reset__type(&mut self) {
self._type = None;
}
pub fn set_message(&mut self, message: String) {
@@ -62,8 +73,12 @@ impl ApiResponse {
self
}
pub fn message(&self) -> &String {
&self.message
pub fn message(&self) -> Option<&String> {
self.message.as_ref()
}
pub fn reset_message(&mut self) {
self.message = None;
}
}

View File

@@ -12,8 +12,10 @@
#[derive(Debug, Serialize, Deserialize)]
pub struct Category {
#[serde(rename = "id")] id: Option<i64>,
#[serde(rename = "name")] name: Option<String>
#[serde(rename = "id")]
id: Option<i64>,
#[serde(rename = "name")]
name: Option<String>
}
impl Category {
@@ -34,8 +36,12 @@ impl Category {
self
}
pub fn id(&self) -> &i64 {
&self.id
pub fn id(&self) -> Option<&i64> {
self.id.as_ref()
}
pub fn reset_id(&mut self) {
self.id = None;
}
pub fn set_name(&mut self, name: String) {
@@ -47,8 +53,12 @@ impl Category {
self
}
pub fn name(&self) -> &String {
&self.name
pub fn name(&self) -> Option<&String> {
self.name.as_ref()
}
pub fn reset_name(&mut self) {
self.name = None;
}
}

View File

@@ -12,13 +12,19 @@
#[derive(Debug, Serialize, Deserialize)]
pub struct Order {
#[serde(rename = "id")] id: Option<i64>,
#[serde(rename = "petId")] pet_id: Option<i64>,
#[serde(rename = "quantity")] quantity: Option<i32>,
#[serde(rename = "shipDate")] ship_date: Option<String>,
#[serde(rename = "id")]
id: Option<i64>,
#[serde(rename = "petId")]
pet_id: Option<i64>,
#[serde(rename = "quantity")]
quantity: Option<i32>,
#[serde(rename = "shipDate")]
ship_date: Option<String>,
/// Order Status
#[serde(rename = "status")] status: Option<String>,
#[serde(rename = "complete")] complete: Option<bool>
#[serde(rename = "status")]
status: Option<String>,
#[serde(rename = "complete")]
complete: Option<bool>
}
impl Order {
@@ -43,8 +49,12 @@ impl Order {
self
}
pub fn id(&self) -> &i64 {
&self.id
pub fn id(&self) -> Option<&i64> {
self.id.as_ref()
}
pub fn reset_id(&mut self) {
self.id = None;
}
pub fn set_pet_id(&mut self, pet_id: i64) {
@@ -56,8 +66,12 @@ impl Order {
self
}
pub fn pet_id(&self) -> &i64 {
&self.pet_id
pub fn pet_id(&self) -> Option<&i64> {
self.pet_id.as_ref()
}
pub fn reset_pet_id(&mut self) {
self.pet_id = None;
}
pub fn set_quantity(&mut self, quantity: i32) {
@@ -69,8 +83,12 @@ impl Order {
self
}
pub fn quantity(&self) -> &i32 {
&self.quantity
pub fn quantity(&self) -> Option<&i32> {
self.quantity.as_ref()
}
pub fn reset_quantity(&mut self) {
self.quantity = None;
}
pub fn set_ship_date(&mut self, ship_date: String) {
@@ -82,8 +100,12 @@ impl Order {
self
}
pub fn ship_date(&self) -> &String {
&self.ship_date
pub fn ship_date(&self) -> Option<&String> {
self.ship_date.as_ref()
}
pub fn reset_ship_date(&mut self) {
self.ship_date = None;
}
pub fn set_status(&mut self, status: String) {
@@ -95,8 +117,12 @@ impl Order {
self
}
pub fn status(&self) -> &String {
&self.status
pub fn status(&self) -> Option<&String> {
self.status.as_ref()
}
pub fn reset_status(&mut self) {
self.status = None;
}
pub fn set_complete(&mut self, complete: bool) {
@@ -108,8 +134,12 @@ impl Order {
self
}
pub fn complete(&self) -> &bool {
&self.complete
pub fn complete(&self) -> Option<&bool> {
self.complete.as_ref()
}
pub fn reset_complete(&mut self) {
self.complete = None;
}
}

View File

@@ -12,13 +12,19 @@
#[derive(Debug, Serialize, Deserialize)]
pub struct Pet {
#[serde(rename = "id")] id: Option<i64>,
#[serde(rename = "category")] category: Option<::models::Category>,
#[serde(rename = "name")] name: String,
#[serde(rename = "photoUrls")] photo_urls: Vec<String>,
#[serde(rename = "tags")] tags: Option<Vec<::models::Tag>>,
#[serde(rename = "id")]
id: Option<i64>,
#[serde(rename = "category")]
category: Option<::models::Category>,
#[serde(rename = "name")]
name: String,
#[serde(rename = "photoUrls")]
photo_urls: Vec<String>,
#[serde(rename = "tags")]
tags: Option<Vec<::models::Tag>>,
/// pet status in the store
#[serde(rename = "status")] status: Option<String>
#[serde(rename = "status")]
status: Option<String>
}
impl Pet {
@@ -43,8 +49,12 @@ impl Pet {
self
}
pub fn id(&self) -> &i64 {
&self.id
pub fn id(&self) -> Option<&i64> {
self.id.as_ref()
}
pub fn reset_id(&mut self) {
self.id = None;
}
pub fn set_category(&mut self, category: ::models::Category) {
@@ -56,8 +66,12 @@ impl Pet {
self
}
pub fn category(&self) -> &::models::Category {
&self.category
pub fn category(&self) -> Option<&::models::Category> {
self.category.as_ref()
}
pub fn reset_category(&mut self) {
self.category = None;
}
pub fn set_name(&mut self, name: String) {
@@ -73,6 +87,7 @@ impl Pet {
&self.name
}
pub fn set_photo_urls(&mut self, photo_urls: Vec<String>) {
self.photo_urls = photo_urls;
}
@@ -82,10 +97,11 @@ impl Pet {
self
}
pub fn photo_urls(&self) -> &Vec&lt;String&gt; {
pub fn photo_urls(&self) -> &Vec<String> {
&self.photo_urls
}
pub fn set_tags(&mut self, tags: Vec<::models::Tag>) {
self.tags = Some(tags);
}
@@ -95,8 +111,12 @@ impl Pet {
self
}
pub fn tags(&self) -> &Vec&lt;::models::Tag&gt; {
&self.tags
pub fn tags(&self) -> Option<&Vec<::models::Tag>> {
self.tags.as_ref()
}
pub fn reset_tags(&mut self) {
self.tags = None;
}
pub fn set_status(&mut self, status: String) {
@@ -108,8 +128,12 @@ impl Pet {
self
}
pub fn status(&self) -> &String {
&self.status
pub fn status(&self) -> Option<&String> {
self.status.as_ref()
}
pub fn reset_status(&mut self) {
self.status = None;
}
}

View File

@@ -12,8 +12,10 @@
#[derive(Debug, Serialize, Deserialize)]
pub struct Tag {
#[serde(rename = "id")] id: Option<i64>,
#[serde(rename = "name")] name: Option<String>
#[serde(rename = "id")]
id: Option<i64>,
#[serde(rename = "name")]
name: Option<String>
}
impl Tag {
@@ -34,8 +36,12 @@ impl Tag {
self
}
pub fn id(&self) -> &i64 {
&self.id
pub fn id(&self) -> Option<&i64> {
self.id.as_ref()
}
pub fn reset_id(&mut self) {
self.id = None;
}
pub fn set_name(&mut self, name: String) {
@@ -47,8 +53,12 @@ impl Tag {
self
}
pub fn name(&self) -> &String {
&self.name
pub fn name(&self) -> Option<&String> {
self.name.as_ref()
}
pub fn reset_name(&mut self) {
self.name = None;
}
}

View File

@@ -12,15 +12,23 @@
#[derive(Debug, Serialize, Deserialize)]
pub struct User {
#[serde(rename = "id")] id: Option<i64>,
#[serde(rename = "username")] username: Option<String>,
#[serde(rename = "firstName")] first_name: Option<String>,
#[serde(rename = "lastName")] last_name: Option<String>,
#[serde(rename = "email")] email: Option<String>,
#[serde(rename = "password")] password: Option<String>,
#[serde(rename = "phone")] phone: Option<String>,
#[serde(rename = "id")]
id: Option<i64>,
#[serde(rename = "username")]
username: Option<String>,
#[serde(rename = "firstName")]
first_name: Option<String>,
#[serde(rename = "lastName")]
last_name: Option<String>,
#[serde(rename = "email")]
email: Option<String>,
#[serde(rename = "password")]
password: Option<String>,
#[serde(rename = "phone")]
phone: Option<String>,
/// User Status
#[serde(rename = "userStatus")] user_status: Option<i32>
#[serde(rename = "userStatus")]
user_status: Option<i32>
}
impl User {
@@ -47,8 +55,12 @@ impl User {
self
}
pub fn id(&self) -> &i64 {
&self.id
pub fn id(&self) -> Option<&i64> {
self.id.as_ref()
}
pub fn reset_id(&mut self) {
self.id = None;
}
pub fn set_username(&mut self, username: String) {
@@ -60,8 +72,12 @@ impl User {
self
}
pub fn username(&self) -> &String {
&self.username
pub fn username(&self) -> Option<&String> {
self.username.as_ref()
}
pub fn reset_username(&mut self) {
self.username = None;
}
pub fn set_first_name(&mut self, first_name: String) {
@@ -73,8 +89,12 @@ impl User {
self
}
pub fn first_name(&self) -> &String {
&self.first_name
pub fn first_name(&self) -> Option<&String> {
self.first_name.as_ref()
}
pub fn reset_first_name(&mut self) {
self.first_name = None;
}
pub fn set_last_name(&mut self, last_name: String) {
@@ -86,8 +106,12 @@ impl User {
self
}
pub fn last_name(&self) -> &String {
&self.last_name
pub fn last_name(&self) -> Option<&String> {
self.last_name.as_ref()
}
pub fn reset_last_name(&mut self) {
self.last_name = None;
}
pub fn set_email(&mut self, email: String) {
@@ -99,8 +123,12 @@ impl User {
self
}
pub fn email(&self) -> &String {
&self.email
pub fn email(&self) -> Option<&String> {
self.email.as_ref()
}
pub fn reset_email(&mut self) {
self.email = None;
}
pub fn set_password(&mut self, password: String) {
@@ -112,8 +140,12 @@ impl User {
self
}
pub fn password(&self) -> &String {
&self.password
pub fn password(&self) -> Option<&String> {
self.password.as_ref()
}
pub fn reset_password(&mut self) {
self.password = None;
}
pub fn set_phone(&mut self, phone: String) {
@@ -125,8 +157,12 @@ impl User {
self
}
pub fn phone(&self) -> &String {
&self.phone
pub fn phone(&self) -> Option<&String> {
self.phone.as_ref()
}
pub fn reset_phone(&mut self) {
self.phone = None;
}
pub fn set_user_status(&mut self, user_status: i32) {
@@ -138,8 +174,12 @@ impl User {
self
}
pub fn user_status(&self) -> &i32 {
&self.user_status
pub fn user_status(&self) -> Option<&i32> {
self.user_status.as_ref()
}
pub fn reset_user_status(&mut self) {
self.user_status = None;
}
}