Bug Report Checklist
Description
The example_client-client example generated from the rust-server generator panics due to a type error.
openapi-generator version
openapi-generator-cli 7.25.0-SNAPSHOT
commit : b8aee7f
built : -999999999-01-01T00:00:00+18:00
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech/
OpenAPI declaration file content or url
The default petstore.yaml produces the error.
Generation Details
Steps to reproduce
- generate the rust crate:
docker run --rm -v $PWD:/local openapitools/openapi-generator-cli generate -i /local/petstore.yml -g rust-server -o /local/out/rust-server/
- change the owner:
sudo chown -R $USER:$GROUP out/
- run the client example with the command from the README:
cd out/rust-server && cargo run --example openapi_client-client FindPetsByStatus
output:
Running `target/debug/examples/openapi_client-client FindPetsByStatus`
thread 'main' (26660) panicked at examples/client/main.rs:115:17:
Mismatch between definition and access of `port`. Could not downcast to u16, need to downcast to alloc::string::String
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Related issues/PRs
None
Suggest a fix
The cause of the bug is on lines 112 to 115 of the examples/client/main.rs file:
let base_url = format!("{}://{}:{}",
if is_https { "https" } else { "http" },
matches.get_one::<String>("host").unwrap(),
matches.get_one::<u16>("port").unwrap());
The command line arguments are strings, but the code tries to convert port to u16. Since the value goes into a string substitution, we can call matches.get_one::<String>("port").unwrap() instead, and let a non-integer port error be caught further down. Alternatively, the whole command line argument could be re-written to be a struct with clap macros on the fields.
If the maintaners confirm, i can open a PR.
Bug Report Checklist
Description
The
example_client-clientexample generated from therust-servergenerator panics due to a type error.openapi-generator version
OpenAPI declaration file content or url
The default
petstore.yamlproduces the error.Generation Details
Steps to reproduce
docker run --rm -v $PWD:/local openapitools/openapi-generator-cli generate -i /local/petstore.yml -g rust-server -o /local/out/rust-server/sudo chown -R $USER:$GROUP out/cd out/rust-server && cargo run --example openapi_client-client FindPetsByStatusoutput:
Related issues/PRs
None
Suggest a fix
The cause of the bug is on lines 112 to 115 of the
examples/client/main.rsfile:The command line arguments are strings, but the code tries to convert
porttou16. Since the value goes into a string substitution, we can callmatches.get_one::<String>("port").unwrap()instead, and let a non-integer port error be caught further down. Alternatively, the whole command line argument could be re-written to be a struct with clap macros on the fields.If the maintaners confirm, i can open a PR.