Skip to content

Commit b01c3d4

Browse files
committed
Make the JsonSchemaAs impl for Hex generic
1 parent 8bedbf5 commit b01c3d4

File tree

3 files changed

+9
-82
lines changed

3 files changed

+9
-82
lines changed

serde_with/src/schemars_0_8.rs

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -405,42 +405,13 @@ impl<T> JsonSchemaAs<T> for DisplayFromStr {
405405
}
406406

407407
#[cfg(feature = "hex")]
408-
impl<T> JsonSchemaAs<T> for hex::Hex<formats::Lowercase> {
408+
impl<T, F: formats::Format> JsonSchemaAs<T> for hex::Hex<F> {
409409
fn schema_name() -> String {
410-
"Hex<Lowercase>".into()
410+
"Hex<F>".into()
411411
}
412412

413413
fn schema_id() -> Cow<'static, str> {
414-
"serde_with::hex::Hex<Lowercase>".into()
415-
}
416-
417-
fn json_schema(_: &mut SchemaGenerator) -> Schema {
418-
use ::schemars_0_8::schema::StringValidation;
419-
420-
SchemaObject {
421-
instance_type: Some(InstanceType::String.into()),
422-
string: Some(Box::new(StringValidation {
423-
pattern: Some(r"^(?:[0-9A-Fa-f]{2})*$".to_owned()),
424-
..Default::default()
425-
})),
426-
..Default::default()
427-
}
428-
.into()
429-
}
430-
431-
fn is_referenceable() -> bool {
432-
false
433-
}
434-
}
435-
436-
#[cfg(feature = "hex")]
437-
impl<T> JsonSchemaAs<T> for hex::Hex<formats::Uppercase> {
438-
fn schema_name() -> String {
439-
"Hex<Uppercase>".into()
440-
}
441-
442-
fn schema_id() -> Cow<'static, str> {
443-
"serde_with::hex::Hex<Uppercase>".into()
414+
"serde_with::hex::Hex<F>".into()
444415
}
445416

446417
fn json_schema(_: &mut SchemaGenerator) -> Schema {

serde_with/src/schemars_0_9.rs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -407,35 +407,13 @@ impl<T> JsonSchemaAs<T> for DisplayFromStr {
407407
}
408408

409409
#[cfg(feature = "hex")]
410-
impl<T> JsonSchemaAs<T> for hex::Hex<formats::Lowercase> {
410+
impl<T, F: formats::Format> JsonSchemaAs<T> for hex::Hex<F> {
411411
fn schema_name() -> Cow<'static, str> {
412-
"Hex<Lowercase>".into()
412+
"Hex<F>".into()
413413
}
414414

415415
fn schema_id() -> Cow<'static, str> {
416-
"serde_with::hex::Hex<Lowercase>".into()
417-
}
418-
419-
fn json_schema(_: &mut SchemaGenerator) -> Schema {
420-
json_schema!({
421-
"type": "string",
422-
"pattern": r"^(?:[0-9A-Fa-f]{2})*$",
423-
})
424-
}
425-
426-
fn inline_schema() -> bool {
427-
true
428-
}
429-
}
430-
431-
#[cfg(feature = "hex")]
432-
impl<T> JsonSchemaAs<T> for hex::Hex<formats::Uppercase> {
433-
fn schema_name() -> Cow<'static, str> {
434-
"Hex<Uppercase>".into()
435-
}
436-
437-
fn schema_id() -> Cow<'static, str> {
438-
"serde_with::hex::Hex<Uppercase>".into()
416+
"serde_with::hex::Hex<F>".into()
439417
}
440418

441419
fn json_schema(_: &mut SchemaGenerator) -> Schema {

serde_with/src/schemars_1.rs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -409,35 +409,13 @@ impl<T> JsonSchemaAs<T> for DisplayFromStr {
409409
}
410410

411411
#[cfg(feature = "hex")]
412-
impl<T> JsonSchemaAs<T> for hex::Hex<formats::Lowercase> {
412+
impl<T, F: formats::Format> JsonSchemaAs<T> for hex::Hex<F> {
413413
fn schema_name() -> Cow<'static, str> {
414-
"Hex<Lowercase>".into()
414+
"Hex<F>".into()
415415
}
416416

417417
fn schema_id() -> Cow<'static, str> {
418-
"serde_with::hex::Hex<Lowercase>".into()
419-
}
420-
421-
fn json_schema(_: &mut SchemaGenerator) -> Schema {
422-
json_schema!({
423-
"type": "string",
424-
"pattern": r"^(?:[0-9A-Fa-f]{2})*$",
425-
})
426-
}
427-
428-
fn inline_schema() -> bool {
429-
true
430-
}
431-
}
432-
433-
#[cfg(feature = "hex")]
434-
impl<T> JsonSchemaAs<T> for hex::Hex<formats::Uppercase> {
435-
fn schema_name() -> Cow<'static, str> {
436-
"Hex<Uppercase>".into()
437-
}
438-
439-
fn schema_id() -> Cow<'static, str> {
440-
"serde_with::hex::Hex<Uppercase>".into()
418+
"serde_with::hex::Hex<F>".into()
441419
}
442420

443421
fn json_schema(_: &mut SchemaGenerator) -> Schema {

0 commit comments

Comments
 (0)