use indexmap::IndexMap;
use serde::Serialize;
use super::type_expr::{IrTypeExpr, IrValidation};
#[derive(Debug, Clone, Serialize)]
pub struct IrSchema {
pub name: String,
pub description: Option<String>,
pub deprecated: bool,
pub kind: IrSchemaKind,
pub is_component: bool,
}
#[derive(Debug, Clone, Serialize)]
pub enum IrSchemaKind {
Object(IrObject),
Enum(IrEnum),
TaggedUnion(IrTaggedUnion),
Union(IrUnion),
Intersection(IrIntersection),
Alias(IrTypeExpr),
}
#[derive(Debug, Clone, Serialize)]
pub struct IrObject {
pub properties: IndexMap<String, IrProperty>,
pub additional_properties: Option<IrTypeExpr>,
}
#[derive(Debug, Clone, Serialize)]
pub struct IrProperty {
pub name: String,
pub type_expr: IrTypeExpr,
pub required: bool,
pub nullable: bool,
pub description: Option<String>,
pub default_value: Option<serde_json::Value>,
pub format: Option<String>,
pub validation: Option<IrValidation>,
}
#[derive(Debug, Clone, Serialize)]
pub struct IrEnum {
pub value_type: IrEnumValueType,
pub values: Vec<IrEnumValue>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub enum IrEnumValueType {
String,
Integer,
Number,
Mixed,
}
#[derive(Debug, Clone, Serialize)]
pub struct IrEnumValue {
pub value: serde_json::Value,
pub description: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct IrTaggedUnion {
pub discriminator_field: String,
pub tagging: TaggingStyle,
pub variants: Vec<IrTaggedVariant>,
}
#[derive(Debug, Clone, Serialize)]
pub enum TaggingStyle {
Internal,
Adjacent { content_field: String },
External,
}
#[derive(Debug, Clone, Serialize)]
pub struct IrTaggedVariant {
pub discriminator_value: String,
pub content_type: IrTypeExpr,
pub description: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct IrUnion {
pub members: Vec<IrTypeExpr>,
pub nullable: bool,
}
#[derive(Debug, Clone, Serialize)]
pub struct IrIntersection {
pub members: Vec<IrTypeExpr>,
}