From e7f0ea8f95b11734725fc5351b1df6aa0868484e Mon Sep 17 00:00:00 2001 From: Jochen Berger Date: Tue, 10 Dec 2024 09:09:01 +0100 Subject: [PATCH] chore: add a test for #499 --- .../generator/impl/SchemaCleanUpUtilsTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/impl/SchemaCleanUpUtilsTest.java b/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/impl/SchemaCleanUpUtilsTest.java index 5d7797db..2b64aef5 100644 --- a/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/impl/SchemaCleanUpUtilsTest.java +++ b/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/impl/SchemaCleanUpUtilsTest.java @@ -25,9 +25,11 @@ import com.github.victools.jsonschema.generator.SchemaGeneratorConfigPart; import com.github.victools.jsonschema.generator.SchemaVersion; import java.util.Collections; +import java.util.List; import java.util.stream.Stream; import org.json.JSONArray; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -116,4 +118,20 @@ public void testSetStrictTypeInfo(String schemaInput, boolean considerNullType, String schemaAsString = schema.toString(); JSONAssert.assertEquals('\n' + schemaAsString +'\n', expectedOutput, schemaAsString, JSONCompareMode.STRICT); } + + @Test + public void testAllOfCleanup() throws Exception { + SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder( + SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON); + SchemaCleanUpUtils utilsInstance = new SchemaCleanUpUtils(configBuilder.build()); + + JsonNode schema = configBuilder.getObjectMapper().readTree( + "{\"allOf\":[{\"type\":\"object\",\"properties\":{\"foo\":{\"type\":\"string\"}},\"required\":[\"foo\"]},{\"type\":\"object\",\"properties\":{\"foo\":{\"type\":\"string\"}},\"required\":[\"foo\"]}]}"); + utilsInstance.reduceAllOfNodes(List.of((ObjectNode) schema)); + + String schemaAsString = schema.toString(); + JSONAssert.assertEquals('\n' + schemaAsString + '\n', + "{\"type\":\"object\",\"properties\":{\"foo\":{\"type\":\"string\"}},\"required\":[\"foo\"]}", + schemaAsString, JSONCompareMode.STRICT); + } }