Change color representation in json schema

This commit is contained in:
Mikayla Maki 2023-06-19 11:47:11 -07:00
parent ea46947489
commit 6ad0b5d79f
No known key found for this signature in database

View file

@ -6,20 +6,16 @@ use std::{
use crate::json::ToJson;
use pathfinder_color::{ColorF, ColorU};
use schemars::{
gen::SchemaGenerator,
schema::{InstanceType, Schema, SchemaObject},
JsonSchema,
};
use schemars::JsonSchema;
use serde::{
de::{self, Unexpected},
Deserialize, Deserializer,
};
use serde_json::json;
#[derive(Clone, Copy, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Clone, Copy, Default, PartialEq, Eq, Hash, PartialOrd, Ord, JsonSchema)]
#[repr(transparent)]
pub struct Color(ColorU);
pub struct Color(#[schemars(with = "String")] ColorU);
impl Color {
pub fn transparent_black() -> Self {
@ -132,16 +128,3 @@ 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)
}
}