Change color representation in json schema
This commit is contained in:
parent
ea46947489
commit
6ad0b5d79f
1 changed files with 3 additions and 20 deletions
|
@ -6,20 +6,16 @@ use std::{
|
||||||
|
|
||||||
use crate::json::ToJson;
|
use crate::json::ToJson;
|
||||||
use pathfinder_color::{ColorF, ColorU};
|
use pathfinder_color::{ColorF, ColorU};
|
||||||
use schemars::{
|
use schemars::JsonSchema;
|
||||||
gen::SchemaGenerator,
|
|
||||||
schema::{InstanceType, Schema, SchemaObject},
|
|
||||||
JsonSchema,
|
|
||||||
};
|
|
||||||
use serde::{
|
use serde::{
|
||||||
de::{self, Unexpected},
|
de::{self, Unexpected},
|
||||||
Deserialize, Deserializer,
|
Deserialize, Deserializer,
|
||||||
};
|
};
|
||||||
use serde_json::json;
|
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)]
|
#[repr(transparent)]
|
||||||
pub struct Color(ColorU);
|
pub struct Color(#[schemars(with = "String")] ColorU);
|
||||||
|
|
||||||
impl Color {
|
impl Color {
|
||||||
pub fn transparent_black() -> Self {
|
pub fn transparent_black() -> Self {
|
||||||
|
@ -132,16 +128,3 @@ impl fmt::Debug for Color {
|
||||||
self.0.fmt(f)
|
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