Skip to content

Commit

Permalink
Merge pull request #2251 from jqnatividad/bump-jsonschema-0.25-to-0.26
Browse files Browse the repository at this point in the history
`deps`: bump jsonschema from 0.25 to 0.26
  • Loading branch information
jqnatividad authored Oct 26, 2024
2 parents 8c54b87 + 0b9bc58 commit 6b69850
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ jaq-interpret = "1.5.0"
jaq-parse = "1.0.3"
jemallocator = { version = "0.5", optional = true }
json-objects-to-csv = "0.1.3"
jsonschema = { version = "0.25", features = [
jsonschema = { version = "0.26", features = [
"resolve-file",
"resolve-http",
], default-features = false }
Expand Down
33 changes: 22 additions & 11 deletions src/cmd/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ use std::{
env,
fs::File,
io::{BufReader, BufWriter, Read, Write},
iter::once,
str,
sync::{
atomic::{AtomicU16, Ordering},
Expand All @@ -149,7 +148,7 @@ use indicatif::{ProgressBar, ProgressDrawTarget};
use jsonschema::{
output::BasicOutput,
paths::{LazyLocation, Location},
ErrorIterator, Keyword, ValidationError, Validator,
Keyword, ValidationError, Validator,
};
use log::{debug, info, log_enabled};
use qsv_currency::Currency;
Expand Down Expand Up @@ -260,17 +259,17 @@ impl Keyword for DynEnumValidator {
&self,
instance: &'instance Value,
instance_path: &LazyLocation,
) -> ErrorIterator<'instance> {
) -> Result<(), ValidationError<'instance>> {
if self.dynenum_set.contains(instance.as_str().unwrap()) {
Box::new(std::iter::empty())
Ok(())
} else {
let error = ValidationError::custom(
Location::default(),
instance_path.into(),
instance,
format!("{instance} is not a valid dynamicEnum value"),
);
Box::new(once(error))
Err(error)
}
}

Expand All @@ -291,7 +290,10 @@ fn dyn_enum_validator_factory<'a>(
location: Location,
) -> Result<Box<dyn Keyword>, ValidationError<'a>> {
if let Value::String(uri) = value {
let temp_download = NamedTempFile::new()?;
let temp_download = match NamedTempFile::new() {
Ok(file) => file,
Err(e) => return fail_validation_error!("Failed to create temporary file: {}", e),
};

let dynenum_path = if uri.starts_with("http") {
let valid_url = reqwest::Url::parse(uri).map_err(|e| {
Expand All @@ -313,8 +315,15 @@ fn dyn_enum_validator_factory<'a>(
Some(download_timeout),
None,
);
if let Err(e) = tokio::runtime::Runtime::new()?.block_on(future) {
return fail_validation_error!("Error downloading dynamicEnum file - {e}");
match tokio::runtime::Runtime::new() {
Ok(runtime) => {
if let Err(e) = runtime.block_on(future) {
return fail_validation_error!("Error downloading dynamicEnum file - {e}");
}
},
Err(e) => {
return fail_validation_error!("Error creating Tokio runtime - {e}");
},
}

temp_download.path().to_str().unwrap().to_string()
Expand All @@ -331,7 +340,10 @@ fn dyn_enum_validator_factory<'a>(
// read the first column into a HashSet
let mut enum_set = HashSet::with_capacity(50);
let rconfig = Config::new(Some(dynenum_path).as_ref());
let mut rdr = rconfig.flexible(true).reader()?;
let mut rdr = match rconfig.flexible(true).reader() {
Ok(reader) => reader,
Err(e) => return fail_validation_error!("Error opening dynamicEnum file: {e}"),
};
for result in rdr.records() {
match result {
Ok(record) => {
Expand Down Expand Up @@ -1537,9 +1549,8 @@ fn test_dyn_enum_validator() {
assert!(!validator.is_valid(&json!("")));
assert!(!validator.is_valid(&json!(5)));
if let Err(e) = validator.validate(&json!("lanzones")) {
let err_info = e.into_iter().next().unwrap();
assert_eq!(
format!("{err_info:?}"),
format!("{e:?}"),
r#"ValidationError { instance: String("lanzones"), kind: Custom { message: "\"lanzones\" is not a valid dynamicEnum value" }, instance_path: Location(""), schema_path: Location("") }"#
);
} else {
Expand Down

0 comments on commit 6b69850

Please sign in to comment.