OpenAPITools / OpenAPITools/openapi-generator
[rust client] Incomplete type in response generates code that fails to compile
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
The Rust generated code fails to compile if the api defines a response type of object with no additional information. Other code generators like C# do generate code that compiles and runs even if it isn't a very useful response.
The errors look like:
error[E0412]: cannot find type `Value` in this scope
--> src\apis\file_api.rs:34:44
|
34 | fn clone(&self, ) -> Box<Future<Item = Value, Error = Error<serde_json::Value>>>;
| ^^^^^ not found in this scope
help: possible candidates are found in other modules, you can import them into scope
|
11 | use serde_json::Value;
|
11 | use serde_json::value::Value;
|
error[E0412]: cannot find type `Value` in this scope
--> src\apis\file_api.rs:39:44
|
39 | fn clone(&self, ) -> Box<Future<Item = Value, Error = Error<serde_json::Value>>> {
| ^^^^^ not found in this scope
help: possible candidates are found in other modules, you can import them into scope
|
11 | use serde_json::Value;
|
11 | use serde_json::value::Value;
openapi-generator version
3.3.2
OpenAPI declaration file content or url
{
"swagger": "2.0",
"info": {
"version": "v1.0",
"title": "test api"
},
"paths": {
"/api/clone": {
"put": {
"tags": [
"File"
],
"operationId": "Clone",
"consumes": [],
"produces": [
"application/json",
"text/json"
],
"parameters": [],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
}
}
}
}
}
}
Command line used for generation
java -jar openapi-generator-cli.jar generate -i api.json -g rust
Steps to reproduce
java -jar openapi-generator-cli.jar generate -i api.json -g rust
cargo build
Related issues/PRs
Suggest a fix/enhancement
It looks like the return type could be serde_json::Value instead of Value, maybe as simple as changing this line.
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 RustClientCodegen.java at the linked line and inspect how an empty object response is mapped. Reproduce the issue with the provided OpenAPI document and command, then run cargo build on the generated client. Done means the generated Rust code compiles for this response type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, rust
- Domain
- api, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100