swagger-api / swagger-api/swagger-codegen
[Rust] EVE Online ESI generated code does not build
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I am trying to build Rust bindings for EVE Online's ESI EVE Swagger Interface. Unfortunately, lists in parameters aren't always being handled correctly. Specifically, the generated API code tries to apply join(",") to Vecs of various incompatible types, including i32 and Vec<i32>.
Swagger-codegen version
I have tried with multiple versions; all seem to generate the same code. I am currently working with master from Git (f6fca7640 2018-05-03).
Swagger declaration file content or url
https://esi.tech.ccp.is/latest/swagger.json?datasource=tranquility
Command line used for generation
java -jar swagger-codegen-cli.jar generate
-i https://esi.tech.ccp.is/latest/swagger.json?datasource=tranquility
-l rust
--invoker-package esi
--api-package esi
--model-package esi
-DpackageName=esi
-o .
Steps to reproduce
Run the generator as described above. cargo build (any recent Rust version).
Related issues/PRs
None found.
Suggest a fix/enhancement
I've started to fix this: the following gross-hack patch to api.mustache gets all the cases for Vec<i32> and the like.
diff --git a/modules/swagger-codegen/src/main/resources/rust/api.mustache b/modules/swagger-codegen/src/main/resources/rust/api.mustache
index 55604ca79..ab6c69334 100644
--- a/modules/swagger-codegen/src/main/resources/rust/api.mustache
+++ b/modules/swagger-codegen/src/main/resources/rust/api.mustache
@@ -87,7 +87,7 @@ impl<C: hyper::client::Connect>{{classname}} for {{classname}}Client<C> {
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
{{#queryParams}}
- query.append_pair("{{baseName}}", &{{paramName}}{{#isListContainer}}.join(","){{/isListContainer}}.to_string());
+ query.append_pair("{{baseName}}", &{{paramName}}{{#isListContainer}}.iter().map(|v| v.to_string()).collect::<Vec<String>>().join(","){{/isListContainer}}.to_string());
{{/queryParams}}
{{#hasAuthMethods}}
for (key, val) in &auth_query {
Unfortunately in one case (/route/<origin>/<destination>) a parameter is a list of pairs, which gets translated to a list of lists i.e. Vec<Vec<i32>> which still fails to join(). I could conceivably kludge around this, but it seems like someone with a better understanding of the mustache templating being used here could put some more principled fix in place.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with modules/swagger-codegen/src/main/resources/rust/api.mustache and reproduce the issue using the documented Java generation command, then run cargo build on the generated client. Check how list and nested-list query parameters are rendered, including the route parameter case; done means the generated Rust code builds for the supplied ESI Swagger document.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100