Check for #[deprecated] attributes

This commit is contained in:
Graham Esau 2020-05-16 16:44:44 +01:00
parent bb8c93ddc1
commit 509a1c3b7b
7 changed files with 124 additions and 7 deletions

View file

@ -0,0 +1,37 @@
#![allow(deprecated)]
mod util;
use schemars::JsonSchema;
use util::*;
#[derive(Debug, JsonSchema)]
#[deprecated]
pub struct DeprecatedStruct {
foo: i32,
#[deprecated]
deprecated_field: bool,
}
#[test]
fn deprecated_struct() -> TestResult {
test_default_generated_schema::<DeprecatedStruct>("deprecated-struct")
}
#[derive(Debug, JsonSchema)]
#[deprecated]
pub enum DeprecatedEnum {
Unit,
#[deprecated]
DeprecatedUnitVariant,
#[deprecated]
DeprecatedStructVariant {
foo: i32,
#[deprecated]
deprecated_field: bool,
},
}
#[test]
fn deprecated_enum() -> TestResult {
test_default_generated_schema::<DeprecatedEnum>("deprecated-enum")
}

View file

@ -0,0 +1,40 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "DeprecatedEnum",
"deprecated": true,
"anyOf": [
{
"type": "string",
"enum": [
"Unit",
"DeprecatedUnitVariant"
]
},
{
"deprecated": true,
"type": "object",
"required": [
"DeprecatedStructVariant"
],
"properties": {
"DeprecatedStructVariant": {
"type": "object",
"required": [
"deprecated_field",
"foo"
],
"properties": {
"deprecated_field": {
"deprecated": true,
"type": "boolean"
},
"foo": {
"type": "integer",
"format": "int32"
}
}
}
}
}
]
}

View file

@ -0,0 +1,20 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "DeprecatedStruct",
"deprecated": true,
"type": "object",
"required": [
"deprecated_field",
"foo"
],
"properties": {
"deprecated_field": {
"deprecated": true,
"type": "boolean"
},
"foo": {
"type": "integer",
"format": "int32"
}
}
}