lucy_types/schema.rs
1//! JSON Schema wrapper types.
2//!
3//! This module provides a thin newtype around [`serde_json::Value`] used to
4//! represent JSON Schemas throughout the Lucy framework. Keeping a dedicated
5//! type here leaves room for future validation hooks without breaking the
6//! public API of [`crate::endpoint::EndpointMeta`].
7
8/// A thin wrapper around [`serde_json::Value`] representing a JSON Schema.
9///
10/// This newtype exists to allow future validation hooks and schema
11/// manipulation to be added without changing the public API of [`EndpointMeta`].
12///
13/// [`EndpointMeta`]: crate::endpoint::EndpointMeta
14#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
15pub struct JsonSchemaWrapper(pub serde_json::Value);
16
17impl From<serde_json::Value> for JsonSchemaWrapper {
18 /// Wrap a raw [`serde_json::Value`] into a [`JsonSchemaWrapper`].
19 fn from(value: serde_json::Value) -> Self {
20 Self(value)
21 }
22}
23
24impl From<JsonSchemaWrapper> for serde_json::Value {
25 /// Unwrap a [`JsonSchemaWrapper`] back into its inner [`serde_json::Value`].
26 fn from(wrapper: JsonSchemaWrapper) -> serde_json::Value {
27 wrapper.0
28 }
29}