Skip to content

Commit

Permalink
Merge pull request #76 from axonivy/noContainer
Browse files Browse the repository at this point in the history
allow @Implementations types provisioning without sub-types container
  • Loading branch information
ivy-rew authored Jun 7, 2024
2 parents 24e4ad5 + 357f902 commit aba4975
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
/** the property that will define the implementing type of this generic object */
public String type() default "type";

/** the property that will hold the implementation specific properties */
/**
* Name of the property that will hold the implementation specific properties.
* Use an empty string to flag, that you don't need a container for sub-types.
*/
public String container() default "config";

/** the provider of at least all valid-subtypes */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,19 @@ private CustomDefinition supplyVirtualContainer(ResolvedType type, SchemaGenerat
storeCommonProps(subTypes, props);
props.set(impls.type(), craftTypeConsts(context, registry));

var container = props.putObject(impls.container());
String containerName = impls.container();
if (!containerName.isBlank()) {
var container = props.putObject(containerName);
if (conditional) {
container.put("type", "object"); //vs-code needs a generic block for validation
} else {
container.setAll(craftAnyOf(context, subTypes));
}
}

if (!conditional) {
container.setAll(craftAnyOf(context, subTypes));
return new CustomDefinition(std, false);
}

container.put("type", "object"); //vs-code needs a generic block for validation
return conditional(context, impls, registry)
.toDefinition(()->std)
.map(node -> new CustomDefinition(node, false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,28 @@ void subTypes_anyOf_unconditional() {
);
}

static class MyRootTypeNoContainer {
public GenericNoContainer provider;
}

@Implementations(value = LocalFactory.class, container = "")
public static interface GenericNoContainer {
String idX();
}

@Test
void types_withoutContainer() {
var unconditional = new ExpressiveSchemaGenerator().generateSchema(MyRootTypeNoContainer.class);
System.out.println(unconditional.toPrettyString());

var generic = unconditional.get("$defs").get(GenericNoContainer.class.getSimpleName());
var props = generic.get("properties");
assertThat(namesOf(props))
.as("empty 'container' name omits its declaration: this allows custom property rules to reflect children")
.doesNotContain("config", "");
}


private static List<String> namesOf(JsonNode defs) {
var names = new ArrayList<String>();
defs.fieldNames().forEachRemaining(names::add);
Expand Down

0 comments on commit aba4975

Please sign in to comment.