From d329bc0912210ea9dccb9b171cbf51b36557cc73 Mon Sep 17 00:00:00 2001 From: Dillen Meijboom Date: Wed, 26 Apr 2023 06:50:04 +0200 Subject: [PATCH] Add support for wasm (#278) --- .github/workflows/rust.yml | 26 ++++++ Cargo.lock | 86 ++++++++++++++++--- Cargo.toml | 1 + example-wasm/.cargo/config | 2 + example-wasm/Cargo.toml | 19 ++++ example-wasm/build.rs | 22 +++++ example-wasm/release.toml | 1 + example-wasm/src/main.rs | 15 ++++ example-wasm/tests/client.rs | 11 +++ progenitor-client/src/progenitor_client.rs | 6 ++ progenitor-impl/src/lib.rs | 19 ++-- .../tests/output/buildomat-builder-tagged.out | 17 ++-- .../tests/output/buildomat-builder.out | 17 ++-- .../tests/output/buildomat-positional.out | 17 ++-- .../tests/output/keeper-builder-tagged.out | 17 ++-- .../tests/output/keeper-builder.out | 17 ++-- .../tests/output/keeper-positional.out | 17 ++-- .../tests/output/nexus-builder-tagged.out | 17 ++-- .../tests/output/nexus-builder.out | 17 ++-- .../tests/output/nexus-positional.out | 17 ++-- .../output/param-overrides-builder-tagged.out | 17 ++-- .../tests/output/param-overrides-builder.out | 17 ++-- .../output/param-overrides-positional.out | 17 ++-- .../output/propolis-server-builder-tagged.out | 17 ++-- .../tests/output/propolis-server-builder.out | 17 ++-- .../output/propolis-server-positional.out | 17 ++-- .../output/test_default_params_builder.out | 17 ++-- .../output/test_default_params_positional.out | 17 ++-- .../tests/output/test_freeform_response.out | 17 ++-- .../tests/output/test_renamed_parameters.out | 17 ++-- 30 files changed, 377 insertions(+), 154 deletions(-) create mode 100644 example-wasm/.cargo/config create mode 100644 example-wasm/Cargo.toml create mode 100644 example-wasm/build.rs create mode 100644 example-wasm/release.toml create mode 100644 example-wasm/src/main.rs create mode 100644 example-wasm/tests/client.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2183428..647b84b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -60,3 +60,29 @@ jobs: run: cargo build --locked --tests --verbose - name: Run tests run: cargo test --locked --verbose + + test-wasm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install nightly + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + components: rustfmt + default: false + target: wasm32-unknown-unknown + - uses: nanasess/setup-chromedriver@v1 + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: rustfmt + default: true + target: wasm32-unknown-unknown + - name: Install wasm-bindgen-cli + run: cargo install --version 0.2.84 wasm-bindgen-cli + - name: Run tests + run: | + cd example-wasm + CHROMEDRIVER=$(which chromedriver) cargo test --target wasm32-unknown-unknown --locked --verbose diff --git a/Cargo.lock b/Cargo.lock index db3813c..3b65cb0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -292,6 +292,16 @@ dependencies = [ "windows-sys 0.42.0", ] +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + [[package]] name = "core-foundation" version = "0.9.2" @@ -503,6 +513,21 @@ dependencies = [ "uuid", ] +[[package]] +name = "example-wasm" +version = "0.1.0" +dependencies = [ + "base64", + "chrono", + "progenitor", + "progenitor-client", + "reqwest", + "serde", + "serde_json", + "uuid", + "wasm-bindgen-test", +] + [[package]] name = "expectorate" version = "1.0.7" @@ -668,8 +693,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi 0.10.2+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] @@ -921,9 +948,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.59" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" dependencies = [ "wasm-bindgen", ] @@ -1589,6 +1616,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "scopeguard" version = "1.1.0" @@ -2268,6 +2301,7 @@ checksum = "5b55a3fef2a1e3b3a00ce878640918820d3c51081576ac657d23af9fc7928fdb" dependencies = [ "getrandom", "serde", + "wasm-bindgen", ] [[package]] @@ -2317,9 +2351,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.82" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2327,9 +2361,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.82" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" dependencies = [ "bumpalo", "log", @@ -2342,9 +2376,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.28" +version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" +checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" dependencies = [ "cfg-if", "js-sys", @@ -2354,9 +2388,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.82" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2364,9 +2398,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.82" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", @@ -2377,9 +2411,33 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.82" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" + +[[package]] +name = "wasm-bindgen-test" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db36fc0f9fb209e88fb3642590ae0205bb5a56216dabd963ba15879fe53a30b" +dependencies = [ + "console_error_panic_hook", + "js-sys", + "scoped-tls", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-test-macro", +] + +[[package]] +name = "wasm-bindgen-test-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0734759ae6b3b1717d661fe4f016efcfb9828f5edb4520c18eaee05af3b43be9" +dependencies = [ + "proc-macro2", + "quote", +] [[package]] name = "wasm-streams" diff --git a/Cargo.toml b/Cargo.toml index 5539eed..86711a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = [ "example-build", "example-macro", + "example-wasm", "progenitor", "progenitor-client", "progenitor-impl", diff --git a/example-wasm/.cargo/config b/example-wasm/.cargo/config new file mode 100644 index 0000000..4ec2f3b --- /dev/null +++ b/example-wasm/.cargo/config @@ -0,0 +1,2 @@ +[target.wasm32-unknown-unknown] +runner = 'wasm-bindgen-test-runner' diff --git a/example-wasm/Cargo.toml b/example-wasm/Cargo.toml new file mode 100644 index 0000000..ee40647 --- /dev/null +++ b/example-wasm/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "example-wasm" +version = "0.1.0" +edition = "2021" + +[dependencies] +chrono = { version = "0.4", features = ["serde"] } +progenitor-client = { path = "../progenitor-client" } +reqwest = { version = "0.11.16", features = ["json", "stream"] } +base64 = "0.21" +serde = { version = "1.0", features = ["derive"] } +uuid = { version = "1.3", features = ["serde", "v4", "js"] } + +[dev-dependencies] +wasm-bindgen-test = "0.3.34" + +[build-dependencies] +progenitor = { path = "../progenitor" } +serde_json = "1.0" diff --git a/example-wasm/build.rs b/example-wasm/build.rs new file mode 100644 index 0000000..ffb0ab4 --- /dev/null +++ b/example-wasm/build.rs @@ -0,0 +1,22 @@ +// Copyright 2022 Oxide Computer Company + +use std::{ + env, + fs::{self, File}, + path::Path, +}; + +fn main() { + let src = "../sample_openapi/keeper.json"; + println!("cargo:rerun-if-changed={}", src); + let file = File::open(src).unwrap(); + let spec = serde_json::from_reader(file).unwrap(); + let mut generator = progenitor::Generator::default(); + + let content = generator.generate_text(&spec).unwrap(); + + let mut out_file = Path::new(&env::var("OUT_DIR").unwrap()).to_path_buf(); + out_file.push("codegen.rs"); + + fs::write(out_file, content).unwrap(); +} diff --git a/example-wasm/release.toml b/example-wasm/release.toml new file mode 100644 index 0000000..9545640 --- /dev/null +++ b/example-wasm/release.toml @@ -0,0 +1 @@ +release = false diff --git a/example-wasm/src/main.rs b/example-wasm/src/main.rs new file mode 100644 index 0000000..c0fa53a --- /dev/null +++ b/example-wasm/src/main.rs @@ -0,0 +1,15 @@ +// Copyright 2021 Oxide Computer Company + +// Include the generated code. +include!(concat!(env!("OUT_DIR"), "/codegen.rs")); + +fn main() { + let client = Client::new("https://foo/bar"); + let _ = client.enrol( + "auth-token", + &types::EnrolBody { + host: "".to_string(), + key: "".to_string(), + }, + ); +} diff --git a/example-wasm/tests/client.rs b/example-wasm/tests/client.rs new file mode 100644 index 0000000..b793fdd --- /dev/null +++ b/example-wasm/tests/client.rs @@ -0,0 +1,11 @@ +use wasm_bindgen_test::*; + +wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); + +include!(concat!(env!("OUT_DIR"), "/codegen.rs")); + +#[wasm_bindgen_test] +fn test_client_new() { + let client = Client::new("http://foo/bar"); + assert!(client.baseurl == "http://foo/bar"); +} diff --git a/progenitor-client/src/progenitor_client.rs b/progenitor-client/src/progenitor_client.rs index f2951f9..a412f7b 100644 --- a/progenitor-client/src/progenitor_client.rs +++ b/progenitor-client/src/progenitor_client.rs @@ -11,9 +11,14 @@ use futures_core::Stream; use reqwest::RequestBuilder; use serde::{de::DeserializeOwned, Serialize}; +#[cfg(not(target_arch = "wasm32"))] type InnerByteStream = std::pin::Pin> + Send + Sync>>; +#[cfg(target_arch = "wasm32")] +type InnerByteStream = + std::pin::Pin>>>; + /// Untyped byte stream used for both success and error responses. pub struct ByteStream(InnerByteStream); @@ -76,6 +81,7 @@ impl ResponseValue { } } +#[cfg(not(target_arch = "wasm32"))] impl ResponseValue { #[doc(hidden)] pub async fn upgrade( diff --git a/progenitor-impl/src/lib.rs b/progenitor-impl/src/lib.rs index b477c2a..fb85396 100644 --- a/progenitor-impl/src/lib.rs +++ b/progenitor-impl/src/lib.rs @@ -346,13 +346,18 @@ impl Generator { baseurl: &str, #inner_parameter ) -> Self { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client, #inner_value) + #[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(), #inner_value) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/buildomat-builder-tagged.out b/progenitor-impl/tests/output/buildomat-builder-tagged.out index 5dbbb31..d0e67cd 100644 --- a/progenitor-impl/tests/output/buildomat-builder-tagged.out +++ b/progenitor-impl/tests/output/buildomat-builder-tagged.out @@ -1591,13 +1591,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/buildomat-builder.out b/progenitor-impl/tests/output/buildomat-builder.out index 35a0b43..8de5a23 100644 --- a/progenitor-impl/tests/output/buildomat-builder.out +++ b/progenitor-impl/tests/output/buildomat-builder.out @@ -1591,13 +1591,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/buildomat-positional.out b/progenitor-impl/tests/output/buildomat-positional.out index 9b852b9..23d801b 100644 --- a/progenitor-impl/tests/output/buildomat-positional.out +++ b/progenitor-impl/tests/output/buildomat-positional.out @@ -266,13 +266,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/keeper-builder-tagged.out b/progenitor-impl/tests/output/keeper-builder-tagged.out index 3e362d9..f6a15f8 100644 --- a/progenitor-impl/tests/output/keeper-builder-tagged.out +++ b/progenitor-impl/tests/output/keeper-builder-tagged.out @@ -916,13 +916,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/keeper-builder.out b/progenitor-impl/tests/output/keeper-builder.out index e8ec0ef..324430f 100644 --- a/progenitor-impl/tests/output/keeper-builder.out +++ b/progenitor-impl/tests/output/keeper-builder.out @@ -916,13 +916,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/keeper-positional.out b/progenitor-impl/tests/output/keeper-positional.out index dccc51d..280b3ed 100644 --- a/progenitor-impl/tests/output/keeper-positional.out +++ b/progenitor-impl/tests/output/keeper-positional.out @@ -155,13 +155,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/nexus-builder-tagged.out b/progenitor-impl/tests/output/nexus-builder-tagged.out index 7e7a3d7..8901e96 100644 --- a/progenitor-impl/tests/output/nexus-builder-tagged.out +++ b/progenitor-impl/tests/output/nexus-builder-tagged.out @@ -17075,13 +17075,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/nexus-builder.out b/progenitor-impl/tests/output/nexus-builder.out index 55fac85..d22a2bf 100644 --- a/progenitor-impl/tests/output/nexus-builder.out +++ b/progenitor-impl/tests/output/nexus-builder.out @@ -17131,13 +17131,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/nexus-positional.out b/progenitor-impl/tests/output/nexus-positional.out index 43f0f90..3c8d43a 100644 --- a/progenitor-impl/tests/output/nexus-positional.out +++ b/progenitor-impl/tests/output/nexus-positional.out @@ -5903,13 +5903,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/param-overrides-builder-tagged.out b/progenitor-impl/tests/output/param-overrides-builder-tagged.out index 99fd722..fa5d148 100644 --- a/progenitor-impl/tests/output/param-overrides-builder-tagged.out +++ b/progenitor-impl/tests/output/param-overrides-builder-tagged.out @@ -27,13 +27,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/param-overrides-builder.out b/progenitor-impl/tests/output/param-overrides-builder.out index cfd115a..cd0a92f 100644 --- a/progenitor-impl/tests/output/param-overrides-builder.out +++ b/progenitor-impl/tests/output/param-overrides-builder.out @@ -27,13 +27,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/param-overrides-positional.out b/progenitor-impl/tests/output/param-overrides-positional.out index f267620..05610f4 100644 --- a/progenitor-impl/tests/output/param-overrides-positional.out +++ b/progenitor-impl/tests/output/param-overrides-positional.out @@ -27,13 +27,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/propolis-server-builder-tagged.out b/progenitor-impl/tests/output/propolis-server-builder-tagged.out index 64b485d..f77852b 100644 --- a/progenitor-impl/tests/output/propolis-server-builder-tagged.out +++ b/progenitor-impl/tests/output/propolis-server-builder-tagged.out @@ -1969,13 +1969,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/propolis-server-builder.out b/progenitor-impl/tests/output/propolis-server-builder.out index 17ebb84..9810ea8 100644 --- a/progenitor-impl/tests/output/propolis-server-builder.out +++ b/progenitor-impl/tests/output/propolis-server-builder.out @@ -1975,13 +1975,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/propolis-server-positional.out b/progenitor-impl/tests/output/propolis-server-positional.out index da93e29..0a69540 100644 --- a/progenitor-impl/tests/output/propolis-server-positional.out +++ b/progenitor-impl/tests/output/propolis-server-positional.out @@ -622,13 +622,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/test_default_params_builder.out b/progenitor-impl/tests/output/test_default_params_builder.out index 9b81b93..095f2db 100644 --- a/progenitor-impl/tests/output/test_default_params_builder.out +++ b/progenitor-impl/tests/output/test_default_params_builder.out @@ -240,13 +240,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/test_default_params_positional.out b/progenitor-impl/tests/output/test_default_params_positional.out index d2214f9..5ca013c 100644 --- a/progenitor-impl/tests/output/test_default_params_positional.out +++ b/progenitor-impl/tests/output/test_default_params_positional.out @@ -70,13 +70,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/test_freeform_response.out b/progenitor-impl/tests/output/test_freeform_response.out index 8b1bc28..ba64d54 100644 --- a/progenitor-impl/tests/output/test_freeform_response.out +++ b/progenitor-impl/tests/output/test_freeform_response.out @@ -39,13 +39,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`, diff --git a/progenitor-impl/tests/output/test_renamed_parameters.out b/progenitor-impl/tests/output/test_renamed_parameters.out index 84d68c5..9701c65 100644 --- a/progenitor-impl/tests/output/test_renamed_parameters.out +++ b/progenitor-impl/tests/output/test_renamed_parameters.out @@ -39,13 +39,16 @@ impl Client { /// `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 { - let dur = std::time::Duration::from_secs(15); - let client = reqwest::ClientBuilder::new() - .connect_timeout(dur) - .timeout(dur) - .build() - .unwrap(); - Self::new_with_client(baseurl, client) + #[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()) } /// Construct a new client with an existing `reqwest::Client`,