From 0f9a445fb5b46c97c5fd771676634c85ac186090 Mon Sep 17 00:00:00 2001 From: Ioannis Canellos Date: Sat, 25 Nov 2023 11:21:46 +0200 Subject: [PATCH] fix: handling of enum constants --- .../main/java/io/fabric8/java/generator/nodes/JEnum.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/java-generator/core/src/main/java/io/fabric8/java/generator/nodes/JEnum.java b/java-generator/core/src/main/java/io/fabric8/java/generator/nodes/JEnum.java index 3ffa9b7d317..10e574afd9b 100644 --- a/java-generator/core/src/main/java/io/fabric8/java/generator/nodes/JEnum.java +++ b/java-generator/core/src/main/java/io/fabric8/java/generator/nodes/JEnum.java @@ -26,8 +26,10 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; +import java.util.Set; import java.util.stream.Collectors; import static io.fabric8.java.generator.nodes.Keywords.JAVA_LANG_LONG; @@ -39,7 +41,7 @@ public class JEnum extends AbstractJSONSchema2Pojo { private final String type; private final String underlyingType; - private final List values; + private final Set values; //Let's prevent duplicates public JEnum(String type, String underlyingType, List values, Config config, String description, final boolean isNullable, @@ -48,7 +50,8 @@ public JEnum(String type, String underlyingType, List values, Config c this.type = AbstractJSONSchema2Pojo.sanitizeString( type.substring(0, 1).toUpperCase() + type.substring(1)); this.underlyingType = underlyingType; - this.values = values.stream().map(JsonNode::asText).collect(Collectors.toList()); + //Tests assume order so let's use LinkedHashSet instead of just using Collectors.toSet() + this.values = values.stream().map(JsonNode::asText).collect(Collectors.toCollection(LinkedHashSet::new)); } @Override