More fixes for deriving JsonSchema inside macro
This commit is contained in:
parent
4d3400152e
commit
ebd7ff32ce
3 changed files with 77 additions and 5 deletions
23
schemars/tests/expected/macro_built_enum.json
Normal file
23
schemars/tests/expected/macro_built_enum.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "OuterEnum",
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"required": [
|
||||
"InnerStruct"
|
||||
],
|
||||
"properties": {
|
||||
"InnerStruct": {
|
||||
"$ref": "#/definitions/InnerStruct"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
],
|
||||
"definitions": {
|
||||
"InnerStruct": {
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,3 +20,48 @@ build_struct!(A { v: i32 });
|
|||
fn macro_built_struct() -> TestResult {
|
||||
test_default_generated_schema::<A>("macro_built_struct")
|
||||
}
|
||||
|
||||
macro_rules! build_enum {
|
||||
(
|
||||
$(#[$outer_derive:meta])*
|
||||
$outer:ident {
|
||||
$($(#[$inner_derive:meta])*
|
||||
$inner:ident {
|
||||
$( $(#[$field_attribute:meta])*
|
||||
$field:ident : $ty:ty),*
|
||||
})*
|
||||
}
|
||||
) => {
|
||||
|
||||
$(
|
||||
$(#[$inner_derive])*
|
||||
pub struct $inner {
|
||||
$(
|
||||
$(#[$field_attribute])*
|
||||
pub $field: $ty
|
||||
),*
|
||||
}
|
||||
)*
|
||||
|
||||
$(#[$outer_derive])*
|
||||
pub enum $outer {
|
||||
$(
|
||||
$inner($inner)
|
||||
),*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
build_enum!(
|
||||
#[derive(Debug, JsonSchema)]
|
||||
OuterEnum {
|
||||
#[derive(Debug, JsonSchema)]
|
||||
InnerStruct {}
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn macro_built_enum() -> TestResult {
|
||||
test_default_generated_schema::<OuterEnum>("macro_built_enum")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue