1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-04-20 14:57:01 +00:00

introduce openapitype

This commit is contained in:
Dominic 2019-09-30 20:58:15 +02:00
parent 24f8fd96db
commit 681482ece3
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
6 changed files with 126 additions and 6 deletions

69
src/openapi/types.rs Normal file
View file

@ -0,0 +1,69 @@
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);