Skip to content

Commit

Permalink
#814 added support for descriptions from java interfaces (#815)
Browse files Browse the repository at this point in the history
* #814 added support for descriptions from java interfaces (only for methods) & restructured generateSchema()

* #814 added definition support for inner definitions

* #814 added test for behaviour of adding descriptions and defaults to JSON schema

* #814 adjusted tests for descriptions and defaults

* #814 merged master into branch and adjusted tests
  • Loading branch information
Bramaten authored Feb 24, 2025
1 parent dc47d50 commit 64499c4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 12 deletions.
6 changes: 6 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,12 @@
<version>${system-lambda.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>model-assert</artifactId>
<version>${model-assert.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
5 changes: 5 additions & 0 deletions core/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>model-assert</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.buschmais.jqassistant.core.runtime.api.configuration;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

Expand All @@ -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);
}

Expand Down Expand Up @@ -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");
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<maven.version>3.6.3</maven.version>
<mockito.version>5.15.2</mockito.version>
<system-lambda.version>1.2.1</system-lambda.version>
<model-assert.version>1.1.0</model-assert.version>
<neo4j_4x.version>4.4.41</neo4j_4x.version>
<neo4j_4x_apoc.version>4.4.0.29</neo4j_4x_apoc.version>
<neo4j_5x.version>5.26.2</neo4j_5x.version>
Expand Down

0 comments on commit 64499c4

Please sign in to comment.