Skip to content

Commit

Permalink
Add test for draft 2020-12
Browse files Browse the repository at this point in the history
  • Loading branch information
GREsau committed May 19, 2024
1 parent 73b7efd commit 46371d3
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 3 deletions.
22 changes: 21 additions & 1 deletion schemars/tests/expected/schema_settings-2019_09.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,32 @@
"type": "null"
}
]
},
"tuples": {
"type": "array",
"items": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint8",
"minimum": 0
},
{
"type": "integer",
"format": "int64"
}
],
"minItems": 2,
"maxItems": 2
}
}
},
"required": [
"int",
"values",
"value"
"value",
"tuples"
],
"$defs": {
"Inner": {
Expand Down
83 changes: 83 additions & 0 deletions schemars/tests/expected/schema_settings-2020_12.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Outer",
"type": "object",
"properties": {
"int": {
"type": "integer",
"format": "int32",
"examples": [
8,
null
]
},
"values": {
"type": "object",
"additionalProperties": true
},
"value": true,
"inner": {
"anyOf": [
{
"$ref": "#/$defs/Inner"
},
{
"type": "null"
}
]
},
"tuples": {
"type": "array",
"items": {
"type": "array",
"prefixItems": [
{
"type": "integer",
"format": "uint8",
"minimum": 0
},
{
"type": "integer",
"format": "int64"
}
],
"minItems": 2,
"maxItems": 2
}
}
},
"required": [
"int",
"values",
"value",
"tuples"
],
"$defs": {
"Inner": {
"oneOf": [
{
"type": "string",
"enum": [
"UndocumentedUnit1",
"UndocumentedUnit2"
]
},
{
"description": "This is a documented unit variant",
"type": "string",
"const": "DocumentedUnit"
},
{
"type": "object",
"properties": {
"ValueNewType": true
},
"required": [
"ValueNewType"
],
"additionalProperties": false
}
]
}
}
}
22 changes: 21 additions & 1 deletion schemars/tests/expected/schema_settings-openapi3.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,32 @@
"$ref": "#/components/schemas/Inner"
}
]
},
"tuples": {
"type": "array",
"items": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint8",
"minimum": 0
},
{
"type": "integer",
"format": "int64"
}
],
"minItems": 2,
"maxItems": 2
}
}
},
"required": [
"int",
"values",
"value"
"value",
"tuples"
],
"components": {
"schemas": {
Expand Down
22 changes: 21 additions & 1 deletion schemars/tests/expected/schema_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,32 @@
"type": "null"
}
]
},
"tuples": {
"type": "array",
"items": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint8",
"minimum": 0
},
{
"type": "integer",
"format": "int64"
}
],
"minItems": 2,
"maxItems": 2
}
}
},
"required": [
"int",
"values",
"value"
"value",
"tuples"
],
"definitions": {
"Inner": {
Expand Down
6 changes: 6 additions & 0 deletions schemars/tests/schema_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct Outer {
pub values: BTreeMap<&'static str, Value>,
pub value: Value,
pub inner: Option<Inner>,
pub tuples: Vec<(u8, i64)>,
}

#[derive(JsonSchema)]
Expand Down Expand Up @@ -39,6 +40,11 @@ fn schema_matches_2019_09() -> TestResult {
test_generated_schema::<Outer>("schema_settings-2019_09", SchemaSettings::draft2019_09())
}

#[test]
fn schema_matches_2020_12() -> TestResult {
test_generated_schema::<Outer>("schema_settings-2020_12", SchemaSettings::draft2020_12())
}

#[test]
fn schema_matches_openapi3() -> TestResult {
test_generated_schema::<Outer>("schema_settings-openapi3", SchemaSettings::openapi3())
Expand Down

0 comments on commit 46371d3

Please sign in to comment.