Implement JsonSchema for std::net types

This commit is contained in:
Graham Esau 2019-10-27 21:24:29 +00:00
parent ebb7173dfc
commit b334bef91a
2 changed files with 24 additions and 14 deletions

View file

@ -115,6 +115,18 @@ impl<T: ?Sized> JsonSchema for std::marker::PhantomData<T> {
} }
} }
impl<'a> JsonSchema for std::fmt::Arguments<'a> {
no_ref_schema!();
fn schema_name() -> String {
<String>::schema_name()
}
fn json_schema(gen: &mut SchemaGenerator) -> Schema {
<String>::json_schema(gen)
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View file

@ -1,6 +1,7 @@
use crate::gen::SchemaGenerator; use crate::gen::SchemaGenerator;
use crate::schema::*; use crate::schema::*;
use crate::JsonSchema; use crate::JsonSchema;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
macro_rules! simple_impl { macro_rules! simple_impl {
@ -32,8 +33,6 @@ macro_rules! simple_impl {
simple_impl!(str => String); simple_impl!(str => String);
simple_impl!(String => String); simple_impl!(String => String);
simple_impl!(Path => String);
simple_impl!(PathBuf => String);
simple_impl!(bool => Boolean); simple_impl!(bool => Boolean);
simple_impl!(f32 => Number, "float"); simple_impl!(f32 => Number, "float");
simple_impl!(f64 => Number, "double"); simple_impl!(f64 => Number, "double");
@ -51,6 +50,17 @@ simple_impl!(u128 => Integer, "uint128");
simple_impl!(usize => Integer, "uint"); simple_impl!(usize => Integer, "uint");
simple_impl!(() => Null); simple_impl!(() => Null);
simple_impl!(Path => String);
simple_impl!(PathBuf => String);
simple_impl!(Ipv4Addr => String, "ipv4");
simple_impl!(Ipv6Addr => String, "ipv6");
simple_impl!(IpAddr => String, "ip");
simple_impl!(SocketAddr => String);
simple_impl!(SocketAddrV4 => String);
simple_impl!(SocketAddrV6 => String);
impl JsonSchema for char { impl JsonSchema for char {
no_ref_schema!(); no_ref_schema!();
@ -71,15 +81,3 @@ impl JsonSchema for char {
.into() .into()
} }
} }
impl<'a> JsonSchema for std::fmt::Arguments<'a> {
no_ref_schema!();
fn schema_name() -> String {
<String>::schema_name()
}
fn json_schema(gen: &mut SchemaGenerator) -> Schema {
<String>::json_schema(gen)
}
}