feat: add JsonSchema to gpui

This commit is contained in:
Sergey Onufrienko 2023-06-16 21:36:42 +02:00
parent cfc1856210
commit b45f5f0489
No known key found for this signature in database
GPG key ID: 3299873ECFD30CA3
9 changed files with 90 additions and 35 deletions

View file

@ -6,17 +6,19 @@ use std::{
use crate::json::ToJson;
use pathfinder_color::{ColorF, ColorU};
use schemars::{
gen::SchemaGenerator,
schema::{InstanceType, Schema, SchemaObject},
JsonSchema,
};
use serde::{
de::{self, Unexpected},
Deserialize, Deserializer,
};
use serde_json::json;
use ts_rs::TS;
#[derive(Clone, Copy, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(transparent)]
#[derive(TS)]
#[ts(export, export_to = "theme/types/")]
pub struct Color(ColorU);
impl Color {
@ -130,3 +132,16 @@ impl fmt::Debug for Color {
self.0.fmt(f)
}
}
impl JsonSchema for Color {
fn schema_name() -> String {
"Color".into()
}
fn json_schema(_: &mut SchemaGenerator) -> Schema {
let mut schema = SchemaObject::default();
schema.instance_type = Some(InstanceType::Integer.into());
schema.format = Some("uint".to_owned());
Schema::Object(schema)
}
}