Exclude skipped fields/variants from json schema
This commit is contained in:
parent
709ba7b62e
commit
5de6bcfdef
5 changed files with 137 additions and 11 deletions
23
schemars/tests/expected/skip_enum_variants.json
Normal file
23
schemars/tests/expected/skip_enum_variants.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "MyEnum",
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"Included2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Included1": {
|
||||
"type": "number",
|
||||
"format": "float"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"Included1"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
18
schemars/tests/expected/skip_struct_fields.json
Normal file
18
schemars/tests/expected/skip_struct_fields.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "MyStruct",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"included1": {
|
||||
"type": "number",
|
||||
"format": "float"
|
||||
},
|
||||
"included2": {
|
||||
"type": "null"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"included1",
|
||||
"included2"
|
||||
]
|
||||
}
|
16
schemars/tests/expected/skip_tuple_fields.json
Normal file
16
schemars/tests/expected/skip_tuple_fields.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "TupleStruct",
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"type": "number",
|
||||
"format": "float"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"maxItems": 2,
|
||||
"minItems": 2
|
||||
}
|
58
schemars/tests/skip.rs
Normal file
58
schemars/tests/skip.rs
Normal file
|
@ -0,0 +1,58 @@
|
|||
mod util;
|
||||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
struct MyStruct {
|
||||
#[schemars(skip)]
|
||||
skipped1: i32,
|
||||
#[serde(skip)]
|
||||
skipped2: bool,
|
||||
#[serde(skip_deserializing)]
|
||||
skipped3: String,
|
||||
#[serde(skip_serializing)]
|
||||
included1: f32,
|
||||
included2: (),
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn skip_struct_fields() -> TestResult {
|
||||
test_default_generated_schema::<MyStruct>("skip_struct_fields")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
struct TupleStruct (
|
||||
#[schemars(skip)]
|
||||
i32,
|
||||
#[serde(skip)]
|
||||
bool,
|
||||
#[serde(skip_deserializing)]
|
||||
String,
|
||||
#[serde(skip_serializing)]
|
||||
f32,
|
||||
(),
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn skip_tuple_fields() -> TestResult {
|
||||
test_default_generated_schema::<TupleStruct>("skip_tuple_fields")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub enum MyEnum {
|
||||
#[schemars(skip)]
|
||||
Skipped1(i32),
|
||||
#[serde(skip)]
|
||||
Skipped2,
|
||||
#[serde(skip_deserializing)]
|
||||
Skipped3,
|
||||
#[serde(skip_serializing)]
|
||||
Included1(f32),
|
||||
Included2,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn skip_enum_variants() -> TestResult {
|
||||
test_default_generated_schema::<MyEnum>("skip_enum_variants")
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue