From d492013e5f4c87f29cc0be1d4a2849494d3cdf7d Mon Sep 17 00:00:00 2001 From: Dmitry Dygalo Date: Thu, 21 Apr 2022 11:22:28 +0200 Subject: [PATCH] fix: Various compilation issues Ref: #356 #358 --- CHANGELOG.md | 9 +++++++++ README.md | 14 +++++++++++--- jsonschema/Cargo.toml | 7 ++----- jsonschema/src/resolver.rs | 21 ++++----------------- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c798e163..ef02b05c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ ## [Unreleased] +### Fixed + +- Library compilation with no default features. [#356](https://github.com/Stranger6667/jsonschema-rs/issues/356) +- Compilation with `resolve-file` only. [#358](https://github.com/Stranger6667/jsonschema-rs/issues/358) + +### Changed + +- **BREAKING**: Revert changes from [#353](https://github.com/Stranger6667/jsonschema-rs/issues/353) and [#343](https://github.com/Stranger6667/jsonschema-rs/issues/343), as they caused compilation issues. + ## [0.15.2] - 2022-04-10 ### Fixed diff --git a/README.md b/README.md index b36c7b45..da8bd092 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,6 @@ Partially supported drafts (some keywords are not implemented): jsonschema = "0.15" ``` -By default `jsonschema` resolves remote references via HTTP by using `reqwest` with `native-tls`. -If you'd like to use `rustls`, you have to explicitly enable `reqwest` and `rustls` features and disable `native-tls` via `default-features = false` in your `Cargo.toml` file. - To validate documents against some schema and get validation errors (if any): ```rust @@ -121,6 +118,17 @@ fn main() { } ``` +## Reference resolving and TLS + +By default, `jsonschema` resolves HTTP references via `reqwest` without TLS support. +If you'd like to resolve HTTPS, you need to enable TLS support in `reqwest`: + +```toml +reqwest = { version = "*", features = [ "rustls-tls" ] } +``` + +Otherwise, you might get validation errors like `invalid URL, scheme is not http`. + ## Status This library is functional and ready for use, but its API is still evolving to the 1.0 API. diff --git a/jsonschema/Cargo.toml b/jsonschema/Cargo.toml index fba60fe5..c90998ee 100644 --- a/jsonschema/Cargo.toml +++ b/jsonschema/Cargo.toml @@ -21,12 +21,9 @@ default = ["resolve-http", "resolve-file", "cli"] draft201909 = [] draft202012 = [] -resolve-http = ["reqwest", "native-tls"] +resolve-http = ["reqwest"] resolve-file = [] -native-tls = ["reqwest/default-tls"] -rustls = ["reqwest/rustls-tls"] - [dependencies] ahash = { version = "0.7.6", features = ["serde"] } anyhow = "1.0.55" @@ -42,7 +39,7 @@ num-cmp = "0.1.0" parking_lot = "0.12.0" percent-encoding = "2.1.0" regex = "1.5.4" -reqwest = { package = "reqwest", version = "0.11.9", features = ["blocking", "json"], default-features = false, optional = true } +reqwest = { version = "0.11.9", features = ["blocking", "json"], default-features = false, optional = true } serde = { version = "1.0.136", features = ["derive"] } serde_json = "1.0.79" structopt = { version = "0.3.26", optional = true } diff --git a/jsonschema/src/resolver.rs b/jsonschema/src/resolver.rs index 5feab5e8..12700e92 100644 --- a/jsonschema/src/resolver.rs +++ b/jsonschema/src/resolver.rs @@ -76,30 +76,17 @@ impl SchemaResolver for DefaultResolver { ) -> Result, SchemaResolverError> { match url.scheme() { "http" | "https" => { - #[cfg(not(any( - feature = "resolve-http", - all(feature = "reqwest", feature = "rustls"), - test - )))] + #[cfg(all(feature = "reqwest", not(feature = "resolve-http")))] { - compile_error!( - r#"the `reqwest` feature alone does not enable HTTP schema resolving anymore. -Use the `resolve-http` feature which enables `native-tls` as well; -or both `reqwest` and `rustls` features together, if you prefer rustls."# - ); + compile_error!("the `reqwest` feature does not enable HTTP schema resolving anymore, use the `resolve-http` feature instead"); } - - #[cfg(any( - feature = "resolve-http", - all(feature = "reqwest", feature = "rustls"), - test - ))] + #[cfg(any(feature = "resolve-http", test))] { let response = reqwest::blocking::get(url.as_str())?; let document: Value = response.json()?; Ok(Arc::new(document)) } - #[cfg(not(any(feature = "resolve-http", all(feature="reqwest", feature="rustls"), test)))] + #[cfg(not(any(feature = "resolve-http", test)))] Err(anyhow::anyhow!("`resolve-http` feature or a custom resolver is required to resolve external schemas via HTTP")) } "file" => {