Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static org.eclipse.dsp.generation.jsom.JsonSchemaKeywords.CONST;
import static org.eclipse.dsp.generation.jsom.JsonSchemaKeywords.CONTAINS;
import static org.eclipse.dsp.generation.jsom.JsonSchemaKeywords.DEFINITIONS;
import static org.eclipse.dsp.generation.jsom.JsonSchemaKeywords.ENUM;
import static org.eclipse.dsp.generation.jsom.JsonSchemaKeywords.ITEMS;
import static org.eclipse.dsp.generation.jsom.JsonSchemaKeywords.ONE_OF;
import static org.eclipse.dsp.generation.jsom.JsonSchemaKeywords.PROPERTIES;
Expand Down Expand Up @@ -227,6 +228,7 @@ private void parseRequired(Map<String, Object> definition, SchemaType schemaType
}
}

@SuppressWarnings("unchecked")
private SchemaProperty parseProperty(String name, Map<String, Object> value) {
var type = value.get(TYPE);
var comment = value.containsKey(COMMENT) ? value.get(COMMENT).toString() : "";
Expand Down Expand Up @@ -260,6 +262,10 @@ private SchemaProperty parseProperty(String name, Map<String, Object> value) {
if (constantValue != null) {
builder.constantValue(constantValue.toString());
}
var enumValues = (List<Object>) value.get(ENUM);
if (enumValues != null) {
builder.enumValues(enumValues);
}
return builder.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ public interface JsonSchemaKeywords {
String PROPERTIES = "properties";
String REQUIRED = "required";
String TYPE = "type";
String ENUM = "enum";
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class SchemaProperty implements Comparable<SchemaProperty> {
private Set<String> types = new TreeSet<>();
private final Set<SchemaType> resolvedTypes = new TreeSet<>();
private final Set<ElementDefinition> itemTypes = new TreeSet<>();
private final Set<Object> enumValues = new TreeSet<>();

public String getName() {
return name;
Expand All @@ -50,6 +51,10 @@ public String getDescription() {
return description;
}

public Set<Object> getEnumValues() {
return enumValues;
}

public Set<SchemaType> getResolvedTypes() {
return resolvedTypes;
}
Expand Down Expand Up @@ -113,6 +118,11 @@ public Builder constantValue(String value) {
return this;
}

public Builder enumValues(Collection<Object> enumValues) {
property.enumValues.addAll(enumValues);
return this;
}

public SchemaProperty build() {
requireNonNull(property.name);
requireNonNull(property.description);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ private void transformProperty(SchemaPropertyReference propertyReference, boolea
builder.append(format("<td>%s</td>", resolvedTypes));
if (resolvedProperty.getConstantValue() != null) {
builder.append(format("<td>Value must be <span class=\"code\">%s</span></td>", resolvedProperty.getConstantValue()));
} else if (!resolvedProperty.getEnumValues().isEmpty()){
var values = resolvedProperty.getEnumValues().stream()
.map(Object::toString)
.collect(Collectors.joining(","));
builder.append(format("<td>Must be of the following:<br><span class=\"code\">%s</span></td>",values));
} else {
var constants = resolvedProperty.getResolvedTypes().stream()
.flatMap(t -> concat(Stream.of(t), t.getResolvedAllOf().stream())) // search the contains of the current type and any references 'allOf' types
Expand Down
Loading