diff --git a/bom/pom.xml b/bom/pom.xml index 3a358fa2c2..8713b24799 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -504,6 +504,12 @@ ${system-lambda.version} test + + uk.org.webcompere + model-assert + ${model-assert.version} + test + diff --git a/core/runtime/pom.xml b/core/runtime/pom.xml index 693a94abb4..8e67aeddf6 100644 --- a/core/runtime/pom.xml +++ b/core/runtime/pom.xml @@ -106,6 +106,11 @@ org.mockito mockito-junit-jupiter + + uk.org.webcompere + model-assert + test + org.slf4j slf4j-simple diff --git a/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/JsonSchemaGenerator.java b/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/JsonSchemaGenerator.java index 5ba0a0ad75..859b05402b 100644 --- a/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/JsonSchemaGenerator.java +++ b/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/JsonSchemaGenerator.java @@ -5,10 +5,9 @@ import java.io.InputStream; import java.net.URI; import java.net.URL; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; +import java.util.*; + +import com.buschmais.jqassistant.core.shared.annotation.Description; import com.fasterxml.classmate.ResolvedType; import com.fasterxml.jackson.databind.JsonNode; @@ -40,20 +39,31 @@ public static ObjectNode generateSchema(Class clazz) { .without(Option.VOID_METHODS, Option.GETTER_METHODS, Option.PUBLIC_STATIC_FIELDS); configBuilder.forMethods() - .withTargetTypeOverridesResolver(target -> getResolvedTypes(target, target.getType())); - configBuilder.forMethods() - .withPropertyNameOverrideResolver(member -> mapToKebabCase(member.getName())); - configBuilder.forTypesInGeneral() - .withCustomDefinitionProvider(new MapDefinitionProvider()); - configBuilder.forMethods() + .withTargetTypeOverridesResolver(target -> getResolvedTypes(target, target.getType())) + .withPropertyNameOverrideResolver(member -> mapToKebabCase(member.getName())) .withDefaultResolver(method -> { WithDefault annotation = method.getAnnotationConsideringFieldAndGetter(WithDefault.class); if (annotation != null) { return annotation.value(); } return null; + }) + .withDescriptionResolver(method -> { + Description annotation = method.getAnnotationConsideringFieldAndGetter(Description.class); + if (annotation != null) { + return annotation.value(); + } + if (method.getType() != null) { + Description innerAnnotation = method.getType().getErasedType().getAnnotation(Description.class); + if (innerAnnotation != null) { + return innerAnnotation.value(); + } + } + return null; }); + configBuilder.forTypesInGeneral() + .withCustomDefinitionProvider(new MapDefinitionProvider()) .withDefinitionNamingStrategy((definitionKey, context) -> mapToKebabCase(definitionKey.getType() .getTypeName())); diff --git a/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/api/configuration/JsonSchemaGeneratorTest.java b/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/api/configuration/JsonSchemaGeneratorTest.java index 89d8e78c0b..f20ac6f3ec 100644 --- a/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/api/configuration/JsonSchemaGeneratorTest.java +++ b/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/api/configuration/JsonSchemaGeneratorTest.java @@ -1,6 +1,5 @@ package com.buschmais.jqassistant.core.runtime.api.configuration; -import java.io.IOException; import java.util.HashSet; import java.util.Set; @@ -11,13 +10,14 @@ import static com.buschmais.jqassistant.core.runtime.api.configuration.JsonSchemaGenerator.validateYaml; import static org.assertj.core.api.Assertions.assertThat; +import static uk.org.webcompere.modelassert.json.JsonAssertions.assertJson; class JsonSchemaGeneratorTest { private JsonNode schemaNode; @BeforeEach - void generateSchema() throws IOException { + void generateSchema() { schemaNode = JsonSchemaGenerator.generateSchema(Configuration.class); } @@ -45,4 +45,21 @@ void testInvalidYaml() throws Exception { } } + @Test + void testDescriptions() { + // inner descriptions should not be available on outer level at the moment + assertJson(schemaNode).at("/$defs/com.buschmais.jqassistant.core.runtime.api.configuration.-plugin/description") + .isMissing(); + + // direct descriptions should be available + assertJson(schemaNode).at("/$defs/com.buschmais.jqassistant.core.runtime.api.configuration.-configuration/properties/skip/description") + .isText("Skip execution of jQAssistant tasks/goals."); + } + + @Test + void testDefaults() { + // default values should be available + assertJson(schemaNode).at("/$defs/com.buschmais.jqassistant.core.runtime.api.configuration.-configuration/properties/skip/default") + .isText("false"); + } } diff --git a/pom.xml b/pom.xml index a46f4da020..05cb0d7307 100644 --- a/pom.xml +++ b/pom.xml @@ -95,6 +95,7 @@ 3.6.3 5.15.2 1.2.1 + 1.1.0 4.4.41 4.4.0.29 5.26.2