jsonschema-rs
jsonschema-rs copied to clipboard
WASM bindings
Hi,
I'd like to know the requirements for this issue to be completed so I could give it a try as I intend to perform jsonschema validation in a wasm environment an this package would be very helpful in that.
So far, building with
cargo build --target wasm32-unknown-unknownonly gives error onreqwestandUrl.
Compiling jsonschema v0.16.0
error[E0433]: failed to resolve: could not find `blocking` in `reqwest`
--> github.com-1ecc6299db9ec823\jsonschema-0.16.0\src\resolver.rs:85:45
|
85 | let response = reqwest::blocking::get(url.as_str())?;
| ^^^^^^^^ could not find `blocking` in `reqwest`
error[E0599]: no method named `to_file_path` found for reference `&Url` in the current scope
--> github.com-1ecc6299db9ec823\jsonschema-0.16.0\src\resolver.rs:95:43
|
95 | if let Ok(path) = url.to_file_path() {
| ^^^^^^^^^^^^ method not found in `&Url`
Some errors have detailed explanations: E0433, E0599.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `jsonschema` due to 2 previous errors
It would be really powerful to have your json-schema validator available in wasm!
@Stranger6667 It can compile to wasm if you disable the default-feature and only enable structopt in the Cargo.toml
jsonschema = { version = "=0.15.0", default-features = false, features = ["structopt"]}
pure wasm doesn't support IO natively so if we want to add support for the IO ref-resolver then we need to provide custom bindings for that or use WASI if runtime supports that.
I was able to compile it down to the wasm module with the above configuration, I didn't need to parse IO refs so It worked for me.