Skip to content

[BUG] rust-server example client panics due to incorrect type of port argument #24515

Description

@vasilNnikolov

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions