diff --git a/jsonschema-module-expressive-annotations/src/main/java/io/github/axonivy/json/schema/ExpressiveSchemaModule.java b/jsonschema-module-expressive-annotations/src/main/java/io/github/axonivy/json/schema/ExpressiveSchemaModule.java index 527c266..0b11575 100644 --- a/jsonschema-module-expressive-annotations/src/main/java/io/github/axonivy/json/schema/ExpressiveSchemaModule.java +++ b/jsonschema-module-expressive-annotations/src/main/java/io/github/axonivy/json/schema/ExpressiveSchemaModule.java @@ -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; @@ -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() diff --git a/jsonschema-module-expressive-annotations/src/test/java/io/github/axonivy/json/schema/tests/TestFieldCondition.java b/jsonschema-module-expressive-annotations/src/test/java/io/github/axonivy/json/schema/tests/TestFieldCondition.java index 74dccdb..d7c4752 100644 --- a/jsonschema-module-expressive-annotations/src/test/java/io/github/axonivy/json/schema/tests/TestFieldCondition.java +++ b/jsonschema-module-expressive-annotations/src/test/java/io/github/axonivy/json/schema/tests/TestFieldCondition.java @@ -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; @@ -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"); } @@ -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; diff --git a/jsonschema-module-expressive-annotations/src/test/java/io/github/axonivy/json/schema/tests/TestImplementationTypes.java b/jsonschema-module-expressive-annotations/src/test/java/io/github/axonivy/json/schema/tests/TestImplementationTypes.java index 654e868..f5605d6 100644 --- a/jsonschema-module-expressive-annotations/src/test/java/io/github/axonivy/json/schema/tests/TestImplementationTypes.java +++ b/jsonschema-module-expressive-annotations/src/test/java/io/github/axonivy/json/schema/tests/TestImplementationTypes.java @@ -154,7 +154,7 @@ void types_withoutContainer() { } - private static List namesOf(JsonNode defs) { + static List namesOf(JsonNode defs) { var names = new ArrayList(); defs.fieldNames().forEachRemaining(names::add); return names;