1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-04-20 06:54:46 +00:00
deprecated-gotham-restful/src/openapi/types.rs

70 lines
1.1 KiB
Rust
Raw Normal View History

2019-09-30 20:58:15 +02:00
use indexmap::IndexMap;
use openapiv3::{
IntegerType, NumberType, ObjectType, SchemaKind, StringType, Type
};
use serde::Serialize;
pub trait OpenapiType : Serialize
{
fn to_schema() -> SchemaKind;
}
impl OpenapiType for ()
{
fn to_schema() -> SchemaKind
{
SchemaKind::Type(Type::Object(ObjectType::default()))
}
}
impl OpenapiType for bool
{
fn to_schema() -> SchemaKind
{
SchemaKind::Type(Type::Boolean{})
}
}
macro_rules! int_types {
($($int_ty:ty),*) => {$(
impl OpenapiType for $int_ty
{
fn to_schema() -> SchemaKind
{
SchemaKind::Type(Type::Integer(IntegerType::default()))
}
}
)*}
}
int_types!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128);
macro_rules! num_types {
($($num_ty:ty),*) => {$(
impl OpenapiType for $num_ty
{
fn to_schema() -> SchemaKind
{
SchemaKind::Type(Type::Number(NumberType::default()))
}
}
)*}
}
num_types!(f32, f64);
macro_rules! str_types {
($($str_ty:ty),*) => {$(
impl OpenapiType for $str_ty
{
fn to_schema() -> SchemaKind
{
SchemaKind::Type(Type::String(StringType::default()))
}
}
)*}
}
str_types!(String, &str);