Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ arrow-json = "55.0.0"
arrow-schema = "55.0.0"
assert-json-diff = "2.0"
assert_cmd = "2.0"
async-recursion = "1.1.1"
async-stream = "0.3.6"
async-trait = "0.1.89"
axum = "0.8.1"
bb8 = "0.9.0"
bb8-postgres = "0.9.0"
Expand All @@ -63,7 +65,7 @@ geojson = "0.24.1"
getrandom = { version = "0.3.3", features = ["wasm_js"] }
http = "1.1"
indexmap = { version = "2.10.0", features = ["serde"] }
jsonschema = { version = "0.33.0", default-features = false }
jsonschema = { version = "0.33.0", default-features = false, features = ["resolve-async"] }
libduckdb-sys = "1.3.0"
log = "0.4.25"
mime = "0.3.17"
Expand All @@ -75,6 +77,7 @@ quote = "1.0"
reqwest = { version = "0.12.8", default-features = false, features = [
"rustls-tls",
] }
referencing = "0.33.0"
rstest = "0.26.1"
rustls = { version = "0.23.22", default-features = false }
serde = "1.0"
Expand Down
6 changes: 2 additions & 4 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::{
io::Write,
str::FromStr,
};
use tokio::{io::AsyncReadExt, net::TcpListener, runtime::Handle, task::JoinSet};
use tokio::{io::AsyncReadExt, net::TcpListener, task::JoinSet};
use tracing::metadata::Level;
use tracing_indicatif::IndicatifLayer;
use tracing_subscriber::{
Expand Down Expand Up @@ -492,9 +492,7 @@ impl Rustac {
}
Command::Validate { ref infile } => {
let value = self.get(infile.as_deref()).await?;
let result = Handle::current()
.spawn_blocking(move || value.validate())
.await?;
let result = value.validate().await;
if let Err(error) = result {
if let stac_validate::Error::Validation(errors) = error {
if let Some(format) = self.output_format {
Expand Down
10 changes: 6 additions & 4 deletions crates/core/tests/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ use stac_validate::Validate;
use std::path::PathBuf;

#[rstest]
fn v1_0_0(#[files("../../spec-examples/v1.0.0/**/*.json")] path: PathBuf) {
#[tokio::test]
async fn v1_0_0(#[files("../../spec-examples/v1.0.0/**/*.json")] path: PathBuf) {
let value: Value = stac::read(path.to_str().unwrap()).unwrap();
value.validate().unwrap();
value.validate().await.unwrap();
}

#[rstest]
fn v1_1_0(#[files("../../spec-examples/v1.1.0/**/*.json")] path: PathBuf) {
#[tokio::test]
async fn v1_1_0(#[files("../../spec-examples/v1.1.0/**/*.json")] path: PathBuf) {
let value: Value = stac::read(path.to_str().unwrap()).unwrap();
value.validate().unwrap();
value.validate().await.unwrap();
}
5 changes: 3 additions & 2 deletions crates/core/tests/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use stac_validate::Validate;
use std::path::PathBuf;

#[rstest]
fn v1_0_0_to_v1_1_0(#[files("../../spec-examples/v1.0.0/**/*.json")] path: PathBuf) {
#[tokio::test]
async fn v1_0_0_to_v1_1_0(#[files("../../spec-examples/v1.0.0/**/*.json")] path: PathBuf) {
let value: Value = stac::read(path.to_str().unwrap()).unwrap();
let value = value.migrate(&Version::v1_1_0).unwrap();
value.validate().unwrap();
value.validate().await.unwrap();
}
1 change: 1 addition & 0 deletions crates/duckdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ thiserror.workspace = true
geo.workspace = true
rstest.workspace = true
stac-validate = { path = "../validate" }
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
5 changes: 3 additions & 2 deletions crates/duckdb/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,13 @@ mod tests {
}

#[rstest]
fn search(client: Client) {
#[tokio::test]
async fn search(client: Client) {
let item_collection = client
.search("data/100-sentinel-2-items.parquet", Search::default())
.unwrap();
assert_eq!(item_collection.items.len(), 100);
item_collection.items[0].validate().unwrap();
item_collection.items[0].validate().await.unwrap();
}

#[rstest]
Expand Down
5 changes: 4 additions & 1 deletion crates/validate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ serde.workspace = true
serde_json.workspace = true
stac.workspace = true
thiserror.workspace = true
async-trait.workspace = true
referencing.workspace = true
async-recursion.workspace = true

[dev-dependencies]
stac-io.workspace = true
tokio = { workspace = true, features = ["macros"] }
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
36 changes: 24 additions & 12 deletions crates/validate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,26 @@
//! use stac::Item;
//! use stac_validate::Validate;
//!
//! Item::new("an-id").validate().unwrap();
//! #[tokio::main]
//! async fn main() {
//! Item::new("an-id").validate().await.unwrap();
//! }
//! ```
//!
//! All fetched schemas are cached, so if you're you're doing multiple
//! validations, you should re-use the same [Validator]:
//!
//! ```
//! # use stac::Item;
//! use stac::Item;
//! use stac_validate::Validator;
//! let mut items: Vec<_> = (0..10).map(|n| Item::new(format!("item-{}", n))).collect();
//! let mut validator = Validator::new().unwrap();
//! for item in items {
//! validator.validate(&item).unwrap();
//!
//! #[tokio::main]
//! async fn main() {
//! let mut items: Vec<_> = (0..10).map(|n| Item::new(format!("item-{}", n))).collect();
//! let mut validator = Validator::new().await.unwrap();
//! for item in items {
//! validator.validate(&item).await.unwrap();
//! }
//! }
//! ```
//!
Expand All @@ -31,13 +38,15 @@ use serde::Serialize;

mod error;
mod validator;
use async_trait::async_trait;

pub use {error::Error, validator::Validator};

/// Public result type.
pub type Result<T> = std::result::Result<T, Error>;

/// Validate any serializable object with [json-schema](https://json-schema.org/)
#[async_trait]
pub trait Validate: Serialize + Sized {
/// Validates this object.
///
Expand All @@ -53,16 +62,19 @@ pub trait Validate: Serialize + Sized {
/// use stac::Item;
/// use stac_validate::Validate;
///
/// let mut item = Item::new("an-id");
/// item.validate().unwrap();
/// #[tokio::main]
/// async fn main() {
/// let mut item = Item::new("an-id");
/// item.validate().await.unwrap();
/// }
/// ```
fn validate(&self) -> Result<()> {
let mut validator = Validator::new()?;
validator.validate(self)
async fn validate(&self) -> Result<()> {
let mut validator = Validator::new().await?;
validator.validate(self).await
}
}

impl<T: Serialize> Validate for T {}
impl<T: Serialize + Send + Sync> Validate for T {}

/// Returns a string suitable for use as a HTTP user agent.
pub fn user_agent() -> &'static str {
Expand Down
Loading
Loading