Derive JsonSchema_repr (#76)
This commit is contained in:
parent
7de2b2276f
commit
11d95b79e5
16 changed files with 225 additions and 18 deletions
35
schemars/tests/enum_repr.rs
Normal file
35
schemars/tests/enum_repr.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
mod util;
|
||||
use schemars::JsonSchema_repr;
|
||||
use util::*;
|
||||
|
||||
#[derive(JsonSchema_repr)]
|
||||
#[repr(u8)]
|
||||
pub enum Enum {
|
||||
Zero,
|
||||
One,
|
||||
Five = 5,
|
||||
Six,
|
||||
Three = 3,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enum_repr() -> TestResult {
|
||||
test_default_generated_schema::<Enum>("enum-repr")
|
||||
}
|
||||
|
||||
#[derive(JsonSchema_repr)]
|
||||
#[repr(i64)]
|
||||
#[serde(rename = "Renamed")]
|
||||
/// Description from comment
|
||||
pub enum EnumWithAttrs {
|
||||
Zero,
|
||||
One,
|
||||
Five = 5,
|
||||
Six,
|
||||
Three = 3,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enum_repr_with_attrs() -> TestResult {
|
||||
test_default_generated_schema::<EnumWithAttrs>("enum-repr-with-attrs")
|
||||
}
|
13
schemars/tests/expected/enum-repr-with-attrs.json
Normal file
13
schemars/tests/expected/enum-repr-with-attrs.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Renamed",
|
||||
"description": "Description from comment",
|
||||
"type": "integer",
|
||||
"enum": [
|
||||
0,
|
||||
1,
|
||||
5,
|
||||
6,
|
||||
3
|
||||
]
|
||||
}
|
12
schemars/tests/expected/enum-repr.json
Normal file
12
schemars/tests/expected/enum-repr.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Enum",
|
||||
"type": "integer",
|
||||
"enum": [
|
||||
0,
|
||||
1,
|
||||
5,
|
||||
6,
|
||||
3
|
||||
]
|
||||
}
|
8
schemars/tests/ui/repr_missing.rs
Normal file
8
schemars/tests/ui/repr_missing.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
use schemars::JsonSchema_repr;
|
||||
|
||||
#[derive(JsonSchema_repr)]
|
||||
pub enum Enum {
|
||||
Unit,
|
||||
}
|
||||
|
||||
fn main() {}
|
7
schemars/tests/ui/repr_missing.stderr
Normal file
7
schemars/tests/ui/repr_missing.stderr
Normal file
|
@ -0,0 +1,7 @@
|
|||
error: JsonSchema_repr: missing #[repr(...)] attribute
|
||||
--> $DIR/repr_missing.rs:3:10
|
||||
|
|
||||
3 | #[derive(JsonSchema_repr)]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
10
schemars/tests/ui/repr_non_unit_variant.rs
Normal file
10
schemars/tests/ui/repr_non_unit_variant.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
use schemars::JsonSchema_repr;
|
||||
|
||||
#[derive(JsonSchema_repr)]
|
||||
#[repr(u8)]
|
||||
pub enum Enum {
|
||||
Unit,
|
||||
EmptyTuple(),
|
||||
}
|
||||
|
||||
fn main() {}
|
5
schemars/tests/ui/repr_non_unit_variant.stderr
Normal file
5
schemars/tests/ui/repr_non_unit_variant.stderr
Normal file
|
@ -0,0 +1,5 @@
|
|||
error: JsonSchema_repr: must be a unit variant
|
||||
--> $DIR/repr_non_unit_variant.rs:7:5
|
||||
|
|
||||
7 | EmptyTuple(),
|
||||
| ^^^^^^^^^^
|
Loading…
Add table
Add a link
Reference in a new issue