Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update jsonschema dependency #3286

Merged
merged 1 commit into from
Sep 19, 2024
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
2 changes: 1 addition & 1 deletion crates/samples/components/json_validator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish = false
crate-type = ["cdylib"]

[dependencies]
jsonschema = { version = "0.19", default-features = false }
jsonschema = { version = "0.20", default-features = false }
serde_json = {version = "1.0", default-features = false }

[dependencies.windows]
Expand Down
12 changes: 6 additions & 6 deletions crates/samples/components/json_validator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use jsonschema::JSONSchema;
use jsonschema::Validator;
use windows::{core::*, Win32::Foundation::*, Win32::System::Com::*};

// Creates a JSON validator object with the given schema. The returned handle must be freed
Expand Down Expand Up @@ -35,16 +35,16 @@ unsafe extern "system" fn ValidateJson(
#[no_mangle]
unsafe extern "system" fn CloseJsonValidator(handle: usize) {
if handle != 0 {
_ = Box::from_raw(handle as *mut JSONSchema);
_ = Box::from_raw(handle as *mut Validator);
}
}

// Implementation of the `CreateJsonValidator` function so we can use `Result` for simplicity.
unsafe fn create_validator(schema: *const u8, schema_len: usize, handle: *mut usize) -> Result<()> {
let schema = json_from_raw_parts(schema, schema_len)?;

let compiled = JSONSchema::compile(&schema)
.map_err(|error| Error::new(E_INVALIDARG, error.to_string()))?;
let compiled =
Validator::new(&schema).map_err(|error| Error::new(E_INVALIDARG, error.to_string()))?;

if handle.is_null() {
return Err(E_POINTER.into());
Expand All @@ -70,9 +70,9 @@ unsafe fn validate(

let value = json_from_raw_parts(value, value_len)?;

// This looks a bit tricky but we're just turning the opaque handle into `JSONSchema` pointer
// This looks a bit tricky but we're just turning the opaque handle into `Validator` pointer
// and then returning a reference to avoid taking ownership of it.
let schema = &*(handle as *const JSONSchema);
let schema = &*(handle as *const Validator);

if schema.is_valid(&value) {
if !sanitized_value.is_null() && !sanitized_value_len.is_null() {
Expand Down
2 changes: 1 addition & 1 deletion crates/samples/components/json_validator_winrt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "sample"
crate-type = ["cdylib"]

[dependencies]
jsonschema = { version = "0.19", default-features = false }
jsonschema = { version = "0.20", default-features = false }
serde_json = {version = "1.0", default-features = false }

[dependencies.windows]
Expand Down
8 changes: 4 additions & 4 deletions crates/samples/components/json_validator_winrt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
mod bindings;
use jsonschema::JSONSchema;
use jsonschema::Validator;
use windows::{core::*, Win32::Foundation::*, Win32::System::WinRT::*};

// The `JsonValidator` struct represents the implementation of the `JsonValidator` class.
// The `implement` attribute provides the boilerplate COM and WinRT implementation support.
#[implement(bindings::JsonValidator)]
struct JsonValidator {
schema: JSONSchema,
schema: Validator,
}

// Implement the `IJsonValidator` interface.
Expand Down Expand Up @@ -49,8 +49,8 @@ impl bindings::IJsonValidatorFactory_Impl for JsonValidatorFactory_Impl {
fn CreateInstance(&self, schema: &HSTRING) -> Result<bindings::JsonValidator> {
let schema = json_from_hstring(schema)?;

let schema = JSONSchema::compile(&schema)
.map_err(|error| Error::new(E_INVALIDARG, error.to_string()))?;
let schema =
Validator::new(&schema).map_err(|error| Error::new(E_INVALIDARG, error.to_string()))?;

Ok(JsonValidator { schema }.into())
}
Expand Down