implement schemars::JsonSchema for StarshipConditionalStyleConfig

thanks for your help david!
This commit is contained in:
Filip Bachul 2022-06-23 20:44:48 +02:00
parent 1cf8aef297
commit 7a0db3c1fb
2 changed files with 28 additions and 7 deletions

View File

@ -2259,7 +2259,7 @@
], ],
"allOf": [ "allOf": [
{ {
"$ref": "#/definitions/Either_for_StarshipConditionalStyleConfig_and_Array_of_StarshipConditionalStyleConfig" "$ref": "#/definitions/Either_for_Either_for_String_and_StarshipConditionalStyle_and_Array_of_Either_for_String_and_StarshipConditionalStyle"
} }
] ]
}, },
@ -2296,21 +2296,28 @@
} }
} }
}, },
"Either_for_StarshipConditionalStyleConfig_and_Array_of_StarshipConditionalStyleConfig": { "Either_for_Either_for_String_and_StarshipConditionalStyle_and_Array_of_Either_for_String_and_StarshipConditionalStyle": {
"anyOf": [ "anyOf": [
{ {
"$ref": "#/definitions/StarshipConditionalStyleConfig" "$ref": "#/definitions/Either_for_String_and_StarshipConditionalStyle"
}, },
{ {
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/StarshipConditionalStyleConfig" "$ref": "#/definitions/Either_for_String_and_StarshipConditionalStyle"
} }
} }
] ]
}, },
"StarshipConditionalStyleConfig": { "Either_for_String_and_StarshipConditionalStyle": {
"anyOf": [
{
"type": "string"
},
{
"$ref": "#/definitions/StarshipConditionalStyle" "$ref": "#/definitions/StarshipConditionalStyle"
}
]
}, },
"StarshipConditionalStyle": { "StarshipConditionalStyle": {
"type": "object", "type": "object",

View File

@ -77,9 +77,23 @@ impl<'a> StarshipConditionalStyle<'a> {
} }
#[derive(Clone, Debug, Default, Serialize, PartialEq)] #[derive(Clone, Debug, Default, Serialize, PartialEq)]
#[cfg_attr(feature = "config-schema", derive(schemars::JsonSchema))]
pub struct StarshipConditionalStyleConfig<'a>(StarshipConditionalStyle<'a>); pub struct StarshipConditionalStyleConfig<'a>(StarshipConditionalStyle<'a>);
#[cfg(feature = "config-schema")]
impl<'a> schemars::JsonSchema for StarshipConditionalStyleConfig<'a> {
fn schema_name() -> String {
Either::<String, StarshipConditionalStyle>::schema_name()
}
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
Either::<String, StarshipConditionalStyle>::json_schema(gen)
}
fn is_referenceable() -> bool {
Either::<String, StarshipConditionalStyle>::is_referenceable()
}
}
impl<'de: 'a, 'a> Deserialize<'de> for StarshipConditionalStyleConfig<'a> { impl<'de: 'a, 'a> Deserialize<'de> for StarshipConditionalStyleConfig<'a> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where where