feat: add JsonSchema to gpui
This commit is contained in:
parent
cfc1856210
commit
b45f5f0489
9 changed files with 90 additions and 35 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue