Merge branch 'master' into v1
This commit is contained in:
commit
efff7e2606
4 changed files with 235 additions and 0 deletions
65
schemars/tests/expected/schema_settings-2019_09.json
Normal file
65
schemars/tests/expected/schema_settings-2019_09.json
Normal file
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
60
schemars/tests/expected/schema_settings-openapi3.json
Normal file
60
schemars/tests/expected/schema_settings-openapi3.json
Normal file
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
65
schemars/tests/expected/schema_settings.json
Normal file
65
schemars/tests/expected/schema_settings.json
Normal file
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
45
schemars/tests/schema_settings.rs
Normal file
45
schemars/tests/schema_settings.rs
Normal file
|
@ -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())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue