Rename MakeSchema to JsonSchema
This commit is contained in:
parent
58e169b866
commit
870dc3a2de
16 changed files with 117 additions and 130 deletions
|
@ -1,8 +1,8 @@
|
|||
[package]
|
||||
name = "schemars_derive"
|
||||
description = "Macros for #[derive(MakeSchema)], for use with schemars"
|
||||
description = "Macros for #[derive(JsonSchema)], for use with schemars"
|
||||
repository = "https://github.com/GREsau/schemars"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
authors = ["Graham Esau <gesau@hotmail.co.uk>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
|
|
|
@ -14,8 +14,8 @@ use serde_derive_internals::{Ctxt, Derive};
|
|||
use syn::spanned::Spanned;
|
||||
use syn::DeriveInput;
|
||||
|
||||
#[proc_macro_derive(MakeSchema, attributes(schemars, serde))]
|
||||
pub fn derive_make_schema(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
#[proc_macro_derive(JsonSchema, attributes(schemars, serde))]
|
||||
pub fn derive_json_schema(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
let mut input = parse_macro_input!(input as DeriveInput);
|
||||
|
||||
preprocess::add_trait_bounds(&mut input.generics);
|
||||
|
@ -64,12 +64,12 @@ pub fn derive_make_schema(input: proc_macro::TokenStream) -> proc_macro::TokenSt
|
|||
|
||||
let impl_block = quote! {
|
||||
#[automatically_derived]
|
||||
impl #impl_generics schemars::MakeSchema for #type_name #ty_generics #where_clause {
|
||||
impl #impl_generics schemars::JsonSchema for #type_name #ty_generics #where_clause {
|
||||
fn schema_name() -> String {
|
||||
#schema_name
|
||||
}
|
||||
|
||||
fn make_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::Result {
|
||||
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::Result {
|
||||
Ok(#schema)
|
||||
}
|
||||
};
|
||||
|
@ -256,7 +256,7 @@ fn schema_for_struct(fields: &[Field], cattrs: &attr::Container) -> TokenStream
|
|||
let flattens = flat.iter().map(|f| {
|
||||
let ty = f.ty;
|
||||
quote_spanned! {f.original.span()=>
|
||||
.flatten(<#ty>::make_schema(gen)?)?
|
||||
.flatten(<#ty>::json_schema(gen)?)?
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use syn::{Attribute, Data, DeriveInput, Field, GenericParam, Generics, Ident, Va
|
|||
pub fn add_trait_bounds(generics: &mut Generics) {
|
||||
for param in &mut generics.params {
|
||||
if let GenericParam::Type(ref mut type_param) = *param {
|
||||
type_param.bounds.push(parse_quote!(schemars::MakeSchema));
|
||||
type_param.bounds.push(parse_quote!(schemars::JsonSchema));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue