Skip to content

Commit

Permalink
Fix mapping of openehr type name to target type name
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterbos committed May 15, 2020
1 parent ef0df6a commit a35ce93
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public JsonObject create(BmmModel bmm) {
JsonObjectBuilder definitions = jsonFactory.createObjectBuilder();


allOfArray.add(createRequiredArray("_type"));
allOfArray.add(createRequiredArray(typeNameProperty));

//for every root type, if the type is right, check that type
//anyof does more or less the same, but this is faster plus it gives MUCH less errors!
Expand Down Expand Up @@ -220,7 +220,7 @@ private void addClass(JsonObjectBuilder definitions, BmmClass bmmClass) {
if(hasRequiredProperties) {
definition.add("required", required);
}
definition.add("properties", properties);


if(!allowAdditionalProperties && atLeastOneProperty) {
definition.add("additionalProperties", false);
Expand All @@ -243,6 +243,7 @@ private void addClass(JsonObjectBuilder definitions, BmmClass bmmClass) {
}
}
if(addedAncestors) {
definition.add("properties", properties);
polymorphicArray.add(definition);
definitions.add(typeName, jsonFactory.createObjectBuilder().add("allOf", polymorphicArray).build());
} else {
Expand All @@ -252,14 +253,16 @@ private void addClass(JsonObjectBuilder definitions, BmmClass bmmClass) {
Map<String, BmmClass> allDescendants = bmmModel.getAllDescendantClassObjects(bmmClass);
for(BmmClass descendant:allDescendants.values()) {
if(shouldClassBeIncluded(descendant)) {
descendantsMappings.add(descendant.getClassKey(), createReference(descendant.getClassKey()));
descendantsMappings.add(descendant.getClassKey(), createReferenceTarget(descendant.getClassKey()));
}
}
properties.add("_type", createType("string"));
definition.add("discriminator", jsonFactory.createObjectBuilder()
.add("propertyName", "_type")
.add("mappings",descendantsMappings)
.add("mapping",descendantsMappings)
);
}
definition.add("properties", properties);
definitions.add(typeName, definition);
}
}
Expand Down Expand Up @@ -397,7 +400,11 @@ private JsonObjectBuilder createReference(String rootType) {
// if(rootType.equalsIgnoreCase("Any")) {
// return jsonFactory.createObjectBuilder().add("type", "object");
// }
return jsonFactory.createObjectBuilder().add("$ref", "#/components/schemas/" + convertTypeName(rootType));
return jsonFactory.createObjectBuilder().add("$ref", createReferenceTarget(rootType));
}

private String createReferenceTarget(String typeName) {
return "#/components/schemas/" + convertTypeName(typeName);
}

private boolean isJSPrimitive(String rootType) {
Expand Down

0 comments on commit a35ce93

Please sign in to comment.