Skip to content

Commit

Permalink
fix: respect definitions for all when inlining nullable references (#417
Browse files Browse the repository at this point in the history
)
  • Loading branch information
CarstenWickner authored Nov 23, 2023
1 parent ea90e6c commit 1aced59
Show file tree
Hide file tree
Showing 12 changed files with 415 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,14 @@ private Predicate<DefinitionKey> getShouldProduceDefinitionCheck(DefinitionKey m
// global setting: always inline schemas by default
return false;
}
if (definitionKey.equals(mainSchemaKey)) {
if (createDefinitionsForAll || definitionKey.equals(mainSchemaKey)) {
return true;
}
List<ObjectNode> references = this.generationContext.getReferences(definitionKey);
if (considerOnlyDirectReferences.get() && references.isEmpty()) {
return false;
}
return createDefinitionsForAll
|| references.size() > 1
return references.size() > 1
|| (references.size() + this.generationContext.getNullableReferences(definitionKey).size()) > 1;
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
{
"$defs": {
"List(TestCircularClass1)": {
"type": "object",
"properties": {
"get(0)": {
"$ref": "#"
}
}
},
"List(TestCircularClass2)": {
"type": "object",
"properties": {
"get(0)": {
"$ref": "#/$defs/TestCircularClass2"
}
}
},
"TestCircularClass2": {
"type": "object",
"properties": {
"list1": {
"type": ["object", "null"],
"properties": {
"get(0)": {
"$ref": "#"
"anyOf": [
{
"type": "null"
}, {
"$ref": "#/$defs/List(TestCircularClass1)"
}
}
]
}
}
}
},
"type": "object",
"properties": {
"list2": {
"type": ["object", "null"],
"properties": {
"get(0)": {
"$ref": "#/$defs/TestCircularClass2"
"anyOf": [
{
"type": "null"
}, {
"$ref": "#/$defs/List(TestCircularClass2)"
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
{
"$defs": {
"List(TestCircularClass1)": {
"type": "object",
"properties": {
"get(0)": {
"$ref": "#"
}
}
},
"List(TestCircularClass2)": {
"type": "object",
"properties": {
"get(0)": {
"$ref": "#/$defs/TestCircularClass2"
}
}
},
"TestCircularClass2": {
"type": "object",
"properties": {
"list1": {
"type": ["object", "null"],
"properties": {
"get(0)": {
"$ref": "#"
"anyOf": [
{
"type": "null"
}, {
"$ref": "#/$defs/List(TestCircularClass1)"
}
}
]
}
}
}
},
"type": "object",
"properties": {
"list2": {
"type": ["object", "null"],
"properties": {
"get(0)": {
"$ref": "#/$defs/TestCircularClass2"
"anyOf": [
{
"type": "null"
}, {
"$ref": "#/$defs/List(TestCircularClass2)"
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
{
"definitions": {
"List(TestCircularClass1)": {
"type": "object",
"properties": {
"get(0)": {
"$ref": "#"
}
}
},
"List(TestCircularClass2)": {
"type": "object",
"properties": {
"get(0)": {
"$ref": "#/definitions/TestCircularClass2"
}
}
},
"TestCircularClass2": {
"type": "object",
"properties": {
"list1": {
"type": ["object", "null"],
"properties": {
"get(0)": {
"$ref": "#"
"anyOf": [
{
"type": "null"
}, {
"$ref": "#/definitions/List(TestCircularClass1)"
}
}
]
}
}
}
},
"type": "object",
"properties": {
"list2": {
"type": ["object", "null"],
"properties": {
"get(0)": {
"$ref": "#/definitions/TestCircularClass2"
"anyOf": [
{
"type": "null"
}, {
"$ref": "#/definitions/List(TestCircularClass2)"
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
{
"definitions": {
"List(TestCircularClass1)": {
"type": "object",
"properties": {
"get(0)": {
"$ref": "#"
}
}
},
"List(TestCircularClass2)": {
"type": "object",
"properties": {
"get(0)": {
"$ref": "#/definitions/TestCircularClass2"
}
}
},
"TestCircularClass2": {
"type": "object",
"properties": {
"list1": {
"type": ["object", "null"],
"properties": {
"get(0)": {
"$ref": "#"
"anyOf": [
{
"type": "null"
}, {
"$ref": "#/definitions/List(TestCircularClass1)"
}
}
]
}
}
}
},
"type": "object",
"properties": {
"list2": {
"type": ["object", "null"],
"properties": {
"get(0)": {
"$ref": "#/definitions/TestCircularClass2"
"anyOf": [
{
"type": "null"
}, {
"$ref": "#/definitions/List(TestCircularClass2)"
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"TestSuperClass(Boolean)-nullable": {
"type": ["object", "null"],
"TestSuperClass(Boolean)": {
"type": "object",
"properties": {
"genericFieldInSupertype": {
"type": ["boolean", "null"],
Expand All @@ -12,8 +12,17 @@
"title": "TestSuperClass<Boolean>",
"description": "supertype-only description"
},
"TestSuperClass(String)-nullable": {
"type": ["object", "null"],
"TestSuperClass(Boolean)-nullable": {
"anyOf": [
{
"type": "null"
}, {
"$ref": "#/definitions/TestSuperClass(Boolean)"
}
]
},
"TestSuperClass(String)": {
"type": "object",
"properties": {
"genericFieldInSupertype": {
"type": ["string", "null"],
Expand All @@ -22,6 +31,15 @@
},
"title": "TestSuperClass<String>",
"description": "supertype-only description"
},
"TestSuperClass(String)-nullable": {
"anyOf": [
{
"type": "null"
}, {
"$ref": "#/definitions/TestSuperClass(String)"
}
]
}
},
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
},
"title": "TestSubClass3"
},
"TestSuperClass(Boolean)-nullable": {
"type": ["object", "null"],
"TestSuperClass(Boolean)": {
"type": "object",
"properties": {
"genericFieldInSupertype": {
"type": ["boolean", "null"],
Expand All @@ -26,12 +26,26 @@
"title": "TestSuperClass<Boolean>",
"description": "supertype-only description"
},
"TestSuperClass(Boolean)-nullable": {
"anyOf": [
{
"type": "null"
}, {
"$ref": "#/definitions/TestSuperClass(Boolean)"
}
]
},
"TestSuperClass(String)": {
"$ref": "#/definitions/TestSubClass3"
},
"TestSuperClass(String)-nullable": {
"anyOf": [{
"anyOf": [
{
"type": "null"
}, {
"$ref": "#/definitions/TestSubClass3"
}]
"$ref": "#/definitions/TestSuperClass(String)"
}
]
}
},
"type": "object",
Expand All @@ -40,15 +54,17 @@
"$ref": "#/definitions/TestSuperClass(Boolean)-nullable"
},
"numberOrStringObjectField": {
"anyOf": [{
"anyOf": [
{
"type": "null"
}, {
"type": "number",
"title": "Number"
}, {
"type": "string",
"title": "String"
}]
}
]
},
"stringSupertypeField": {
"$ref": "#/definitions/TestSuperClass(String)-nullable"
Expand Down
Loading

0 comments on commit 1aced59

Please sign in to comment.