swagger-api / swagger-api/swagger-codegen
[RUST] Add support for HTTPS
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Currently, the Rust client code generated will reject any REST endpoint using the "https" scheme.
Its very difficult to figure out how to support HTTPS / TLS using an older version of hyper used by swagger-codegen (0.11.27). The current version of hyper is 0.12.x (this was a major breaking change).
Swagger-codegen version
Swagger editor at https://editor.swagger.io/
Swagger declaration file content or url
Petstore yaml
Command line used for generation
Rust Client
Steps to reproduce
Try to use the generated rust client. Minimal code sample:
# Cargo.toml
[package]
name = "swagger_demo"
version = "0.1.0"
authors = ["Bryce Fisher-Fleig <email@domain.com>"]
edition = "2018"
[dependencies]
futures = "0.1.25"
hyper = { version = "0.11.27" }
swagger = { path = "../swagger" }
tokio-core = { version = "0.1.17" }
// src/main.rs
use futures::future::Future;
use hyper::client::Client;
use swagger::apis::{
configuration::Configuration,
client::APIClient,
Error,
PetApi
};
use tokio_core::reactor::Core;
fn main() {
let core = Core::new().unwrap();
let handle = core.handle();
let mut client = Client::new(&handle);
let mut c = Configuration::new(client);
// Use anything with HTTPS
c.base_path = "https://localhost/api".into();
let api_client = APIClient::new(c);
let pet_client = api_client.pet_api();
let result = pet_client.get_pet_by_id(1i64).wait();
match result {
Err(Error::Hyper(err)) => println!("Hyper Error: {:?}", err.description()),
Err(Error::Serde(err)) => println!("Serde Error: {:?}", err.description()),
Err(Error::ApiError(err)) => println!("Api Error: {:?}", err),
_ => println!("Something else"),
};
}
Running this code via cargo run results in the following output:
"Hyper Error: invalid URL, scheme must be http"
Related issues/PRs
https://github.com/swagger-api/swagger-codegen/issues/6250 -- the first bullet of including usage documentation
Suggest a fix/enhancement
I can tink of two possible paths forward:
- Document how to make TLS work somewhere in the generated output
- Upgrade to use a more recent version of hyper
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
Reproduce the failure with the generated Rust client using the Cargo.toml and src/main.rs example, focusing on Configuration.base_path and the hyper 0.11.27 dependency. Review the Rust generator output and related issue 6250, then establish whether the deliverable is HTTPS support or usage documentation; done means the chosen path is implemented and verified against the Petstore example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api, networking
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100