pub trait JsonSchema {
// Required method
fn json_schema(&self) -> Value;
// Provided method
fn is_required(&self) -> bool { ... }
}Expand description
Trait for types that can produce a JSON Schema representation.
Implemented for all core vld schemas. The output is a serde_json::Value
representing the JSON Schema object, compatible with OpenAPI 3.1.
Required Methods§
Sourcefn json_schema(&self) -> Value
fn json_schema(&self) -> Value
Generate a JSON Schema representation.
Provided Methods§
Sourcefn is_required(&self) -> bool
fn is_required(&self) -> bool
Whether this schema should be included in an object’s required array.
By default, fields are required. Schemas that accept a missing key
return false: .optional(), .nullable() (a missing key parses as
None), .nullish(), .with_default(...), .catch(...), and the
null-accepting vld::any(), vld::null() and an unconstrained
vld::json_value().
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<A, B, C, D, E, F, G, H, I, J, K, L> JsonSchema for (A, B, C, D, E, F, G, H, I, J, K, L)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
E: VldSchema + JsonSchema,
F: VldSchema + JsonSchema,
G: VldSchema + JsonSchema,
H: VldSchema + JsonSchema,
I: VldSchema + JsonSchema,
J: VldSchema + JsonSchema,
K: VldSchema + JsonSchema,
L: VldSchema + JsonSchema,
impl<A, B, C, D, E, F, G, H, I, J, K, L> JsonSchema for (A, B, C, D, E, F, G, H, I, J, K, L)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
E: VldSchema + JsonSchema,
F: VldSchema + JsonSchema,
G: VldSchema + JsonSchema,
H: VldSchema + JsonSchema,
I: VldSchema + JsonSchema,
J: VldSchema + JsonSchema,
K: VldSchema + JsonSchema,
L: VldSchema + JsonSchema,
fn json_schema(&self) -> Value
Source§impl<A, B, C, D, E, F, G, H, I, J, K> JsonSchema for (A, B, C, D, E, F, G, H, I, J, K)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
E: VldSchema + JsonSchema,
F: VldSchema + JsonSchema,
G: VldSchema + JsonSchema,
H: VldSchema + JsonSchema,
I: VldSchema + JsonSchema,
J: VldSchema + JsonSchema,
K: VldSchema + JsonSchema,
impl<A, B, C, D, E, F, G, H, I, J, K> JsonSchema for (A, B, C, D, E, F, G, H, I, J, K)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
E: VldSchema + JsonSchema,
F: VldSchema + JsonSchema,
G: VldSchema + JsonSchema,
H: VldSchema + JsonSchema,
I: VldSchema + JsonSchema,
J: VldSchema + JsonSchema,
K: VldSchema + JsonSchema,
fn json_schema(&self) -> Value
Source§impl<A, B, C, D, E, F, G, H, I, J> JsonSchema for (A, B, C, D, E, F, G, H, I, J)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
E: VldSchema + JsonSchema,
F: VldSchema + JsonSchema,
G: VldSchema + JsonSchema,
H: VldSchema + JsonSchema,
I: VldSchema + JsonSchema,
J: VldSchema + JsonSchema,
impl<A, B, C, D, E, F, G, H, I, J> JsonSchema for (A, B, C, D, E, F, G, H, I, J)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
E: VldSchema + JsonSchema,
F: VldSchema + JsonSchema,
G: VldSchema + JsonSchema,
H: VldSchema + JsonSchema,
I: VldSchema + JsonSchema,
J: VldSchema + JsonSchema,
fn json_schema(&self) -> Value
Source§impl<A, B, C, D, E, F, G, H, I> JsonSchema for (A, B, C, D, E, F, G, H, I)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
E: VldSchema + JsonSchema,
F: VldSchema + JsonSchema,
G: VldSchema + JsonSchema,
H: VldSchema + JsonSchema,
I: VldSchema + JsonSchema,
impl<A, B, C, D, E, F, G, H, I> JsonSchema for (A, B, C, D, E, F, G, H, I)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
E: VldSchema + JsonSchema,
F: VldSchema + JsonSchema,
G: VldSchema + JsonSchema,
H: VldSchema + JsonSchema,
I: VldSchema + JsonSchema,
fn json_schema(&self) -> Value
Source§impl<A, B, C, D, E, F, G, H> JsonSchema for (A, B, C, D, E, F, G, H)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
E: VldSchema + JsonSchema,
F: VldSchema + JsonSchema,
G: VldSchema + JsonSchema,
H: VldSchema + JsonSchema,
impl<A, B, C, D, E, F, G, H> JsonSchema for (A, B, C, D, E, F, G, H)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
E: VldSchema + JsonSchema,
F: VldSchema + JsonSchema,
G: VldSchema + JsonSchema,
H: VldSchema + JsonSchema,
fn json_schema(&self) -> Value
Source§impl<A, B, C, D, E, F, G> JsonSchema for (A, B, C, D, E, F, G)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
E: VldSchema + JsonSchema,
F: VldSchema + JsonSchema,
G: VldSchema + JsonSchema,
impl<A, B, C, D, E, F, G> JsonSchema for (A, B, C, D, E, F, G)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
E: VldSchema + JsonSchema,
F: VldSchema + JsonSchema,
G: VldSchema + JsonSchema,
fn json_schema(&self) -> Value
Source§impl<A, B, C, D, E, F> JsonSchema for (A, B, C, D, E, F)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
E: VldSchema + JsonSchema,
F: VldSchema + JsonSchema,
impl<A, B, C, D, E, F> JsonSchema for (A, B, C, D, E, F)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
E: VldSchema + JsonSchema,
F: VldSchema + JsonSchema,
fn json_schema(&self) -> Value
Source§impl<A, B, C, D, E> JsonSchema for (A, B, C, D, E)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
E: VldSchema + JsonSchema,
impl<A, B, C, D, E> JsonSchema for (A, B, C, D, E)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
E: VldSchema + JsonSchema,
fn json_schema(&self) -> Value
Source§impl<A, B, C, D> JsonSchema for (A, B, C, D)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
impl<A, B, C, D> JsonSchema for (A, B, C, D)where
A: VldSchema + JsonSchema,
B: VldSchema + JsonSchema,
C: VldSchema + JsonSchema,
D: VldSchema + JsonSchema,
fn json_schema(&self) -> Value
Source§impl<A, B, C> JsonSchema for (A, B, C)
impl<A, B, C> JsonSchema for (A, B, C)
fn json_schema(&self) -> Value
Source§impl<A, B> JsonSchema for (A, B)
impl<A, B> JsonSchema for (A, B)
fn json_schema(&self) -> Value
Source§impl<A> JsonSchema for (A,)where
A: VldSchema + JsonSchema,
impl<A> JsonSchema for (A,)where
A: VldSchema + JsonSchema,
fn json_schema(&self) -> Value
Implementors§
impl JsonSchema for AnyKey
openapi only.impl JsonSchema for ZAny
openapi only.Generate a JSON Schema representation (empty schema = any).
impl JsonSchema for ZBoolean
openapi only.Generate a JSON Schema representation.
impl JsonSchema for ZBytes
openapi only.JSON Schema. In string modes minLength/maxLength describe the
encoded string length (Base64: 4*ceil(n/3) padded; Base64URL may be
unpadded; hex: 2n, plus an optional 0x prefix).
impl JsonSchema for ZChar
openapi only.{"type": "string", "minLength": 1, "maxLength": 1}.
impl JsonSchema for ZDiscriminatedUnion
{"anyOf": [<variant schemas>]}.
impl JsonSchema for ZDuration
openapi only.JSON Schema. min/max become minimum/maximum (seconds) on the
number branch and x-minSeconds/x-maxSeconds on the string branch.
impl JsonSchema for ZEnum
openapi only.Generate a JSON Schema representation.
impl JsonSchema for ZF32
openapi only.impl JsonSchema for ZJsonValue
openapi only.impl JsonSchema for ZNever
openapi only.{"not": {}} (matches nothing).
impl JsonSchema for ZNull
openapi only.{"type": "null"}.
Source§impl JsonSchema for ZNumber
Available on crate feature openapi only.Generate a JSON Schema representation of this number schema.
impl JsonSchema for ZNumber
openapi only.Generate a JSON Schema representation of this number schema.
The strictest lower/upper bound (from min/gt/positive/
non_negative/safe, …) is emitted as minimum or exclusiveMinimum
(likewise for the maximum). The first multiple_of goes into
multipleOf, further ones into allOf.
impl JsonSchema for ZObject
openapi only.Properties from the fields (with their own schemas and required status);
additionalProperties is false for strict(), the catchall schema when
set, true otherwise.
impl JsonSchema for ZPath
openapi only.impl JsonSchema for ZSocketAddr
openapi only.Source§impl JsonSchema for ZString
Available on crate feature openapi only.Generate a JSON Schema representation of this string schema.
impl JsonSchema for ZString
openapi only.Generate a JSON Schema representation of this string schema.
- Length bounds: the strictest
min/max/len/non_emptywins. - Formats: the first goes into
format, further ones intoallOf. pattern/starts_with/ends_with/containsbecomepatterns (first inpattern, further ones inallOf).- Password rules add
format: "password"and anx-passwordobject (lowercase,uppercase,digit,symbol:true;maxRepeat,minScore: numbers).
impl<A, B, C> JsonSchema for ZUnion3<A, B, C>
impl<A, B> JsonSchema for ZIntersection<A, B>
impl<A, B> JsonSchema for ZPipe<A, B>
{} — the output of the first stage is re-validated by the second,
so no single input schema describes the pipe.
impl<A, B> JsonSchema for ZUnion2<A, B>
impl<F, S> JsonSchema for ZPreprocess<F, S>
impl<F, T> JsonSchema for ZCustom<F, T>
{} — arbitrary validation function.
impl<K, V> JsonSchema for ZMap<K, V>
openapi only.[[key, value], ...]: an array of 2-item tuples.
impl<K> JsonSchema for KeySchema<K>where
K: JsonSchema,
openapi only.impl<S, F, U, E> JsonSchema for ZTryTransform<S, F, U>
impl<S, F, U> JsonSchema for ZTransform<S, F, U>
impl<S, F> JsonSchema for ZRefine<S, F>
impl<S, F> JsonSchema for ZSuperRefine<S, F>
impl<S, R> JsonSchema for ZRule<S, R>
openapi only.impl<S> JsonSchema for ZCatch<S>
The inner schema; never required (a missing key yields the fallback).
impl<S> JsonSchema for ZDefault<S>
impl<S> JsonSchema for ZDescribe<S>where
S: VldSchema + JsonSchema,
impl<S> JsonSchema for ZMessage<S>where
S: VldSchema + JsonSchema,
impl<S> JsonSchema for ZNullable<S>where
S: VldSchema + JsonSchema,
The key is required and null is allowed (TypeScript x: T | null).
impl<S> JsonSchema for ZNullish<S>where
S: VldSchema + JsonSchema,
May be left out or null (TypeScript x?: T | null).
impl<S> JsonSchema for ZOptional<S>where
S: VldSchema + JsonSchema,
May be left out; null is not part of the schema (TypeScript x?: T),
although parsing tolerates it (serde writes None as null).
impl<S> JsonSchema for ZRange<S>where
S: JsonSchema,
openapi only.{"type": "object", "properties": {start: item, end: item}, "required": [start, end], "x-rangeOrder": [start, end]} (x-rangeOrder is a vld
extension: the order is not expressible in JSON Schema; vld::fake
honours it).
impl<S> JsonSchema for ZRedact<S>where
S: VldSchema + JsonSchema,
impl<T, F> JsonSchema for NestedSchema<T, F>
openapi only.impl<T, F> JsonSchema for ZLazy<T, F>
{} — a recursive schema cannot be expanded inline.
impl<T> JsonSchema for ZArray<T>where
T: VldSchema + JsonSchema,
openapi only.impl<T> JsonSchema for ZEnumOf<T>where
T: Clone,
openapi only.impl<T> JsonSchema for ZFromSerde<T>
openapi only.impl<T> JsonSchema for ZFromStr<T>
openapi only.impl<T> JsonSchema for ZInteger<T>where
T: IntType,
openapi only.{"type": "integer"} plus bounds; typed integers (vld::u8(), …) add
format and the type range.
impl<T> JsonSchema for ZLiteral<T>where
T: IntoLiteral,
openapi only.{"const": <literal>}.
impl<T> JsonSchema for ZSet<T>
openapi only.min_size becomes minItems (n unique items need at least n items);
max_size is not emitted as maxItems, because duplicates in the
input are allowed and do not count towards the limit. The bound is
exposed as x-maxUniqueItems instead.
impl<V, K, M> JsonSchema for ZRecord<V, K, M>
openapi only.{"type": "object", "additionalProperties": <value>}; a key schema adds
propertyNames.