Skip to main content

JsonSchema

Trait JsonSchema 

Source
pub trait JsonSchema {
    // Required method
    fn json_schema(&self) -> Value;

    // Provided method
    fn is_required(&self) -> bool { ... }
}
Available on crate feature 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§

Source

fn json_schema(&self) -> Value

Generate a JSON Schema representation.

Provided Methods§

Source

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)

Source§

fn json_schema(&self) -> Value

Available on crate feature 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)

Source§

fn json_schema(&self) -> Value

Available on crate feature 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)

Source§

fn json_schema(&self) -> Value

Available on crate feature 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)

Source§

fn json_schema(&self) -> Value

Available on crate feature 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)

Source§

fn json_schema(&self) -> Value

Available on crate feature 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)

Source§

fn json_schema(&self) -> Value

Available on crate feature 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)

Source§

fn json_schema(&self) -> Value

Available on crate feature 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)

Source§

fn json_schema(&self) -> Value

Available on crate feature openapi only.
Source§

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

Available on crate feature openapi only.
Source§

impl<A: VldSchema + JsonSchema, B: VldSchema + JsonSchema, C: VldSchema + JsonSchema> JsonSchema for (A, B, C)

Source§

fn json_schema(&self) -> Value

Available on crate feature openapi only.
Source§

impl<A: VldSchema + JsonSchema, B: VldSchema + JsonSchema> JsonSchema for (A, B)

Source§

fn json_schema(&self) -> Value

Available on crate feature openapi only.
Source§

impl<A: VldSchema + JsonSchema> JsonSchema for (A,)

Source§

fn json_schema(&self) -> Value

Available on crate feature openapi only.

Implementors§

Source§

impl JsonSchema for AnyKey

Source§

impl JsonSchema for ZAny

Generate a JSON Schema representation (empty schema = any).

Source§

impl JsonSchema for ZBoolean

Generate a JSON Schema representation.

Source§

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).

Source§

impl JsonSchema for ZChar

{"type": "string", "minLength": 1, "maxLength": 1}.

Source§

impl JsonSchema for ZDecimal

Available on crate feature 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.

Source§

impl JsonSchema for ZDiscriminatedUnion

{"anyOf": [<variant schemas>]}.

Source§

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.

Source§

impl JsonSchema for ZEnum

Generate a JSON Schema representation.

Source§

impl JsonSchema for ZF32

Source§

impl JsonSchema for ZFile

Available on crate feature file only.
Source§

impl JsonSchema for ZIpNetwork

Available on crate feature net only.
Source§

impl JsonSchema for ZJsonValue

Source§

impl JsonSchema for ZNever

{"not": {}} (matches nothing).

Source§

impl JsonSchema for ZNull

{"type": "null"}.

Source§

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.

Source§

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.

Source§

impl JsonSchema for ZPath

Source§

impl JsonSchema for ZSocketAddr

Source§

impl JsonSchema for ZString

Generate a JSON Schema representation of this string schema.

  • Length bounds: the strictest min/max/len/non_empty wins.
  • Formats: the first goes into format, further ones into allOf.
  • pattern/starts_with/ends_with/contains become patterns (first in pattern, further ones in allOf).
Source§

impl<A, B, C> JsonSchema for ZUnion3<A, B, C>

Source§

impl<A, B> JsonSchema for ZIntersection<A, B>

Source§

impl<A, B> JsonSchema for ZPipe<A, B>
where A: VldSchema, B: VldSchema, A::Output: Serialize,

{} — the output of the first stage is re-validated by the second, so no single input schema describes the pipe.

Source§

impl<A, B> JsonSchema for ZUnion2<A, B>

Source§

impl<B: DateBackend> JsonSchema for ZDate<B>

Available on crate features chrono or jiff or time only.

{"type": "string", "format": "date"}; min/max become formatMinimum/formatMaximum, past()/future() x-past/x-future.

Source§

impl<B: DateBackend> JsonSchema for ZDateTime<B>

Available on crate features 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.

Source§

impl<B: DateBackend> JsonSchema for ZTime<B>

Available on crate features 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.

Source§

impl<F, S> JsonSchema for ZPreprocess<F, S>
where S: VldSchema + JsonSchema, F: Fn(&Value) -> Value,

Source§

impl<F, T> JsonSchema for ZCustom<F, T>

{} — arbitrary validation function.

Source§

impl<K, V> JsonSchema for ZMap<K, V>

[[key, value], ...]: an array of 2-item tuples.

Source§

impl<K: JsonSchema> JsonSchema for KeySchema<K>

Source§

impl<S, F, U, E> JsonSchema for ZTryTransform<S, F, U>
where S: VldSchema + JsonSchema, F: Fn(S::Output) -> Result<U, E>, E: Display,

Source§

impl<S, F, U> JsonSchema for ZTransform<S, F, U>
where S: VldSchema + JsonSchema, F: Fn(S::Output) -> U,

Source§

impl<S, F> JsonSchema for ZRefine<S, F>
where S: VldSchema + JsonSchema, F: Fn(&S::Output) -> bool,

Source§

impl<S, F> JsonSchema for ZSuperRefine<S, F>
where S: VldSchema + JsonSchema, F: Fn(&S::Output, &mut VldError),

Source§

impl<S, R> JsonSchema for ZRule<S, R>
where S: JsonSchema + VldSchema, R: Rule<<S as VldSchema>::Output>,

Source§

impl<S: VldSchema + JsonSchema> JsonSchema for ZCatch<S>
where S::Output: Clone,

The inner schema; never required (a missing key yields the fallback).

Source§

impl<S: VldSchema + JsonSchema> JsonSchema for ZDefault<S>
where S::Output: Clone + Serialize,

Source§

impl<S: VldSchema + JsonSchema> JsonSchema for ZDescribe<S>

Source§

impl<S: VldSchema + JsonSchema> JsonSchema for ZNullable<S>

The key is required and null is allowed (TypeScript x: T | null).

Source§

impl<S: VldSchema + JsonSchema> JsonSchema for ZNullish<S>

May be left out or null (TypeScript x?: T | null).

Source§

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).

Source§

impl<S> JsonSchema for ZMessage<S>
where S: VldSchema + JsonSchema,

Source§

impl<T, F> JsonSchema for NestedSchema<T, F>
where F: Fn(&Value) -> Result<T, VldError>,

Source§

impl<T: Clone> JsonSchema for ZEnumOf<T>

Source§

impl<T: IntType> JsonSchema for ZInteger<T>

{"type": "integer"} plus bounds; typed integers (vld::u8(), …) add format and the type range.

Source§

impl<T: IntoLiteral> JsonSchema for ZLiteral<T>

{"const": <literal>}.

Source§

impl<T: VldSchema, F: Fn() -> T> JsonSchema for ZLazy<T, F>

{} — a recursive schema cannot be expanded inline.

Source§

impl<T> JsonSchema for ZArray<T>
where T: VldSchema + JsonSchema,

Source§

impl<T> JsonSchema for ZFromSerde<T>

Source§

impl<T> JsonSchema for ZFromStr<T>

Source§

impl<T> JsonSchema for ZSet<T>
where T: VldSchema + JsonSchema, T::Output: Eq + Hash,

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.

Source§

impl<V, K, M> JsonSchema for ZRecord<V, K, M>

{"type": "object", "additionalProperties": <value>}; a key schema adds propertyNames.