Skip to content

Commit

Permalink
Merge pull request #79 from axonivy/hideConditional
Browse files Browse the repository at this point in the history
fix: do not state @conditional field as property
  • Loading branch information
ivy-rew authored Jun 7, 2024
2 parents 06a6ac6 + 09de9f0 commit 8eaffa5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.github.victools.jsonschema.generator.Module;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder;

import io.github.axonivy.json.schema.annotations.Conditional;
import io.github.axonivy.json.schema.impl.ConditionalFieldProvider;
import io.github.axonivy.json.schema.impl.ConfigNamingStrategy;
import io.github.axonivy.json.schema.impl.CustomTypeProvider;
Expand Down Expand Up @@ -45,7 +46,8 @@ public void applyToConfigBuilder(SchemaGeneratorConfigBuilder configBuilder) {
configBuilder.forFields()
.withCustomDefinitionProvider(new RemoteRefProvider(refs))
.withCustomDefinitionProvider(new ExamplesProvider())
.withCustomDefinitionProvider(new CustomTypeProvider());
.withCustomDefinitionProvider(new CustomTypeProvider())
.withIgnoreCheck(f -> f.getAnnotation(Conditional.class) != null);

if (options.contains(ExpressiveSchemaOption.USE_ADDITIONAL_PROPERTIES_ANNOTATION)) {
configBuilder.forTypesInGeneral()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.axonivy.json.schema.tests;

import static io.github.axonivy.json.schema.tests.TestImplementationTypes.namesOf;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.ArrayList;
Expand Down Expand Up @@ -93,11 +94,15 @@ public static class ComplexType {
void conditionalOtherProp() {
ObjectNode schema = new ExpressiveSchemaGenerator().generateSchema(MyConditionalFieldSibling.class);

assertThat(namesOf(schema.get("properties")))
.as("conditional fields are not listed as classic 'properties'")
.containsOnly("$schema", "provider");

JsonNode ifProvider = schema.get("if").get("properties").get("provider");
assertThat(ifProvider.get("const").asText())
.isEqualTo("azure");

JsonNode thenProperty = schema.get("then").get("properties").get("always");
JsonNode thenProperty = schema.get("then").get("properties").get("ifAzure");
assertThat(thenProperty.get("$ref").asText())
.isEqualTo("#/$defs/ComplexType");
}
Expand All @@ -108,7 +113,7 @@ static class MyConditionalFieldSibling {
public String provider;

@Conditional(ifProperty = "provider", hasConst = { "azure" })
public ComplexType always;
private ComplexType ifAzure;

public static class ComplexType {
public String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void types_withoutContainer() {
}


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

0 comments on commit 8eaffa5

Please sign in to comment.