pub trait JsonSchema {
// Required method
fn json_schema(&self) -> Value;
// Provided method
fn is_required(&self) -> bool { ... }
}openapi only.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: 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> JsonSchema for (A, B, C, D, E, F, G, H, I, J, K, L)
impl<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> JsonSchema for (A, B, C, D, E, F, G, H, I, J, K, L)
Source§fn json_schema(&self) -> Value
fn json_schema(&self) -> Value
openapi only.Source§impl<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> JsonSchema for (A, B, C, D, E, F, G, H, I, J, K)
impl<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> JsonSchema for (A, B, C, D, E, F, G, H, I, J, K)
Source§fn json_schema(&self) -> Value
fn json_schema(&self) -> Value
openapi only.Source§impl<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> JsonSchema for (A, B, C, D, E, F, G, H, I, J)
impl<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> JsonSchema for (A, B, C, D, E, F, G, H, I, J)
Source§fn json_schema(&self) -> Value
fn json_schema(&self) -> Value
openapi only.Source§impl<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> JsonSchema for (A, B, C, D, E, F, G, H, I)
impl<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> JsonSchema for (A, B, C, D, E, F, G, H, I)
Source§fn json_schema(&self) -> Value
fn json_schema(&self) -> Value
openapi only.Source§impl<A: VldSchema + JsonSchema, B: VldSchema + JsonSchema, C: VldSchema + JsonSchema, D: VldSchema + JsonSchema, E: VldSchema + JsonSchema, F: VldSchema + JsonSchema, G: VldSchema + JsonSchema, H: VldSchema + JsonSchema> JsonSchema for (A, B, C, D, E, F, G, H)
impl<A: VldSchema + JsonSchema, B: VldSchema + JsonSchema, C: VldSchema + JsonSchema, D: VldSchema + JsonSchema, E: VldSchema + JsonSchema, F: VldSchema + JsonSchema, G: VldSchema + JsonSchema, H: VldSchema + JsonSchema> JsonSchema for (A, B, C, D, E, F, G, H)
Source§fn json_schema(&self) -> Value
fn json_schema(&self) -> Value
openapi only.Source§impl<A: VldSchema + JsonSchema, B: VldSchema + JsonSchema, C: VldSchema + JsonSchema, D: VldSchema + JsonSchema, E: VldSchema + JsonSchema, F: VldSchema + JsonSchema, G: VldSchema + JsonSchema> JsonSchema for (A, B, C, D, E, F, G)
impl<A: VldSchema + JsonSchema, B: VldSchema + JsonSchema, C: VldSchema + JsonSchema, D: VldSchema + JsonSchema, E: VldSchema + JsonSchema, F: VldSchema + JsonSchema, G: VldSchema + JsonSchema> JsonSchema for (A, B, C, D, E, F, G)
Source§fn json_schema(&self) -> Value
fn json_schema(&self) -> Value
openapi only.Source§impl<A: VldSchema + JsonSchema, B: VldSchema + JsonSchema, C: VldSchema + JsonSchema, D: VldSchema + JsonSchema, E: VldSchema + JsonSchema, F: VldSchema + JsonSchema> JsonSchema for (A, B, C, D, E, F)
impl<A: VldSchema + JsonSchema, B: VldSchema + JsonSchema, C: VldSchema + JsonSchema, D: VldSchema + JsonSchema, E: VldSchema + JsonSchema, F: VldSchema + JsonSchema> JsonSchema for (A, B, C, D, E, F)
Source§fn json_schema(&self) -> Value
fn json_schema(&self) -> Value
openapi only.Source§impl<A: VldSchema + JsonSchema, B: VldSchema + JsonSchema, C: VldSchema + JsonSchema, D: VldSchema + JsonSchema, E: VldSchema + JsonSchema> JsonSchema for (A, B, C, D, E)
impl<A: VldSchema + JsonSchema, B: VldSchema + JsonSchema, C: VldSchema + JsonSchema, D: VldSchema + JsonSchema, E: VldSchema + JsonSchema> JsonSchema for (A, B, C, D, E)
Source§fn json_schema(&self) -> Value
fn json_schema(&self) -> Value
openapi only.Source§impl<A: VldSchema + JsonSchema, B: VldSchema + JsonSchema, C: VldSchema + JsonSchema, D: VldSchema + JsonSchema> JsonSchema for (A, B, C, D)
impl<A: VldSchema + JsonSchema, B: VldSchema + JsonSchema, C: VldSchema + JsonSchema, D: VldSchema + JsonSchema> JsonSchema for (A, B, C, D)
Source§fn json_schema(&self) -> Value
fn json_schema(&self) -> Value
openapi only.Source§impl<A: VldSchema + JsonSchema, B: VldSchema + JsonSchema, C: VldSchema + JsonSchema> JsonSchema for (A, B, C)
impl<A: VldSchema + JsonSchema, B: VldSchema + JsonSchema, C: VldSchema + JsonSchema> JsonSchema for (A, B, C)
Source§fn json_schema(&self) -> Value
fn json_schema(&self) -> Value
openapi only.Source§impl<A: VldSchema + JsonSchema, B: VldSchema + JsonSchema> JsonSchema for (A, B)
impl<A: VldSchema + JsonSchema, B: VldSchema + JsonSchema> JsonSchema for (A, B)
Source§fn json_schema(&self) -> Value
fn json_schema(&self) -> Value
openapi only.Source§impl<A: VldSchema + JsonSchema> JsonSchema for (A,)
impl<A: VldSchema + JsonSchema> JsonSchema for (A,)
Source§fn json_schema(&self) -> Value
fn json_schema(&self) -> Value
openapi only.Implementors§
impl JsonSchema for AnyKey
impl JsonSchema for ZAny
Generate a JSON Schema representation (empty schema = any).
impl JsonSchema for ZBoolean
Generate a JSON Schema representation.
impl JsonSchema for ZBytes
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
{"type": "string", "minLength": 1, "maxLength": 1}.
impl JsonSchema for ZDecimal
decimal only.JSON Schema: a decimal-format string with x-minDecimal /
x-exclusiveMinDecimal (strictest lower bound, sign flags included),
x-maxDecimal / x-exclusiveMaxDecimal and x-multipleOfDecimal.
impl JsonSchema for ZDiscriminatedUnion
{"anyOf": [<variant schemas>]}.
impl JsonSchema for ZDuration
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
Generate a JSON Schema representation.
impl JsonSchema for ZF32
impl JsonSchema for ZFile
file only.impl JsonSchema for ZIpNetwork
net only.impl JsonSchema for ZJsonValue
impl JsonSchema for ZNever
{"not": {}} (matches nothing).
impl JsonSchema for ZNull
{"type": "null"}.
impl JsonSchema for ZNumber
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
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
impl JsonSchema for ZSocketAddr
impl JsonSchema for ZString
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).
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<B: DateBackend> JsonSchema for ZDate<B>
chrono or jiff or time only.{"type": "string", "format": "date"}; min/max become
formatMinimum/formatMaximum, past()/future() x-past/x-future.
impl<B: DateBackend> JsonSchema for ZDateTime<B>
chrono or jiff or time only.{"type": "string", "format": "date-time"} when an offset is required
(with_timezone_only,
timezone_offset_only). By default naive
input is accepted too, which date-time forbids, so the schema is
{"type": "string", "anyOf": [{"format": "date-time"}, {"pattern": <naive>}]}.
min/max become formatMinimum/formatMaximum, past()/future()
x-past/x-future.
impl<B: DateBackend> JsonSchema for ZTime<B>
chrono or jiff or time only.{"type": "string", "format": "partial-time", "pattern": ...} — RFC 3339
partial-time (not format: time, which requires an offset; validators
ignore the unknown format and use the pattern); min/max become
formatMinimum/formatMaximum.
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>
[[key, value], ...]: an array of 2-item tuples.
impl<K: JsonSchema> JsonSchema for KeySchema<K>
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>
impl<S: VldSchema + JsonSchema> JsonSchema for ZCatch<S>
The inner schema; never required (a missing key yields the fallback).
impl<S: VldSchema + JsonSchema> JsonSchema for ZDefault<S>
impl<S: VldSchema + JsonSchema> JsonSchema for ZDescribe<S>
impl<S: VldSchema + JsonSchema> JsonSchema for ZNullable<S>
The key is required and null is allowed (TypeScript x: T | null).
impl<S: VldSchema + JsonSchema> JsonSchema for ZNullish<S>
May be left out or null (TypeScript x?: T | null).
impl<S: VldSchema + JsonSchema> JsonSchema for ZOptional<S>
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 ZMessage<S>where
S: VldSchema + JsonSchema,
impl<T, F> JsonSchema for NestedSchema<T, F>
impl<T: Clone> JsonSchema for ZEnumOf<T>
impl<T: IntType> JsonSchema for ZInteger<T>
{"type": "integer"} plus bounds; typed integers (vld::u8(), …) add
format and the type range.
impl<T: IntoLiteral> JsonSchema for ZLiteral<T>
{"const": <literal>}.
impl<T: VldSchema, F: Fn() -> T> JsonSchema for ZLazy<T, F>
{} — a recursive schema cannot be expanded inline.
impl<T> JsonSchema for ZArray<T>where
T: VldSchema + JsonSchema,
impl<T> JsonSchema for ZFromSerde<T>
impl<T> JsonSchema for ZFromStr<T>
impl<T> JsonSchema for ZSet<T>
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>
{"type": "object", "additionalProperties": <value>}; a key schema adds
propertyNames.