Skip to content

Commit

Permalink
fix: handling of enum constants
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel authored and manusa committed Nov 27, 2023
1 parent 971fa34 commit a2cc1f1
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,7 +41,7 @@ public class JEnum extends AbstractJSONSchema2Pojo {

private final String type;
private final String underlyingType;
private final List<String> values;
private final Set<String> values; //Let's prevent duplicates

public JEnum(String type, String underlyingType, List<JsonNode> values, Config config, String description,
final boolean isNullable,
Expand All @@ -48,7 +50,8 @@ public JEnum(String type, String underlyingType, List<JsonNode> 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
Expand Down

0 comments on commit a2cc1f1

Please sign in to comment.