-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more tests for different schema settings
This is mainly to keep this coverage around in v1, where the `schema_for_schema` tests are no longer viable
- Loading branch information
Showing
4 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2019-09/schema", | ||
"title": "Outer", | ||
"type": "object", | ||
"required": [ | ||
"int", | ||
"value", | ||
"values" | ||
], | ||
"properties": { | ||
"int": { | ||
"examples": [ | ||
8, | ||
null | ||
], | ||
"type": "integer", | ||
"format": "int32" | ||
}, | ||
"values": { | ||
"type": "object", | ||
"additionalProperties": true | ||
}, | ||
"value": true, | ||
"inner": { | ||
"anyOf": [ | ||
{ | ||
"$ref": "#/definitions/Inner" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
} | ||
}, | ||
"definitions": { | ||
"Inner": { | ||
"oneOf": [ | ||
{ | ||
"type": "string", | ||
"enum": [ | ||
"UndocumentedUnit1", | ||
"UndocumentedUnit2" | ||
] | ||
}, | ||
{ | ||
"description": "This is a documented unit variant", | ||
"type": "string", | ||
"enum": [ | ||
"DocumentedUnit" | ||
] | ||
}, | ||
{ | ||
"type": "object", | ||
"required": [ | ||
"ValueNewType" | ||
], | ||
"properties": { | ||
"ValueNewType": true | ||
}, | ||
"additionalProperties": false | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema", | ||
"title": "Outer", | ||
"type": "object", | ||
"required": [ | ||
"int", | ||
"value", | ||
"values" | ||
], | ||
"properties": { | ||
"int": { | ||
"type": "integer", | ||
"format": "int32", | ||
"example": 8 | ||
}, | ||
"values": { | ||
"type": "object", | ||
"additionalProperties": true | ||
}, | ||
"value": {}, | ||
"inner": { | ||
"allOf": [ | ||
{ | ||
"$ref": "#/components/schemas/Inner" | ||
} | ||
], | ||
"nullable": true | ||
} | ||
}, | ||
"definitions": { | ||
"Inner": { | ||
"oneOf": [ | ||
{ | ||
"type": "string", | ||
"enum": [ | ||
"UndocumentedUnit1", | ||
"UndocumentedUnit2" | ||
] | ||
}, | ||
{ | ||
"description": "This is a documented unit variant", | ||
"type": "string", | ||
"enum": [ | ||
"DocumentedUnit" | ||
] | ||
}, | ||
{ | ||
"type": "object", | ||
"required": [ | ||
"ValueNewType" | ||
], | ||
"properties": { | ||
"ValueNewType": {} | ||
}, | ||
"additionalProperties": false | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "Outer", | ||
"type": "object", | ||
"required": [ | ||
"int", | ||
"value", | ||
"values" | ||
], | ||
"properties": { | ||
"int": { | ||
"examples": [ | ||
8, | ||
null | ||
], | ||
"type": "integer", | ||
"format": "int32" | ||
}, | ||
"values": { | ||
"type": "object", | ||
"additionalProperties": true | ||
}, | ||
"value": true, | ||
"inner": { | ||
"anyOf": [ | ||
{ | ||
"$ref": "#/definitions/Inner" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
} | ||
}, | ||
"definitions": { | ||
"Inner": { | ||
"oneOf": [ | ||
{ | ||
"type": "string", | ||
"enum": [ | ||
"UndocumentedUnit1", | ||
"UndocumentedUnit2" | ||
] | ||
}, | ||
{ | ||
"description": "This is a documented unit variant", | ||
"type": "string", | ||
"enum": [ | ||
"DocumentedUnit" | ||
] | ||
}, | ||
{ | ||
"type": "object", | ||
"required": [ | ||
"ValueNewType" | ||
], | ||
"properties": { | ||
"ValueNewType": true | ||
}, | ||
"additionalProperties": false | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
mod util; | ||
use schemars::gen::SchemaSettings; | ||
use schemars::JsonSchema; | ||
use serde_json::Value; | ||
use std::collections::BTreeMap; | ||
use util::*; | ||
|
||
#[derive(JsonSchema)] | ||
pub struct Outer { | ||
#[schemars(example = "eight", example = "null")] | ||
pub int: i32, | ||
pub values: BTreeMap<&'static str, Value>, | ||
pub value: Value, | ||
pub inner: Option<Inner>, | ||
} | ||
|
||
#[derive(JsonSchema)] | ||
pub enum Inner { | ||
UndocumentedUnit1, | ||
UndocumentedUnit2, | ||
/// This is a documented unit variant | ||
DocumentedUnit, | ||
ValueNewType(Value), | ||
} | ||
|
||
fn eight() -> i32 { | ||
8 | ||
} | ||
|
||
fn null() {} | ||
|
||
#[test] | ||
fn schema_matches_draft07() -> TestResult { | ||
test_generated_schema::<Outer>("schema_settings", SchemaSettings::draft07()) | ||
} | ||
|
||
#[test] | ||
fn schema_matches_2019_09() -> TestResult { | ||
test_generated_schema::<Outer>("schema_settings-2019_09", SchemaSettings::draft2019_09()) | ||
} | ||
|
||
#[test] | ||
fn schema_matches_openapi3() -> TestResult { | ||
test_generated_schema::<Outer>("schema_settings-openapi3", SchemaSettings::openapi3()) | ||
} |