Skip to main content

kynos_openapi/model/schema/
types.rs

1//! The `type` keyword: the seven primitives, and unions of them.
2
3use serde::{Deserialize, Serialize};
4
5/// One of the seven JSON Schema primitive types.
6#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(rename_all = "lowercase")]
8pub enum SchemaType {
9    /// The JSON `null` literal.
10    Null,
11    /// `true` or `false`.
12    Boolean,
13    /// A JSON object.
14    Object,
15    /// A JSON array.
16    Array,
17    /// Any JSON number.
18    Number,
19    /// A JSON string.
20    String,
21    /// A JSON number with a zero fractional part.
22    ///
23    /// JSON has no distinct integer type, so `1` and `1.0` are the same
24    /// instance for validation purposes.
25    Integer,
26}
27
28/// The value of the `type` keyword: one type, or a union of them.
29#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum TypeSet {
32    /// Exactly one type.
33    One(SchemaType),
34    /// Any of several types, as used for nullability.
35    Many(Vec<SchemaType>),
36}