use serde::{Deserialize, Serialize};
use serde_json::Value;
use super::Schema;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ObjectSchema {
pub name: String,
pub description: Option<String>,
pub properties: Vec<Schema>,
pub required: Vec<String>,
pub allow_additional_properties: bool,
pub json_schema: Option<Value>,
}
impl ObjectSchema {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
description: None,
properties: Vec::new(),
required: Vec::new(),
allow_additional_properties: false,
json_schema: None,
}
}
pub fn from_raw_json_schema(name: impl Into<String>, json_schema: Value) -> Self {
Self {
json_schema: Some(json_schema),
..Self::new(name)
}
}
pub fn with_description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
}
pub fn with_property(mut self, schema: Schema, required: bool) -> Self {
if required {
self.required.push(schema.name().to_string());
}
self.properties.push(schema);
self
}
pub fn with_additional_properties(mut self, allow: bool) -> Self {
self.allow_additional_properties = allow;
self
}
}