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

introduce OpenapiSchema type

This commit is contained in:
Dominic 2019-10-01 15:33:05 +02:00
parent 0619e69925
commit d1c7ac5887
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
5 changed files with 85 additions and 115 deletions

View file

@ -29,14 +29,9 @@ macro_rules! rest_struct {
impl ::gotham_restful::OpenapiType for $struct_name
{
fn schema_name() -> Option<String>
fn to_schema() -> ::gotham_restful::OpenapiSchema
{
Some(stringify!($struct_name).to_string())
}
fn to_schema() -> ::gotham_restful::helper::openapi::SchemaKind
{
use ::gotham_restful::helper::openapi::*;
use ::gotham_restful::{helper::openapi::*, OpenapiSchema};
let mut properties : IndexMap<String, ReferenceOr<Box<Schema>>> = IndexMap::new();
let mut required : Vec<String> = Vec::new();
@ -44,31 +39,23 @@ macro_rules! rest_struct {
$(
properties.insert(
stringify!($field_id).to_string(),
ReferenceOr::Item(Box::new(Schema {
schema_data: SchemaData {
nullable: false,
read_only: false,
write_only: false,
deprecated: false,
external_docs: None,
example: None,
title: <$field_ty>::schema_name(),
description: None,
discriminator: None,
default: None
},
schema_kind: <$field_ty>::to_schema()
}))
ReferenceOr::Item(Box::new(<$field_ty>::to_schema().to_schema()))
);
)*
SchemaKind::Type(Type::Object(ObjectType {
let schema = SchemaKind::Type(Type::Object(ObjectType {
properties,
required,
additional_properties: None,
min_properties: None,
max_properties: None
}))
}));
OpenapiSchema {
name: Some(stringify!($struct_name).to_string()),
nullable: false,
schema
}
}
}
}