From ca6eda4e43268aa87de6c3013ca08ece63eababd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tibor=20Zim=C3=A1nyi?= Date: Wed, 7 Feb 2024 16:30:30 +0100 Subject: [PATCH 1/4] Generate reproducible dmndefinitions.json. --- .../dmn/openapi/impl/DMNOASGeneratorImpl.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java b/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java index bd006c1dfaf..6d787ae1c49 100644 --- a/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java +++ b/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java @@ -18,16 +18,6 @@ */ package org.kie.dmn.openapi.impl; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.stream.Collectors; - import com.fasterxml.jackson.databind.node.ObjectNode; import io.smallrye.openapi.runtime.io.JsonUtil; import io.smallrye.openapi.runtime.io.schema.SchemaWriter; @@ -44,6 +34,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.stream.Collectors; + public class DMNOASGeneratorImpl implements DMNOASGenerator { private static final Logger LOG = LoggerFactory.getLogger(DMNOASGeneratorImpl.class); private final List dmnModels; @@ -81,7 +82,8 @@ private void prepareSerializaton() { ObjectNode tree = JsonUtil.objectNode(); ObjectNode definitions = JsonUtil.objectNode(); tree.set("definitions", definitions); - for (Entry kv : schemas.entrySet()) { + final List> sortedEntries = schemas.entrySet().stream().sorted(Map.Entry.comparingByKey(Comparator.comparing(DMNType::getName))).toList(); + for (Entry kv : sortedEntries) { SchemaWriter.writeSchema(definitions, kv.getValue(), namingPolicy.getName(kv.getKey())); } jsonSchema = tree; @@ -191,5 +193,4 @@ private void visitForIndexing(DMNType idnType) { } } } - } From 1e39be6a83eccaf62cfac7d189322916d70d42ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tibor=20Zim=C3=A1nyi?= Date: Wed, 7 Feb 2024 17:18:33 +0100 Subject: [PATCH 2/4] Replace HashMap with TreeMap. --- .../java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java b/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java index 6d787ae1c49..bb1bb4bd88d 100644 --- a/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java +++ b/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java @@ -37,12 +37,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.TreeMap; import java.util.stream.Collectors; public class DMNOASGeneratorImpl implements DMNOASGenerator { @@ -52,7 +52,7 @@ public class DMNOASGeneratorImpl implements DMNOASGenerator { private final Set typesIndex = new HashSet<>(); private final String refPrefix; private NamingPolicy namingPolicy; - private final Map schemas = new HashMap<>(); + private final Map schemas = new TreeMap<>(Comparator.comparing(DMNType::getName)); private ObjectNode jsonSchema; public DMNOASGeneratorImpl(Collection models, String refPrefix) { @@ -82,8 +82,7 @@ private void prepareSerializaton() { ObjectNode tree = JsonUtil.objectNode(); ObjectNode definitions = JsonUtil.objectNode(); tree.set("definitions", definitions); - final List> sortedEntries = schemas.entrySet().stream().sorted(Map.Entry.comparingByKey(Comparator.comparing(DMNType::getName))).toList(); - for (Entry kv : sortedEntries) { + for (Entry kv : schemas.entrySet()) { SchemaWriter.writeSchema(definitions, kv.getValue(), namingPolicy.getName(kv.getKey())); } jsonSchema = tree; From 4f6029e25a1b572b27d7ff1fc5ae512a3e22fe89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tibor=20Zim=C3=A1nyi?= Date: Thu, 8 Feb 2024 09:08:04 +0100 Subject: [PATCH 3/4] Revert TreeMap as that breaks some transitively related code. --- .../java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java b/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java index bb1bb4bd88d..6d787ae1c49 100644 --- a/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java +++ b/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java @@ -37,12 +37,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import java.util.TreeMap; import java.util.stream.Collectors; public class DMNOASGeneratorImpl implements DMNOASGenerator { @@ -52,7 +52,7 @@ public class DMNOASGeneratorImpl implements DMNOASGenerator { private final Set typesIndex = new HashSet<>(); private final String refPrefix; private NamingPolicy namingPolicy; - private final Map schemas = new TreeMap<>(Comparator.comparing(DMNType::getName)); + private final Map schemas = new HashMap<>(); private ObjectNode jsonSchema; public DMNOASGeneratorImpl(Collection models, String refPrefix) { @@ -82,7 +82,8 @@ private void prepareSerializaton() { ObjectNode tree = JsonUtil.objectNode(); ObjectNode definitions = JsonUtil.objectNode(); tree.set("definitions", definitions); - for (Entry kv : schemas.entrySet()) { + final List> sortedEntries = schemas.entrySet().stream().sorted(Map.Entry.comparingByKey(Comparator.comparing(DMNType::getName))).toList(); + for (Entry kv : sortedEntries) { SchemaWriter.writeSchema(definitions, kv.getValue(), namingPolicy.getName(kv.getKey())); } jsonSchema = tree; From 958b547f74ec359f1f9020c642f2952373e74f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tibor=20Zim=C3=A1nyi?= Date: Thu, 8 Feb 2024 09:13:52 +0100 Subject: [PATCH 4/4] Adding a comment. --- .../main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java b/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java index 6d787ae1c49..1e948f09ce5 100644 --- a/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java +++ b/kie-dmn/kie-dmn-openapi/src/main/java/org/kie/dmn/openapi/impl/DMNOASGeneratorImpl.java @@ -82,6 +82,8 @@ private void prepareSerializaton() { ObjectNode tree = JsonUtil.objectNode(); ObjectNode definitions = JsonUtil.objectNode(); tree.set("definitions", definitions); + // It would be better if the map is a TreeMap, however that breaks test ProcessItemTest.test_together + // For some reason, it looks like there is some reliance on the map being a HashMap, which should be investigated later as that should never happen. final List> sortedEntries = schemas.entrySet().stream().sorted(Map.Entry.comparingByKey(Comparator.comparing(DMNType::getName))).toList(); for (Entry kv : sortedEntries) { SchemaWriter.writeSchema(definitions, kv.getValue(), namingPolicy.getName(kv.getKey()));