Skip to content

Commit

Permalink
fix: Various compilation issues
Browse files Browse the repository at this point in the history
Ref: #356 #358
  • Loading branch information
Stranger6667 committed Apr 21, 2022
1 parent e2d09aa commit 233e1a0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 2 additions & 5 deletions jsonschema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 }
Expand Down
21 changes: 4 additions & 17 deletions jsonschema/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,17 @@ impl SchemaResolver for DefaultResolver {
) -> Result<Arc<Value>, 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" => {
Expand Down

0 comments on commit 233e1a0

Please sign in to comment.