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 { ... }
}
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, 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)

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)

Source§

impl<A, B, C, D, E, F, G, H, I, J> JsonSchema for (A, B, C, D, E, F, G, H, I, J)

Source§

impl<A, B, C, D, E, F, G, H, I> JsonSchema for (A, B, C, D, E, F, G, H, I)

Source§

impl<A, B, C, D, E, F, G, H> JsonSchema for (A, B, C, D, E, F, G, H)

Source§

impl<A, B, C, D, E, F, G> JsonSchema for (A, B, C, D, E, F, G)

Source§

impl<A, B, C, D, E, F> JsonSchema for (A, B, C, D, E, F)

Source§

impl<A, B, C, D, E> JsonSchema for (A, B, C, D, E)

Source§

impl<A, B, C, D> JsonSchema for (A, B, C, D)

Source§

impl<A, B, C> JsonSchema for (A, B, C)

Source§

impl<A, B> JsonSchema for (A, B)

Source§

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

Implementors§

Source§

impl JsonSchema for AnyKey

Available on crate feature openapi only.
Source§

impl JsonSchema for ZAny

Available on crate feature openapi only.

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

Source§

impl JsonSchema for ZBoolean

Available on crate feature openapi only.

Generate a JSON Schema representation.

Source§

impl JsonSchema for ZBytes

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

Source§

impl JsonSchema for ZChar

Available on crate feature openapi only.

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

Source§

impl JsonSchema for ZDiscriminatedUnion

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

Source§

impl JsonSchema for ZDuration

Available on crate feature openapi only.

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

Available on crate feature openapi only.

Generate a JSON Schema representation.

Source§

impl JsonSchema for ZF32

Available on crate feature openapi only.
Source§

impl JsonSchema for ZJsonValue

Available on crate feature openapi only.
Source§

impl JsonSchema for ZNever

Available on crate feature openapi only.

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

Source§

impl JsonSchema for ZNull

Available on crate feature openapi only.

{"type": "null"}.

Source§

impl JsonSchema for ZNumber

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

Source§

impl JsonSchema for ZObject

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

Source§

impl JsonSchema for ZPath

Available on crate feature openapi only.
Source§

impl JsonSchema for ZSocketAddr

Available on crate feature openapi only.
Source§

impl JsonSchema for ZString

Available on crate feature openapi only.

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).
  • Password rules add format: "password" and an x-password object (lowercase, uppercase, digit, symbol: true; maxRepeat, minScore: numbers).
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 as VldSchema>::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<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>

Available on crate feature openapi only.

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

Source§

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

Available on crate feature openapi only.
Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Available on crate feature openapi only.
Source§

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

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

Source§

impl<S> JsonSchema for ZDefault<S>

Source§

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

Source§

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

Source§

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

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

Source§

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

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

Source§

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

Source§

impl<S> JsonSchema for ZRange<S>
where S: JsonSchema,

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

Source§

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

Source§

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

Available on crate feature openapi only.
Source§

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

{} — a recursive schema cannot be expanded inline.

Source§

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

Available on crate feature openapi only.
Source§

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

Available on crate feature openapi only.
Source§

impl<T> JsonSchema for ZFromSerde<T>

Available on crate feature openapi only.
Source§

impl<T> JsonSchema for ZFromStr<T>

Available on crate feature openapi only.
Source§

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

Available on crate feature openapi only.

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

Source§

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

Available on crate feature openapi only.

{"const": <literal>}.

Source§

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

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

Source§

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

Available on crate feature openapi only.

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