Derive JsonSchema_repr (#76)

This commit is contained in:
Graham Esau 2021-03-25 22:36:28 +00:00 committed by GitHub
parent 7de2b2276f
commit 11d95b79e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 225 additions and 18 deletions

View 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")
}

View 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
]
}

View file

@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Enum",
"type": "integer",
"enum": [
0,
1,
5,
6,
3
]
}

View file

@ -0,0 +1,8 @@
use schemars::JsonSchema_repr;
#[derive(JsonSchema_repr)]
pub enum Enum {
Unit,
}
fn main() {}

View 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)

View file

@ -0,0 +1,10 @@
use schemars::JsonSchema_repr;
#[derive(JsonSchema_repr)]
#[repr(u8)]
pub enum Enum {
Unit,
EmptyTuple(),
}
fn main() {}

View file

@ -0,0 +1,5 @@
error: JsonSchema_repr: must be a unit variant
--> $DIR/repr_non_unit_variant.rs:7:5
|
7 | EmptyTuple(),
| ^^^^^^^^^^