Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not state @Conditional field as property #79

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading