1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-05-09 08:00:41 +00:00

copy OpenapiType implementations and fix codegen reference

This commit is contained in:
Dominic 2021-03-08 16:33:38 +01:00
parent d9c7f4135f
commit 667009bd22
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
7 changed files with 388 additions and 17 deletions

View file

@ -29,7 +29,10 @@ fn gen_struct(fields: Vec<(LitStr, Type)>) -> syn::Result<TokenStream> {
#({
const FIELD_NAME: &::core::primitive::str = #field_name;
let mut field_schema = <#field_ty as ::openapi_type::OpenapiType>::schema();
add_dependencies(&mut field_schema.dependencies);
::openapi_type::private::add_dependencies(
&mut dependencies,
&mut field_schema.dependencies
);
// fields in OpenAPI are nullable by default
match field_schema.nullable {

View file

@ -59,22 +59,7 @@ fn expand_openapi_type(mut input: DeriveInput) -> syn::Result<TokenStream2> {
impl #impl_generics ::openapi_type::OpenapiType for #ident #ty_generics #where_clause {
fn schema() -> ::openapi_type::OpenapiSchema {
// prepare the dependencies
let mut dependencies = <::openapi_type::indexmap::IndexMap<
::std::string::String,
::openapi_type::OpenapiSchema
>>::new();
// this function can be used to include dependencies of dependencies
let add_dependencies = |deps: &mut ::openapi_type::indexmap::IndexMap<
::std::string::String,
::openapi_type::OpenapiSchema
>| {
while let ::std::option::Option::Some((dep_name, dep_schema)) = deps.pop() {
if !dependencies.contains_key(&dep_name) {
dependencies.insert(dep_name, dep_schema);
}
}
};
let mut dependencies = ::openapi_type::private::Dependencies::new();
// create the schema
let schema = #schema_code;