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

first valid openapi spec generated

This commit is contained in:
Dominic 2019-09-30 23:53:55 +02:00
parent 681482ece3
commit d9b4b22af3
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
4 changed files with 130 additions and 20 deletions

View file

@ -1,4 +1,11 @@
#[cfg(feature = "openapi")]
pub mod openapi
{
pub use indexmap::IndexMap;
pub use openapiv3::{ObjectType, ReferenceOr, Schema, SchemaData, SchemaKind, Type};
}
#[cfg(not(feature = "openapi"))]
#[macro_export]
macro_rules! rest_struct {
($struct_name:ident { $($field_id:ident : $field_ty:ty),* }) => {
@ -10,6 +17,52 @@ macro_rules! rest_struct {
}
}
#[cfg(feature = "openapi")]
#[macro_export]
macro_rules! rest_struct {
($struct_name:ident { $($field_id:ident : $field_ty:ty),* }) => {
#[derive(serde::Deserialize, serde::Serialize)]
struct $struct_name
{
$($field_id : $field_ty),*
}
impl ::gotham_restful::OpenapiType for $struct_name
{
fn schema_name() -> Option<String>
{
Some(stringify!($struct_name).to_string())
}
fn to_schema() -> ::gotham_restful::helper::openapi::SchemaKind
{
use ::gotham_restful::helper::openapi::*;
let mut properties : IndexMap<String, ReferenceOr<Box<Schema>>> = IndexMap::new();
let mut required : Vec<String> = Vec::new();
$(
properties.insert(
stringify!($field_id).to_string(),
ReferenceOr::Item(Box::new(Schema {
schema_data: SchemaData::default(),
schema_kind: <$field_ty>::to_schema()
}))
);
)*
SchemaKind::Type(Type::Object(ObjectType {
properties,
required,
additional_properties: None,
min_properties: None,
max_properties: None
}))
}
}
}
}
#[macro_export]
macro_rules! rest_resource {
($res_name:ident, $route:ident => $setup:block) => {