Check for #[deprecated] attributes
This commit is contained in:
parent
bb8c93ddc1
commit
509a1c3b7b
7 changed files with 124 additions and 7 deletions
37
schemars/tests/deprecated.rs
Normal file
37
schemars/tests/deprecated.rs
Normal 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")
|
||||
}
|
40
schemars/tests/expected/deprecated-enum.json
Normal file
40
schemars/tests/expected/deprecated-enum.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
20
schemars/tests/expected/deprecated-struct.json
Normal file
20
schemars/tests/expected/deprecated-struct.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue