Skip to content

Commit

Permalink
chore: Update API for new jsonschema exports
Browse files Browse the repository at this point in the history
  • Loading branch information
qdot committed Oct 7, 2024
1 parent 88f8e65 commit 269d5f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions buttplug/src/core/message/serializer/json_serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::core::{
ButtplugServerMessageVariant,
},
};
use jsonschema::JSONSchema;
use jsonschema::Validator;
use once_cell::sync::OnceCell;
use serde::{Deserialize, Serialize};
use serde_json::{Deserializer, Value};
Expand All @@ -39,14 +39,14 @@ static MESSAGE_JSON_SCHEMA: &str =
include_str!("../../../../buttplug-schema/schema/buttplug-schema.json");

/// Creates a [jsonschema::JSONSchema] validator using the built in buttplug message schema.
pub fn create_message_validator() -> JSONSchema {
pub fn create_message_validator() -> Validator {
let schema: serde_json::Value =
serde_json::from_str(MESSAGE_JSON_SCHEMA).expect("Built in schema better be valid");
JSONSchema::compile(&schema).expect("Built in schema better be valid")
Validator::new(&schema).expect("Built in schema better be valid")
}
pub struct ButtplugServerJSONSerializer {
pub(super) message_version: OnceCell<message::ButtplugMessageSpecVersion>,
validator: JSONSchema,
validator: Validator,
}

impl Default for ButtplugServerJSONSerializer {
Expand Down Expand Up @@ -83,7 +83,7 @@ where
}

pub fn deserialize_to_message<T>(
validator: &JSONSchema,
validator: &Validator,
msg_str: &str,
) -> Result<Vec<T>, ButtplugSerializerError>
where
Expand Down Expand Up @@ -319,7 +319,7 @@ impl ButtplugMessageSerializer for ButtplugServerJSONSerializer {
}

pub struct ButtplugClientJSONSerializerImpl {
validator: JSONSchema,
validator: Validator,
}

impl Default for ButtplugClientJSONSerializerImpl {
Expand Down
6 changes: 3 additions & 3 deletions buttplug/src/util/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
//! jsonschema library.

use crate::core::message::serializer::ButtplugSerializerError;
use jsonschema::JSONSchema;
use jsonschema::Validator;

pub struct JSONValidator {
schema: JSONSchema,
schema: Validator,
}

impl JSONValidator {
Expand All @@ -26,7 +26,7 @@ impl JSONValidator {
pub fn new(schema: &str) -> Self {
let schema_json: serde_json::Value =
serde_json::from_str(schema).expect("Built in schema better be valid");
let schema = JSONSchema::compile(&schema_json).expect("Built in schema better be valid");
let schema = Validator::new(&schema_json).expect("Built in schema better be valid");
Self { schema }
}

Expand Down

0 comments on commit 269d5f5

Please sign in to comment.