Skip to content

Commit

Permalink
Adding Wasm support after moving to Cow.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinswiber committed Nov 30, 2023
1 parent 3ec206b commit 2315b79
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ serde_yaml = "0.9"
console_error_panic_hook = { version = "0.1.6", optional = true }
gloo-utils = { version = "0.2", features = ["serde"] }
wasm-bindgen = "0.2"
js-sys = "0.3"
wee_alloc = { version = "0.4.5", optional = true }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {
.long("output-format")
.help("The output format")
.value_name("format")
.possible_values(&["yaml", "json"])
.possible_values(["yaml", "json"])
.default_value("yaml"),
)
.arg(
Expand Down
9 changes: 8 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,15 @@ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
pub fn transpile(collection: JsValue) -> std::result::Result<JsValue, JsValue> {
let s = if collection.is_undefined() {
String::from("null")
} else {
js_sys::JSON::stringify(&collection)
.map(String::from)
.unwrap_throw()
};
let postman_spec: std::result::Result<postman::Spec, serde_json::Error> =
collection.into_serde();
serde_json::from_str(&s);
match postman_spec {
Ok(s) => {
let oas_spec = Transpiler::transpile(s);
Expand Down

0 comments on commit 2315b79

Please sign in to comment.