Skip to content

Commit 958f83e

Browse files
authored
refactor: only blocking validation (#611)
## Closes - Closes #538 as OBE - Closes #517 ## Related to - Once Stranger6667/jsonschema#385 lands we can re-add async validation
1 parent 62567de commit 958f83e

File tree

13 files changed

+211
-358
lines changed

13 files changed

+211
-358
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ geo-types = "0.7.13"
5454
geoarrow = "0.4.0-beta.3"
5555
geojson = "0.24.1"
5656
http = "1.1"
57-
jsonschema = { version = "0.22.3", default-features = false }
57+
jsonschema = { version = "0.28.3", default-features = false }
5858
libduckdb-sys = "1.1.1"
5959
log = "0.4.22"
6060
mime = "0.3.17"

crates/core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Removed
10+
11+
- Async validation ([#611](https://github.com/stac-utils/stac-rs/pull/611))
12+
913
## [0.11.1] - 2025-01-02
1014

1115
### Added

crates/core/Cargo.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ object-store-all = [
4343
"object-store-http",
4444
]
4545
reqwest = ["dep:reqwest"]
46-
validate = ["dep:jsonschema", "dep:reqwest", "dep:tokio", "dep:fluent-uri"]
47-
validate-blocking = ["validate", "tokio/rt"]
46+
validate = ["dep:jsonschema", "dep:fluent-uri", "reqwest"]
4847

4948
[dependencies]
5049
arrow-array = { workspace = true, optional = true }
@@ -58,7 +57,7 @@ geo = { workspace = true, optional = true }
5857
geo-types = { workspace = true, optional = true }
5958
geoarrow = { workspace = true, optional = true }
6059
geojson.workspace = true
61-
jsonschema = { workspace = true, optional = true }
60+
jsonschema = { workspace = true, optional = true, features = ["resolve-http"] }
6261
log.workspace = true
6362
mime.workspace = true
6463
object_store = { workspace = true, optional = true }
@@ -82,11 +81,11 @@ tokio-test.workspace = true
8281

8382
[[test]]
8483
name = "examples"
85-
required-features = ["validate-blocking"]
84+
required-features = ["validate"]
8685

8786
[[test]]
8887
name = "migrate"
89-
required-features = ["validate-blocking"]
88+
required-features = ["validate"]
9089

9190
[package.metadata.docs.rs]
9291
all-features = true
@@ -101,5 +100,4 @@ denylist = [
101100
"object-store-azure",
102101
"object-store-gcp",
103102
"object-store-http",
104-
"validate-blocking",
105103
]

crates/core/src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub enum Error {
2121
/// [fluent_uri::error::ParseError]
2222
#[error(transparent)]
2323
#[cfg(feature = "validate")]
24-
FluentUriParse(#[from] fluent_uri::error::ParseError),
24+
FluentUriParse(#[from] fluent_uri::error::ParseError<String>),
2525

2626
/// Returned when unable to read a STAC value from a path.
2727
#[error("{io}: {path}")]
@@ -102,7 +102,7 @@ pub enum Error {
102102
Parquet(#[from] parquet::errors::ParquetError),
103103

104104
/// [reqwest::Error]
105-
#[cfg(any(feature = "reqwest", feature = "validate"))]
105+
#[cfg(any(feature = "reqwest"))]
106106
#[error(transparent)]
107107
Reqwest(#[from] reqwest::Error),
108108

@@ -116,7 +116,7 @@ pub enum Error {
116116

117117
/// [tokio::task::JoinError]
118118
#[error(transparent)]
119-
#[cfg(any(feature = "validate", feature = "object-store"))]
119+
#[cfg(feature = "object-store")]
120120
TokioJoin(#[from] tokio::task::JoinError),
121121

122122
/// [std::num::TryFromIntError]

crates/core/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,6 @@ pub use node::{Container, Node};
209209
#[cfg(feature = "object-store")]
210210
pub use resolver::Resolver;
211211
pub use statistics::Statistics;
212-
#[cfg(feature = "validate-blocking")]
213-
pub use validate::ValidateBlocking;
214212
#[cfg(feature = "validate")]
215213
pub use validate::{Validate, Validator};
216214
pub use value::Value;
@@ -332,6 +330,11 @@ pub fn version() -> &'static str {
332330
env!("CARGO_PKG_VERSION")
333331
}
334332

333+
/// Returns a string suitable for use as a HTTP user agent.
334+
pub fn user_agent() -> &'static str {
335+
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"))
336+
}
337+
335338
#[cfg(test)]
336339
mod tests {
337340
use rstest as _;

crates/core/src/validate/blocking.rs

Lines changed: 0 additions & 83 deletions
This file was deleted.

crates/core/src/validate/mod.rs

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,7 @@
77
//! ```
88
//! use stac::{Item, Validate};
99
//!
10-
//! # tokio_test::block_on(async {
11-
//! Item::new("an-id").validate().await.unwrap();
12-
//! # })
13-
//! ```
14-
//!
15-
//! If you're working in a blocking context (not async), enable the `blocking` feature and use [ValidateBlocking]:
16-
//!
17-
//! ```
18-
//! #[cfg(feature = "blocking")]
19-
//! {
20-
//! use stac::{ValidateBlocking, Item};
21-
//! Item::new("an-id").validate_blocking().unwrap();
22-
//! }
10+
//! Item::new("an-id").validate().unwrap();
2311
//! ```
2412
//!
2513
//! All fetched schemas are cached, so if you're you're doing multiple
@@ -28,27 +16,20 @@
2816
//! ```
2917
//! # use stac::{Item, Validator};
3018
//! let mut items: Vec<_> = (0..10).map(|n| Item::new(format!("item-{}", n))).collect();
31-
//! # tokio_test::block_on(async {
32-
//! let mut validator = Validator::new().await.unwrap();
19+
//! let mut validator = Validator::new().unwrap();
3320
//! for item in items {
34-
//! validator.validate(&item).await.unwrap();
21+
//! validator.validate(&item).unwrap();
3522
//! }
36-
//! # })
3723
//! ```
3824
//!
3925
//! [Validator] is cheap to clone, so you are encouraged to validate a large
4026
//! number of objects at the same time if that's your use-case.
4127
4228
use crate::Result;
4329
use serde::Serialize;
44-
use std::future::Future;
4530

46-
#[cfg(feature = "validate-blocking")]
47-
mod blocking;
4831
mod validator;
4932

50-
#[cfg(feature = "validate-blocking")]
51-
pub use blocking::ValidateBlocking;
5233
pub use validator::Validator;
5334

5435
/// Validate any serializable object with [json-schema](https://json-schema.org/)
@@ -68,15 +49,11 @@ pub trait Validate: Serialize + Sized {
6849
/// use stac::{Item, Validate};
6950
///
7051
/// let mut item = Item::new("an-id");
71-
/// # tokio_test::block_on(async {
72-
/// item.validate().await.unwrap();
73-
/// });
52+
/// item.validate().unwrap();
7453
/// ```
75-
fn validate(&self) -> impl Future<Output = Result<()>> {
76-
async {
77-
let validator = Validator::new().await?;
78-
validator.validate(self).await
79-
}
54+
fn validate(&self) -> Result<()> {
55+
let mut validator = Validator::new()?;
56+
validator.validate(self)
8057
}
8158
}
8259

0 commit comments

Comments
 (0)