Skip to content

Commit 32f6ebf

Browse files
authored
feat: adds enum support (#191)
1 parent 4275593 commit 32f6ebf

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

artifacts/buildSrc/src/main/java/org/eclipse/dsp/generation/jsom/JsomParser.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import static org.eclipse.dsp.generation.jsom.JsonSchemaKeywords.CONST;
3838
import static org.eclipse.dsp.generation.jsom.JsonSchemaKeywords.CONTAINS;
3939
import static org.eclipse.dsp.generation.jsom.JsonSchemaKeywords.DEFINITIONS;
40+
import static org.eclipse.dsp.generation.jsom.JsonSchemaKeywords.ENUM;
4041
import static org.eclipse.dsp.generation.jsom.JsonSchemaKeywords.ITEMS;
4142
import static org.eclipse.dsp.generation.jsom.JsonSchemaKeywords.ONE_OF;
4243
import static org.eclipse.dsp.generation.jsom.JsonSchemaKeywords.PROPERTIES;
@@ -227,6 +228,7 @@ private void parseRequired(Map<String, Object> definition, SchemaType schemaType
227228
}
228229
}
229230

231+
@SuppressWarnings("unchecked")
230232
private SchemaProperty parseProperty(String name, Map<String, Object> value) {
231233
var type = value.get(TYPE);
232234
var comment = value.containsKey(COMMENT) ? value.get(COMMENT).toString() : "";
@@ -260,6 +262,10 @@ private SchemaProperty parseProperty(String name, Map<String, Object> value) {
260262
if (constantValue != null) {
261263
builder.constantValue(constantValue.toString());
262264
}
265+
var enumValues = (List<Object>) value.get(ENUM);
266+
if (enumValues != null) {
267+
builder.enumValues(enumValues);
268+
}
263269
return builder.build();
264270
}
265271
}

artifacts/buildSrc/src/main/java/org/eclipse/dsp/generation/jsom/JsonSchemaKeywords.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ public interface JsonSchemaKeywords {
3030
String PROPERTIES = "properties";
3131
String REQUIRED = "required";
3232
String TYPE = "type";
33+
String ENUM = "enum";
3334
}

artifacts/buildSrc/src/main/java/org/eclipse/dsp/generation/jsom/SchemaProperty.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class SchemaProperty implements Comparable<SchemaProperty> {
3333
private Set<String> types = new TreeSet<>();
3434
private final Set<SchemaType> resolvedTypes = new TreeSet<>();
3535
private final Set<ElementDefinition> itemTypes = new TreeSet<>();
36+
private final Set<Object> enumValues = new TreeSet<>();
3637

3738
public String getName() {
3839
return name;
@@ -50,6 +51,10 @@ public String getDescription() {
5051
return description;
5152
}
5253

54+
public Set<Object> getEnumValues() {
55+
return enumValues;
56+
}
57+
5358
public Set<SchemaType> getResolvedTypes() {
5459
return resolvedTypes;
5560
}
@@ -113,6 +118,11 @@ public Builder constantValue(String value) {
113118
return this;
114119
}
115120

121+
public Builder enumValues(Collection<Object> enumValues) {
122+
property.enumValues.addAll(enumValues);
123+
return this;
124+
}
125+
116126
public SchemaProperty build() {
117127
requireNonNull(property.name);
118128
requireNonNull(property.description);

artifacts/buildSrc/src/main/java/org/eclipse/dsp/generation/transformer/HtmlTableTransformer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ private void transformProperty(SchemaPropertyReference propertyReference, boolea
6767
builder.append(format("<td>%s</td>", resolvedTypes));
6868
if (resolvedProperty.getConstantValue() != null) {
6969
builder.append(format("<td>Value must be <span class=\"code\">%s</span></td>", resolvedProperty.getConstantValue()));
70+
} else if (!resolvedProperty.getEnumValues().isEmpty()){
71+
var values = resolvedProperty.getEnumValues().stream()
72+
.map(Object::toString)
73+
.collect(Collectors.joining(","));
74+
builder.append(format("<td>Must be of the following:<br><span class=\"code\">%s</span></td>",values));
7075
} else {
7176
var constants = resolvedProperty.getResolvedTypes().stream()
7277
.flatMap(t -> concat(Stream.of(t), t.getResolvedAllOf().stream())) // search the contains of the current type and any references 'allOf' types

0 commit comments

Comments
 (0)