JsonSchema

Struct JsonSchema 

Source
pub struct JsonSchema {
Show 34 fields pub schema: Option<String>, pub id: Option<String>, pub title: Option<String>, pub description: Option<String>, pub schema_type: Option<JsonSchemaType>, pub format: Option<String>, pub properties: Option<HashMap<String, JsonSchema>>, pub required: Option<Vec<String>>, pub items: Option<Box<JsonSchema>>, pub additional_properties: Option<AdditionalProperties>, pub min_length: Option<usize>, pub max_length: Option<usize>, pub pattern: Option<String>, pub minimum: Option<f64>, pub maximum: Option<f64>, pub exclusive_minimum: Option<f64>, pub exclusive_maximum: Option<f64>, pub multiple_of: Option<f64>, pub min_items: Option<usize>, pub max_items: Option<usize>, pub unique_items: Option<bool>, pub enum: Option<Vec<Value>>, pub const: Option<Value>, pub reference: Option<String>, pub any_of: Option<Vec<JsonSchema>>, pub all_of: Option<Vec<JsonSchema>>, pub one_of: Option<Vec<JsonSchema>>, pub not: Option<Box<JsonSchema>>, pub default: Option<Value>, pub examples: Option<Vec<Value>>, pub deprecated: Option<bool>, pub read_only: Option<bool>, pub write_only: Option<bool>, pub defs: Option<HashMap<String, JsonSchema>>,
}
Expand description

JSON Schema document (Draft 2020-12)

Fields§

§schema: Option<String>§id: Option<String>§title: Option<String>§description: Option<String>§schema_type: Option<JsonSchemaType>§format: Option<String>§properties: Option<HashMap<String, JsonSchema>>§required: Option<Vec<String>>§items: Option<Box<JsonSchema>>§additional_properties: Option<AdditionalProperties>§min_length: Option<usize>§max_length: Option<usize>§pattern: Option<String>§minimum: Option<f64>§maximum: Option<f64>§exclusive_minimum: Option<f64>§exclusive_maximum: Option<f64>§multiple_of: Option<f64>§min_items: Option<usize>§max_items: Option<usize>§unique_items: Option<bool>§enum: Option<Vec<Value>>§const: Option<Value>§reference: Option<String>§any_of: Option<Vec<JsonSchema>>§all_of: Option<Vec<JsonSchema>>§one_of: Option<Vec<JsonSchema>>§not: Option<Box<JsonSchema>>§default: Option<Value>§examples: Option<Vec<Value>>§deprecated: Option<bool>§read_only: Option<bool>§write_only: Option<bool>§defs: Option<HashMap<String, JsonSchema>>

Implementations§

Source§

impl JsonSchema

Source

pub fn new() -> Self

Create a new empty schema

Source

pub fn string() -> Self

Create a string schema

Source

pub fn integer() -> Self

Create an integer schema

Source

pub fn number() -> Self

Create a number schema

Source

pub fn boolean() -> Self

Create a boolean schema

Source

pub fn array(items: JsonSchema) -> Self

Create an array schema

Source

pub fn object() -> Self

Create an object schema

Source

pub fn null() -> Self

Create a null schema

Source

pub fn reference(name: &str) -> Self

Create a reference to another schema

Source

pub fn title(self, title: impl Into<String>) -> Self

Set the title

Source

pub fn description(self, desc: impl Into<String>) -> Self

Set the description

Source

pub fn format(self, format: impl Into<String>) -> Self

Set the format

Source

pub fn property(self, name: impl Into<String>, schema: JsonSchema) -> Self

Add a property to an object schema

Source

pub fn required(self, fields: &[&str]) -> Self

Set required fields

Source

pub fn min_length(self, min: usize) -> Self

Set minimum length for strings

Source

pub fn max_length(self, max: usize) -> Self

Set maximum length for strings

Source

pub fn pattern(self, pattern: impl Into<String>) -> Self

Set regex pattern for strings

Source

pub fn minimum(self, min: impl Into<f64>) -> Self

Set minimum value for numbers

Source

pub fn maximum(self, max: impl Into<f64>) -> Self

Set maximum value for numbers

Source

pub fn exclusive_minimum(self, min: impl Into<f64>) -> Self

Set exclusive minimum for numbers

Source

pub fn exclusive_maximum(self, max: impl Into<f64>) -> Self

Set exclusive maximum for numbers

Source

pub fn multiple_of(self, divisor: impl Into<f64>) -> Self

Set multipleOf constraint for numbers

Source

pub fn min_items(self, min: usize) -> Self

Set minimum items for arrays

Source

pub fn max_items(self, max: usize) -> Self

Set maximum items for arrays

Source

pub fn unique_items(self, unique: bool) -> Self

Set unique items constraint for arrays

Source

pub fn enum_values<T: Serialize>(self, values: &[T]) -> Self

Set enum values

Source

pub fn const_value<T: Serialize>(self, value: T) -> Self

Set a const value

Source

pub fn default<T: Serialize>(self, value: T) -> Self

Set a default value

Source

pub fn examples<T: Serialize>(self, values: Vec<T>) -> Self

Set example values

Source

pub fn deprecated(self, deprecated: bool) -> Self

Mark as deprecated

Source

pub fn read_only(self, read_only: bool) -> Self

Mark as read-only

Source

pub fn write_only(self, write_only: bool) -> Self

Mark as write-only

Source

pub fn any_of(schemas: Vec<JsonSchema>) -> Self

Create an anyOf schema

Source

pub fn all_of(schemas: Vec<JsonSchema>) -> Self

Create an allOf schema

Source

pub fn one_of(schemas: Vec<JsonSchema>) -> Self

Create a oneOf schema

Source

pub fn negation(schema: JsonSchema) -> Self

Create a negation schema (not)

Trait Implementations§

Source§

impl Clone for JsonSchema

Source§

fn clone(&self) -> JsonSchema

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for JsonSchema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for JsonSchema

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for JsonSchema

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for JsonSchema

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,