Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,16 @@ private static JsonNode handleObject(Schema schema, Map<String, Schema> definiti

if (schema.getAllOf() != null && !schema.getAllOf().isEmpty()) {
List<Schema> schemas = schema.getAllOf();
// Open: Handle properties of all schemas, not only the first one
return buildSchemaInternal(schemas.get(0), definitions, visited);

ObjectNode combinedNode = objectMapper.createObjectNode();
schemas.stream()
.map(s -> buildSchemaInternal(s, definitions, visited))
.filter(JsonNode::isObject)
.map(JsonNode::fields)
.forEach(fields ->
fields.forEachRemaining(entry -> combinedNode.set(entry.getKey(), entry.getValue())));

return combinedNode;
}
if (schema.getAnyOf() != null && !schema.getAnyOf().isEmpty()) {
List<Schema> schemas = schema.getAnyOf();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,38 @@ void object_with_anyOf() {
assertThat(actual).isEqualTo("{\"anyOfField\":\"string\"}");
}

@Test
void object_with_oneOf() {
ObjectSchema compositeSchema = new ObjectSchema();

Schema propertySchema = new ObjectSchema();
propertySchema.setOneOf(List.of(new StringSchema(), new NumberSchema()));
compositeSchema.addProperty("oneOfField", propertySchema);

String actual = ExampleJsonGenerator.buildSchema(compositeSchema, Map.of("Nested", propertySchema));

assertThat(actual).isEqualTo("{\"oneOfField\":\"string\"}");
}

@Test
void object_with_allOf() {
ObjectSchema compositeSchema = new ObjectSchema();

ObjectSchema schema1 = new ObjectSchema();
schema1.setProperties(Map.of("field1", new StringSchema()));
ObjectSchema schema2 = new ObjectSchema();
schema2.setProperties(Map.of("field2", new NumberSchema()));
StringSchema skippedSchemaSinceObjectIsRequired = new StringSchema();

Schema propertySchema = new ObjectSchema();
propertySchema.setAllOf(List.of(schema1, schema2, skippedSchemaSinceObjectIsRequired));
compositeSchema.addProperty("allOfField", propertySchema);

String actual = ExampleJsonGenerator.buildSchema(compositeSchema, Map.of("Nested", propertySchema));

assertThat(actual).isEqualTo("{\"allOfField\":{\"field1\":\"string\",\"field2\":1.1}}");
}

@Test
void schema_with_problematic_object_toString_example() {
ObjectSchema schema = new ObjectSchema();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"type" : "object",
"examples" : [ {
"firstOne" : "string",
"secondOne" : "string"
"secondOne" : "string",
"firstTwo" : 0,
"secondTwo" : true
} ],
"allOf" : [ {
"$ref" : "#/components/schemas/ImplementationOne"
Expand Down Expand Up @@ -85,7 +87,9 @@
"examples" : [ {
"allOf" : {
"firstOne" : "string",
"secondOne" : "string"
"secondOne" : "string",
"firstTwo" : 0,
"secondTwo" : true
},
"anyOf" : {
"firstOne" : "string",
Expand Down