From 2cd8c2bcf0786c31fd833f3b375e0c0582689b09 Mon Sep 17 00:00:00 2001 From: Maria Brauer Date: Mon, 17 Feb 2025 15:23:22 +0100 Subject: [PATCH 1/5] #814 added support for descriptions from java interfaces (only for methods) & restructured generateSchema() --- .../configuration/JsonSchemaGenerator.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) 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 5df7a03c1e..5133eb6c06 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 @@ -10,6 +10,8 @@ import java.util.Optional; import java.util.Set; +import com.buschmais.jqassistant.core.shared.annotation.Description; + import com.fasterxml.classmate.ResolvedType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -40,20 +42,25 @@ 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(); + } + return null; }); + configBuilder.forTypesInGeneral() + .withCustomDefinitionProvider(new MapDefinitionProvider()) .withDefinitionNamingStrategy((definitionKey, context) -> mapToKebabCase(definitionKey.getType() .getTypeName())); From c2209dcad18322747dc0b9fe02dedf2f8e178abc Mon Sep 17 00:00:00 2001 From: Maria Brauer Date: Wed, 19 Feb 2025 08:37:36 +0100 Subject: [PATCH 2/5] #814 added definition support for inner definitions --- .../api/configuration/JsonSchemaGenerator.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 5133eb6c06..045c154374 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,7 @@ 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; @@ -56,6 +53,12 @@ public static ObjectNode generateSchema(Class clazz) { 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; }); From e661991e1e7f80242f80ba1cd21221994356f745 Mon Sep 17 00:00:00 2001 From: Maria Brauer Date: Mon, 24 Feb 2025 09:46:33 +0100 Subject: [PATCH 3/5] #814 added test for behaviour of adding descriptions and defaults to JSON schema --- .../JsonSchemaGeneratorTest.java | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) 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..1dc736fba7 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,10 +1,12 @@ package com.buschmais.jqassistant.core.runtime.api.configuration; -import java.io.IOException; import java.util.HashSet; import java.util.Set; +import com.buschmais.jqassistant.core.shared.aether.configuration.Plugin; + import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.networknt.schema.ValidationMessage; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -17,7 +19,7 @@ class JsonSchemaGeneratorTest { private JsonNode schemaNode; @BeforeEach - void generateSchema() throws IOException { + void generateSchema() { schemaNode = JsonSchemaGenerator.generateSchema(Configuration.class); } @@ -45,4 +47,48 @@ void testInvalidYaml() throws Exception { } } + @Test + void testDescriptionsAndDefaults() { + ObjectNode pluginNode = JsonSchemaGenerator.generateSchema(Plugin.class); + + // inner descriptions should not be available at the moment on outer level + assertThat(schemaNode.findValue("plugins") + .has("description")).isFalse(); + assertThat(schemaNode.findValue("default-plugins") + .has("description")).isFalse(); + + // direct descriptions should be available + assertThat(schemaNode.findValue("skip") + .get("description") + .textValue()).isEqualTo("Skip execution of jQAssistant tasks/goals."); + assertThat(pluginNode.findValue("group-id") + .get("description") + .textValue()).isEqualTo("The groupId of the plugin."); + assertThat(pluginNode.findValue("classifier") + .get("description") + .textValue()).isEqualTo("The classifier of the plugin (optional)."); + assertThat(pluginNode.findValue("artifact-id") + .get("description") + .textValue()).isEqualTo("The artifactId of the plugin."); + assertThat(pluginNode.findValues("type") + .get(11) + .get("description") + .textValue()).isEqualTo("The type (extension) of the plugin."); + assertThat(pluginNode.findValue("version") + .get("description") + .textValue()).isEqualTo("The version of the plugin."); + assertThat(pluginNode.findValue("exclusions") + .get("description") + .textValue()).isEqualTo("The exclusions of the plugin."); + + // defaults should be available + assertThat(schemaNode.findValue("skip") + .get("default") + .textValue()).isEqualTo("false"); + assertThat(pluginNode.findValues("type") + .get(11) + .get("default") + .textValue()).isEqualTo("jar"); + + } } From 190542412b77286f0e57dc5c1e875add15543232 Mon Sep 17 00:00:00 2001 From: Maria Brauer Date: Mon, 24 Feb 2025 15:14:17 +0100 Subject: [PATCH 4/5] #814 adjusted tests for descriptions and defaults --- bom/pom.xml | 6 ++ core/runtime/pom.xml | 5 ++ .../JsonSchemaGeneratorTest.java | 55 +++++-------------- pom.xml | 1 + 4 files changed, 25 insertions(+), 42 deletions(-) diff --git a/bom/pom.xml b/bom/pom.xml index ce0100c6fa..df11a8f832 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/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 1dc736fba7..1646b048ff 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 @@ -3,16 +3,14 @@ import java.util.HashSet; import java.util.Set; -import com.buschmais.jqassistant.core.shared.aether.configuration.Plugin; - import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.networknt.schema.ValidationMessage; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; 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 { @@ -48,47 +46,20 @@ void testInvalidYaml() throws Exception { } @Test - void testDescriptionsAndDefaults() { - ObjectNode pluginNode = JsonSchemaGenerator.generateSchema(Plugin.class); - - // inner descriptions should not be available at the moment on outer level - assertThat(schemaNode.findValue("plugins") - .has("description")).isFalse(); - assertThat(schemaNode.findValue("default-plugins") - .has("description")).isFalse(); + void testDescriptions() { + // inner descriptions should not be available on outer level at the moment + assertJson(schemaNode).at("/properties/jqassistant/properties/plugins") + .doesNotContainKey("description"); // direct descriptions should be available - assertThat(schemaNode.findValue("skip") - .get("description") - .textValue()).isEqualTo("Skip execution of jQAssistant tasks/goals."); - assertThat(pluginNode.findValue("group-id") - .get("description") - .textValue()).isEqualTo("The groupId of the plugin."); - assertThat(pluginNode.findValue("classifier") - .get("description") - .textValue()).isEqualTo("The classifier of the plugin (optional)."); - assertThat(pluginNode.findValue("artifact-id") - .get("description") - .textValue()).isEqualTo("The artifactId of the plugin."); - assertThat(pluginNode.findValues("type") - .get(11) - .get("description") - .textValue()).isEqualTo("The type (extension) of the plugin."); - assertThat(pluginNode.findValue("version") - .get("description") - .textValue()).isEqualTo("The version of the plugin."); - assertThat(pluginNode.findValue("exclusions") - .get("description") - .textValue()).isEqualTo("The exclusions of the plugin."); - - // defaults should be available - assertThat(schemaNode.findValue("skip") - .get("default") - .textValue()).isEqualTo("false"); - assertThat(pluginNode.findValues("type") - .get(11) - .get("default") - .textValue()).isEqualTo("jar"); + assertJson(schemaNode).at("/properties/jqassistant/properties/skip/description") + .isText("Skip execution of jQAssistant tasks/goals."); + } + @Test + void testDefaults() { + // default values should be available + assertJson(schemaNode).at("/properties/jqassistant/properties/skip/default") + .isText("false"); } } diff --git a/pom.xml b/pom.xml index 6d33c84ea5..652c3ef5ae 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 From d21435dc9c9634f794fb0adda95b2303e9e757ca Mon Sep 17 00:00:00 2001 From: Maria Brauer Date: Mon, 24 Feb 2025 16:50:28 +0100 Subject: [PATCH 5/5] #814 merged master into branch and adjusted tests --- .../api/configuration/JsonSchemaGeneratorTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 1646b048ff..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 @@ -48,18 +48,18 @@ void testInvalidYaml() throws Exception { @Test void testDescriptions() { // inner descriptions should not be available on outer level at the moment - assertJson(schemaNode).at("/properties/jqassistant/properties/plugins") - .doesNotContainKey("description"); + assertJson(schemaNode).at("/$defs/com.buschmais.jqassistant.core.runtime.api.configuration.-plugin/description") + .isMissing(); // direct descriptions should be available - assertJson(schemaNode).at("/properties/jqassistant/properties/skip/description") + 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("/properties/jqassistant/properties/skip/default") + assertJson(schemaNode).at("/$defs/com.buschmais.jqassistant.core.runtime.api.configuration.-configuration/properties/skip/default") .isText("false"); } }