Rust reqwest improve (#1890)

* Resolves #525 for Rust client generator with reqwest library.

* Use Reqwest "query" method to generate query URL.

* urlencode URL string parameters.

* Generate rust-reqwest client, and verify it compiles and work as intended.

* Map file params (to "&std::path::Path") and support multipart operations (with file params) in Reqwest library.

* Cleanup: template compression to remove unecessary blank lines in generated code.
This commit is contained in:
Benoît Courtine
2019-02-01 08:02:16 +01:00
committed by William Cheng
parent 16f52cf2ad
commit 888068d122
18 changed files with 324 additions and 330 deletions

View File

@@ -119,8 +119,11 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.put("date", "string");
typeMapping.put("DateTime", "String");
typeMapping.put("password", "String");
// TODO(farcaller): map file
typeMapping.put("file", "::models::File");
// TODO(bcourtine): review file mapping.
// 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".
// Reference is required here because Path does not implement the "Sized" trait.
typeMapping.put("file", "&std::path::Path");
typeMapping.put("binary", "::models::File");
typeMapping.put("ByteArray", "String");
typeMapping.put("object", "Value");
@@ -379,7 +382,6 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
Map<String, Object> objectMap = (Map<String, Object>) objs.get("operations");
@SuppressWarnings("unchecked")
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
Set<String> headerKeys = new HashSet<>();
for (CodegenOperation operation : operations) {
// http method verb conversion, depending on client library (e.g. Hyper: PUT => Put, Reqwest: PUT => put)
if (HYPER_LIBRARY.equals(getLibrary())) {
@@ -439,9 +441,6 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
}*/
}
additionalProperties.put("headerKeys", headerKeys);
additionalProperties.putIfAbsent("authHeaderKey", "api-key");
return objs;
}