JsonSchema

Struct JsonSchema 

Source
pub struct JsonSchema {
Show 19 fields pub schema: String, pub id: Option<String>, pub title: Option<String>, pub description: Option<String>, pub schema_type: String, pub properties: Option<HashMap<String, JsonSchema>>, pub required: Option<Vec<String>>, pub items: Option<Box<JsonSchema>>, pub enum_values: Option<Vec<Value>>, pub additional_properties: Option<Box<JsonSchema>>, pub definitions: Option<HashMap<String, JsonSchema>>, pub minimum: Option<f64>, pub maximum: Option<f64>, pub pattern: Option<String>, pub format: Option<String>, pub one_of: Option<Vec<JsonSchema>>, pub any_of: Option<Vec<JsonSchema>>, pub all_of: Option<Vec<JsonSchema>>, pub reference: Option<String>,
}
Expand description

JSON Schema document

Fields§

§schema: String

Schema version (always “https://json-schema.org/draft/2020-12/schema”)

§id: Option<String>

Schema identifier

§title: Option<String>

Schema title

§description: Option<String>

Schema description

§schema_type: String

Type of the schema

§properties: Option<HashMap<String, JsonSchema>>

Properties for object types

§required: Option<Vec<String>>

Required property names

§items: Option<Box<JsonSchema>>

Items schema for array types

§enum_values: Option<Vec<Value>>

Enum values for enums

§additional_properties: Option<Box<JsonSchema>>

Additional properties

§definitions: Option<HashMap<String, JsonSchema>>

Schema definitions

§minimum: Option<f64>

Minimum value for numbers

§maximum: Option<f64>

Maximum value for numbers

§pattern: Option<String>

Pattern for strings

§format: Option<String>

Format for strings

§one_of: Option<Vec<JsonSchema>>

One of (union types)

§any_of: Option<Vec<JsonSchema>>

Any of (union types with overlap)

§all_of: Option<Vec<JsonSchema>>

All of (intersection types)

§reference: Option<String>

Reference to another schema

Implementations§

Source§

impl JsonSchema

Source

pub fn new(schema_type: &str) -> Self

Create a new empty schema

Source

pub fn string() -> Self

Create a string schema

Source

pub fn number() -> Self

Create a number schema

Source

pub fn integer() -> Self

Create an integer 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 reference(ref_path: &str) -> Self

Create a reference schema

Source

pub fn with_title(self, title: String) -> Self

Set title

Source

pub fn with_description(self, description: String) -> Self

Set description

Source

pub fn with_id(self, id: String) -> Self

Set ID

Source

pub fn add_property(&mut self, name: String, schema: JsonSchema)

Add a property to an object schema

Source

pub fn add_required(&mut self, name: String)

Add a required property

Source

pub fn with_enum(self, values: Vec<Value>) -> Self

Set enum values

Source

pub fn with_pattern(self, pattern: String) -> Self

Set pattern for strings

Source

pub fn with_format(self, format: String) -> Self

Set format for strings

Source

pub fn add_definition(&mut self, name: String, schema: JsonSchema)

Add a definition

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<'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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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