Skip to content

Commit c97b63d

Browse files
euankwing328
authored andcommitted
[Rust] Implement 'object' type conversion (#6846)
* [Rust] Use serde Value for objects This hopefully fixes the previous TODO; it at least fixes compilation errors for the specific swagger model I'm working with. * [Rust] Update Cargo.toml to specify versions Letting the version float freely is scary, to say the least. This gives it a better chance at being future-proof. When the crate author had a recommended selector I picked that, otherwise I went semver compatible. * [Rust] Regenerate the example
1 parent 7755c7d commit c97b63d

File tree

18 files changed

+45
-368
lines changed

18 files changed

+45
-368
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RustClientCodegen.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ public RustClientCodegen() {
9999
typeMapping.put("file", "File");
100100
typeMapping.put("binary", "Vec<u8>");
101101
typeMapping.put("ByteArray", "String");
102-
// TODO what should 'object' mapped to
103-
typeMapping.put("object", "Object");
102+
typeMapping.put("object", "Value");
104103

105104
// no need for rust
106105
//importMapping = new HashMap<String, String>();

modules/swagger-codegen/src/main/resources/rust/Cargo.mustache

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ version = "{{{packageVersion}}}"
44
authors = ["Swagger Codegen team and contributors"]
55

66
[dependencies]
7-
serde = "*"
8-
serde_derive = "*"
9-
serde_yaml = "*"
10-
serde_json = "*"
11-
base64 = "*"
12-
futures = "*"
13-
hyper = "*"
14-
url = "*"
7+
serde = "1.0"
8+
serde_derive = "1.0"
9+
serde_yaml = "0.7"
10+
serde_json = "1.0"
11+
base64 = "~0.7.0"
12+
futures = "0.1.16"
13+
hyper = "0.11.6"
14+
url = "1.5"
1515

1616
[dev-dependencies]
1717
tokio-core = "*"

modules/swagger-codegen/src/main/resources/rust/model.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
/// {{{classname}}} : {{{description}}}
66
{{/description}}
77

8+
#[allow(unused_imports)]
9+
use serde_json::Value;
10+
811
#[derive(Debug, Serialize, Deserialize)]
912
pub struct {{classname}} {
1013
{{#vars}}

samples/client/petstore/rust/Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ version = "1.0.0"
44
authors = ["Swagger Codegen team and contributors"]
55

66
[dependencies]
7-
serde = "*"
8-
serde_derive = "*"
9-
serde_yaml = "*"
10-
serde_json = "*"
11-
base64 = "*"
12-
futures = "*"
13-
hyper = "*"
14-
url = "*"
7+
serde = "1.0"
8+
serde_derive = "1.0"
9+
serde_yaml = "0.7"
10+
serde_json = "1.0"
11+
base64 = "~0.7.0"
12+
futures = "0.1.16"
13+
hyper = "0.11.6"
14+
url = "1.5"
1515

1616
[dev-dependencies]
1717
tokio-core = "*"

samples/client/petstore/rust/src/models/api_response.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
/// ApiResponse : Describes the result of uploading an image resource
1212
13+
#[allow(unused_imports)]
14+
use serde_json::Value;
15+
1316
#[derive(Debug, Serialize, Deserialize)]
1417
pub struct ApiResponse {
1518
#[serde(rename = "code")]

samples/client/petstore/rust/src/models/category.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
/// Category : A category for a pet
1212
13+
#[allow(unused_imports)]
14+
use serde_json::Value;
15+
1316
#[derive(Debug, Serialize, Deserialize)]
1417
pub struct Category {
1518
#[serde(rename = "id")]

samples/client/petstore/rust/src/models/order.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
/// Order : An order for a pets from the pet store
1212
13+
#[allow(unused_imports)]
14+
use serde_json::Value;
15+
1316
#[derive(Debug, Serialize, Deserialize)]
1417
pub struct Order {
1518
#[serde(rename = "id")]

samples/client/petstore/rust/src/models/pet.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
/// Pet : A pet for sale in the pet store
1212
13+
#[allow(unused_imports)]
14+
use serde_json::Value;
15+
1316
#[derive(Debug, Serialize, Deserialize)]
1417
pub struct Pet {
1518
#[serde(rename = "id")]

samples/client/petstore/rust/src/models/tag.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
/// Tag : A tag for a pet
1212
13+
#[allow(unused_imports)]
14+
use serde_json::Value;
15+
1316
#[derive(Debug, Serialize, Deserialize)]
1417
pub struct Tag {
1518
#[serde(rename = "id")]

samples/client/petstore/rust/src/models/user.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
/// User : A User who is purchasing from the pet store
1212
13+
#[allow(unused_imports)]
14+
use serde_json::Value;
15+
1316
#[derive(Debug, Serialize, Deserialize)]
1417
pub struct User {
1518
#[serde(rename = "id")]

0 commit comments

Comments
 (0)