jsonschema-rs icon indicating copy to clipboard operation
jsonschema-rs copied to clipboard

WASM bindings

Open Stranger6667 opened this issue 4 years ago • 4 comments

Stranger6667 avatar May 06 '21 15:05 Stranger6667

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-unknown only gives error on reqwest and Url.

islami00 avatar Jul 09 '22 16:07 islami00

   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

oovm avatar Jul 15 '22 13:07 oovm

It would be really powerful to have your json-schema validator available in wasm!

manuschillerdev avatar Nov 06 '22 11:11 manuschillerdev

@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.

Niraj-Kamdar avatar Nov 13 '22 23:11 Niraj-Kamdar