Skip to content

Commit

Permalink
[kie-issues#843] Generate reproducible dmndefinitions.json. (apache#5676
Browse files Browse the repository at this point in the history
)

* Generate reproducible dmndefinitions.json.

* Replace HashMap with TreeMap.

* Revert TreeMap as that breaks some transitively related code.

* Adding a comment.
  • Loading branch information
baldimir authored and rgdoliveira committed Mar 11, 2024
1 parent cfc8175 commit ccb71db
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<DMNModel> dmnModels;
Expand Down Expand Up @@ -81,7 +82,10 @@ private void prepareSerializaton() {
ObjectNode tree = JsonUtil.objectNode();
ObjectNode definitions = JsonUtil.objectNode();
tree.set("definitions", definitions);
for (Entry<DMNType, Schema> kv : schemas.entrySet()) {
// 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<Entry<DMNType, Schema>> sortedEntries = schemas.entrySet().stream().sorted(Map.Entry.comparingByKey(Comparator.comparing(DMNType::getName))).toList();
for (Entry<DMNType, Schema> kv : sortedEntries) {
SchemaWriter.writeSchema(definitions, kv.getValue(), namingPolicy.getName(kv.getKey()));
}
jsonSchema = tree;
Expand Down Expand Up @@ -191,5 +195,4 @@ private void visitForIndexing(DMNType idnType) {
}
}
}

}

0 comments on commit ccb71db

Please sign in to comment.