OpenAPITools / OpenAPITools/openapi-generator

[BUG][RUST][CLIENT][HYPER] Rust hyper client can't be used with threads.

Open
#19,208 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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 rust hyper client cannot be used in threads as it isn't Send friendly. Something like this will fail to compile:

#[tokio::main]
async fn main() {
    tokio::spawn(async move {
        let client = APIClient::new(Configuration::new());
        let _result = client.pet_api().get_pet_by_id(5).await;
    });
}
openapi-generator version

master and the latest release

OpenAPI declaration file content or url

This is an issue with any OpenAPI endpoint. It can be reproduced with the PetStore example. https://petstore.swagger.io/v2/swagger.json

Generation Details

openapi-generator-cli generate -i https://petstore.swagger.io/v2/swagger.json -g rust --skip-validate-spec -o petstore-hyper --library hyper --package-name petstore-hyper

Steps to reproduce

Set up a main.rs file like so:

use petstore_hyper::apis::client::APIClient;
use petstore_hyper::apis::configuration::Configuration;

#[tokio::main]
async fn main() {
    tokio::spawn(async move {
        let client = APIClient::new(Configuration::new());
        let _result = client.pet_api().get_pet_by_id(5).await;
    });
}

Add it to Cargo.toml

[[bin]]
name = "main"
path = "src/main.rs"

cargo build will fail.

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/pull/19207

Suggest a fix

https://github.com/OpenAPITools/openapi-generator/pull/19207

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated Rust hyper client entry points in src/main.rs, Cargo.toml, APIClient, and Configuration, then reproduce the failure using the PetStore generation command and cargo build. Review pull request 19207 as the work is already proposed; done means the tokio::spawn example compiles and runs with the generated client.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.