Better Rust client imports (#3332)

* Better Rust client imports.

* No more "unused_imports" in models for serde_json::Value.
* No more compilation problem for apis requiring serde_json::Value.
* "crate::" prefix for models and apis imports, for compatibility with Rust 2018 edition.

* Rust samples regeneration using new code.
This commit is contained in:
Benoît Courtine
2019-07-18 11:08:48 +02:00
committed by Benjamin Gill
parent 0fec25e92e
commit 26b8d1f4c2
36 changed files with 126 additions and 165 deletions

View File

@@ -124,9 +124,9 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
// I tried to map as "std::io::File", but Reqwest multipart file requires a "AsRef<Path>" param.
// Getting a file from a Path is simple, but the opposite is difficult. So I map as "std::path::Path".
typeMapping.put("file", "std::path::PathBuf");
typeMapping.put("binary", "::models::File");
typeMapping.put("binary", "crate::models::File");
typeMapping.put("ByteArray", "String");
typeMapping.put("object", "Value");
typeMapping.put("object", "serde_json::Value");
// no need for rust
//importMapping = new HashMap<String, String>();
@@ -352,8 +352,8 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
}
// return fully-qualified model name
// ::models::{{classnameFile}}::{{classname}}
return "::models::" + toModelName(schemaType);
// crate::models::{{classnameFile}}::{{classname}}
return "crate::models::" + toModelName(schemaType);
}
@Override