Skip to content

Commit

Permalink
chore(catalog): Set with_inner_type()
Browse files Browse the repository at this point in the history
This appears to be required when using hooks because the generated code
passes `self.inner` which is undefined without this:

    error[E0609]: no field `inner` on type `&client::Client`
        --> catalog-api-v1/src/client.rs:1646:18
         |
    1646 |         })(&self.inner, &request);
         |                  ^^^^^ unknown field
         |
         = note: available fields are: `baseurl`, `client`
  • Loading branch information
dcarley committed May 21, 2024
1 parent e15b8bc commit 8d3482e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions cli/catalog-api-v1/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn main() {
fn generate_client(spec: &OpenAPI) -> String {
let mut settings = progenitor::GenerationSettings::default();
settings.with_derive("PartialEq");
settings.with_inner_type(quote!(()));
settings.with_pre_hook(quote! {
|_, request: &reqwest::Request| {
let error_content = String::from("failed to parse body");
Expand Down
12 changes: 9 additions & 3 deletions cli/catalog-api-v1/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1524,33 +1524,35 @@ Version: v0.1.dev134+gd1854a6.d19800101*/
pub struct Client {
pub(crate) baseurl: String,
pub(crate) client: reqwest::Client,
pub(crate) inner: (),
}
impl Client {
/// Create a new client.
///
/// `baseurl` is the base URL provided to the internal
/// `reqwest::Client`, and should include a scheme and hostname,
/// as well as port and a path stem if applicable.
pub fn new(baseurl: &str) -> Self {
pub fn new(baseurl: &str, inner: ()) -> Self {
#[cfg(not(target_arch = "wasm32"))]
let client = {
let dur = std::time::Duration::from_secs(15);
reqwest::ClientBuilder::new().connect_timeout(dur).timeout(dur)
};
#[cfg(target_arch = "wasm32")]
let client = reqwest::ClientBuilder::new();
Self::new_with_client(baseurl, client.build().unwrap())
Self::new_with_client(baseurl, client.build().unwrap(), inner)
}
/// Construct a new client with an existing `reqwest::Client`,
/// allowing more control over its configuration.
///
/// `baseurl` is the base URL provided to the internal
/// `reqwest::Client`, and should include a scheme and hostname,
/// as well as port and a path stem if applicable.
pub fn new_with_client(baseurl: &str, client: reqwest::Client) -> Self {
pub fn new_with_client(baseurl: &str, client: reqwest::Client, inner: ()) -> Self {
Self {
baseurl: baseurl.to_string(),
client,
inner,
}
}
/// Get the base URL to which requests are made.
Expand All @@ -1568,6 +1570,10 @@ impl Client {
pub fn api_version(&self) -> &'static str {
"v0.1.dev134+gd1854a6.d19800101"
}
/// Return a reference to the inner type stored in `self`.
pub fn inner(&self) -> &() {
&self.inner
}
}
#[allow(clippy::all)]
impl Client {
Expand Down
2 changes: 1 addition & 1 deletion cli/flox-rust-sdk/src/providers/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub struct CatalogClient {
impl CatalogClient {
pub fn new(baseurl: &str) -> Self {
Self {
client: APIClient::new(baseurl),
client: APIClient::new(baseurl, ()),
}
}

Expand Down

0 comments on commit 8d3482e

Please sign in to comment.