Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add option to select HTTP client type #1079

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

wfchandler
Copy link
Contributor

Currently reqwest::Client is the only type we allow as the underlying HTTP client. Some consumers of Progenitor may want to use reqwest_middleware to enable conveniences like automatic retries and support for tracing.

Add a new with_client_type argument for GenerationSettings to allow callers to select which of these types to use as the client.

Currently `reqwest::Client` is the only type we allow as the underlying
HTTP client. Some consumers of Progenitor may want to use
`reqwest_middleware` to enable conveniences like automatic retries and
support for `tracing`.

Add a new `with_client_type` argument for `GenerationSettings` to allow
callers to select which of these types to use as the client.
Reqwest added the `from_parts` and `build_split` methods on
`RequestBuilder` for wasm targets with v0.12.5.

Bump Reqwest on the wasm example to that version.
Copy link
Collaborator

@ahl ahl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are significant obstacles to consider. For example, I don't think reqwest-middleware should become a dependency in omicron.

I would suggest we consider other approaches to allow for more inspection of CLI requests.

@@ -244,6 +265,7 @@ pub fn dependencies(builder: Generator, include_client: bool) -> Vec<String> {
format!("bytes = \"{}\"", DEPENDENCIES.bytes),
format!("futures-core = \"{}\"", DEPENDENCIES.futures),
format!("reqwest = {{ version = \"{}\", default-features=false, features = [\"json\", \"stream\"] }}", DEPENDENCIES.reqwest),
format!("reqwest-middleware = {{ version = \"{}\", default-features=false, features = [\"json\"] }}", DEPENDENCIES.reqwest_middleware),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to always include this dependency.

bytes = { workspace = true }
futures-core = { workspace = true }
percent-encoding = { workspace = true }
reqwest = { workspace = true }
reqwest-middleware = { workspace = true }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be a mandatory dependency

@@ -7,10 +7,12 @@ repository = "https://github.com/oxidecomputer/progenitor.git"
description = "An OpenAPI client generator - client support"

[dependencies]
anyhow = { workspace = true }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a step in the wrong direction. If we need a generic error, could we use Box?

Comment on lines +125 to +130
impl Default for ClientType {
fn default() -> Self {
Self::Reqwest
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you could derive default on enums and use a marker annotation

Comment on lines +432 to +433
ClientType::Reqwest => quote! { reqwest::Client },
ClientType::ReqwestMiddleware => quote! { reqwest_middleware::ClientWithMiddleware },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ClientType::Reqwest => quote! { reqwest::Client },
ClientType::ReqwestMiddleware => quote! { reqwest_middleware::ClientWithMiddleware },
ClientType::Reqwest => quote! { ::reqwest::Client },
ClientType::ReqwestMiddleware => quote! { ::reqwest_middleware::ClientWithMiddleware },

@@ -31,6 +31,7 @@ http = { workspace = true }
hyper = { workspace = true }
progenitor-client = { workspace = true }
reqwest = { workspace = true }
reqwest-middleware = { workspace = true }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what fails if this is not present?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants