Skip to content

Commit

Permalink
schema experimental version ready
Browse files Browse the repository at this point in the history
  • Loading branch information
miho committed Aug 13, 2024
1 parent 4cf82a5 commit 8dcf9fd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ private Map<String, Object> getPropertySchema(Property property) {

// Handle polymorphic types with oneOf and add @vmf-type as a required property
Type elementType = VMFTypeUtils.forClass(property.getType().getElementTypeName().get());
if (isValueType(elementType)) {
itemsSchema.put("type", mapValueType(elementType));
} else
if (!VMFTypeUtils.getSubTypes(elementType).isEmpty()) {

var typesToChooseFrom = VMFTypeUtils.getSubTypes(elementType);
Expand Down Expand Up @@ -283,7 +286,6 @@ private Map<String, Object> getPropertySchema(Property property) {
var typeAlias = getTypeAlias(elementType);
itemsSchema.put("$ref", "#/definitions/" + typeAlias);
}

propertySchema.put("items", itemsSchema);
addDefaultValueAndDescriptionAndConstraintIfAvailable(property, propertySchema);
} else if (VMFTypeUtils.isEnum(property.getType())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,6 @@ void testModel() {
Assertions.fail(e);
e.printStackTrace();
}

// create a json schema from model class
try {
Map<String, Object> schema = VMFJsonSchemaGenerator.newInstance(VMFJacksonModule.RUNTIME_TYPE.EXPERIMENTAL)
.generateSchema(ExternalTypeModel01.class);
ObjectMapper schemaMapper = new ObjectMapper();
String jsonSchema = schemaMapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);
System.out.println(jsonSchema);
} catch (Exception e) {
Assertions.fail(e);
e.printStackTrace();
}
}

}

0 comments on commit 8dcf9fd

Please sign in to comment.