Prevent stack overflow when using inline_subschemas

This commit is contained in:
Graham Esau 2021-03-21 20:09:32 +00:00
parent d85eec3b7a
commit 1017506ce6
4 changed files with 170 additions and 31 deletions

View file

@ -0,0 +1,95 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "RecursiveOuter",
"type": "object",
"properties": {
"direct": {
"anyOf": [
{
"$ref": "#/definitions/RecursiveOuter"
},
{
"type": "null"
}
]
},
"indirect": {
"type": [
"object",
"null"
],
"required": [
"recursive"
],
"properties": {
"recursive": {
"type": "object",
"properties": {
"direct": {
"anyOf": [
{
"$ref": "#/definitions/RecursiveOuter"
},
{
"type": "null"
}
]
},
"indirect": {
"anyOf": [
{
"$ref": "#/definitions/RecursiveInner"
},
{
"type": "null"
}
]
}
}
}
}
}
},
"definitions": {
"RecursiveOuter": {
"type": "object",
"properties": {
"direct": {
"anyOf": [
{
"$ref": "#/definitions/RecursiveOuter"
},
{
"type": "null"
}
]
},
"indirect": {
"type": [
"object",
"null"
],
"required": [
"recursive"
],
"properties": {
"recursive": {
"$ref": "#/definitions/RecursiveOuter"
}
}
}
}
},
"RecursiveInner": {
"type": "object",
"required": [
"recursive"
],
"properties": {
"recursive": {
"$ref": "#/definitions/RecursiveOuter"
}
}
}
}
}

View file

@ -1,23 +1,23 @@
{
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MyJob",
"type": "object",
"required": [
"spec"
],
"properties": {
"spec": {
"properties": {
"replicas": {
"format": "uint32",
"minimum": 0,
"type": "integer"
}
},
"type": "object",
"required": [
"replicas"
],
"type": "object"
"properties": {
"replicas": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
}
}
},
"required": [
"spec"
],
"title": "MyJob",
"type": "object"
}
}

View file

@ -15,7 +15,25 @@ pub struct MyJobSpec {
#[test]
fn struct_normal() -> TestResult {
let mut settings = SchemaSettings::openapi3();
let mut settings = SchemaSettings::default();
settings.inline_subschemas = true;
test_generated_schema::<MyJob>("inline-subschemas", settings)
}
#[derive(Debug, JsonSchema)]
pub struct RecursiveOuter {
pub direct: Option<Box<RecursiveOuter>>,
pub indirect: Option<Box<RecursiveInner>>,
}
#[derive(Debug, JsonSchema)]
pub struct RecursiveInner {
pub recursive: RecursiveOuter,
}
#[test]
fn struct_recursive() -> TestResult {
let mut settings = SchemaSettings::default();
settings.inline_subschemas = true;
test_generated_schema::<RecursiveOuter>("inline-subschemas-recursive", settings)
}