Skip to content

Commit f10f2d8

Browse files
committed
openapi: MVC routes don't have custom annotations in attributes
- fix #3582
1 parent ad6c256 commit f10f2d8

File tree

4 files changed

+72
-5
lines changed

4 files changed

+72
-5
lines changed

modules/jooby-apt/src/main/java/io/jooby/internal/apt/RouteAttributesGenerator.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -167,28 +167,31 @@ private Map<String, Object> annotationMap(List<? extends AnnotationMirror> annot
167167
}
168168
String prefix = elem.getSimpleName().toString();
169169
// Set all values and then override with present values (fix for JDK 11+)
170-
result.putAll(toMap(annotation.getElementValues(), prefix));
170+
result.putAll(toMap(annotation.getElementValues(), prefix, false));
171171

172172
// Defaults value only pick "value"
173-
toMap(elements.getElementValuesWithDefaults(annotation), prefix, "value"::equals)
173+
toMap(elements.getElementValuesWithDefaults(annotation), prefix, true, "value"::equals)
174174
.forEach(result::putIfAbsent);
175175
}
176176
return result;
177177
}
178178

179179
private Map<String, Object> toMap(
180-
Map<? extends ExecutableElement, ? extends AnnotationValue> values, String prefix) {
181-
return toMap(values, prefix, name -> true);
180+
Map<? extends ExecutableElement, ? extends AnnotationValue> values,
181+
String prefix,
182+
boolean defaults) {
183+
return toMap(values, prefix, defaults, name -> true);
182184
}
183185

184186
private Map<String, Object> toMap(
185187
Map<? extends ExecutableElement, ? extends AnnotationValue> values,
186188
String prefix,
189+
boolean defaults,
187190
Predicate<String> filter) {
188191
Map<String, Object> result = new LinkedHashMap<>();
189192
for (var attribute : values.entrySet()) {
190193
var value = annotationValue(attribute.getValue());
191-
if (value != null && !value.toString().isEmpty()) {
194+
if (defaults || (value != null && !value.toString().isEmpty())) {
192195
var method = attribute.getKey().getSimpleName().toString();
193196
if (filter.test(method)) {
194197
var name = method.equals("value") ? prefix : prefix + "." + method;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package tests.i3582;
7+
8+
import java.lang.annotation.ElementType;
9+
import java.lang.annotation.Retention;
10+
import java.lang.annotation.RetentionPolicy;
11+
import java.lang.annotation.Target;
12+
13+
@Target({ElementType.METHOD, ElementType.TYPE, ElementType.ANNOTATION_TYPE})
14+
@Retention(RetentionPolicy.RUNTIME)
15+
public @interface Annotation3582 {
16+
String value() default "";
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package tests.i3582;
7+
8+
import com.google.inject.Inject;
9+
import io.jooby.annotation.GET;
10+
import io.jooby.annotation.QueryParam;
11+
12+
@Annotation3582
13+
public class C3582 {
14+
15+
@Inject
16+
public C3582() {}
17+
18+
@GET("/hello")
19+
public String helloWorld(@QueryParam String property) {
20+
return "hello world" + property;
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package tests.i3582;
7+
8+
import static org.junit.Assert.assertTrue;
9+
10+
import org.junit.jupiter.api.Test;
11+
12+
import io.jooby.apt.ProcessorRunner;
13+
14+
public class Issue3585 {
15+
16+
@Test
17+
public void shouldGenerateDefaultAnnotation() throws Exception {
18+
new ProcessorRunner(new C3582())
19+
.withSourceCode(
20+
source -> {
21+
assertTrue(source.contains(".setAttributes(java.util.Map.of("));
22+
assertTrue(source.contains("\"Annotation3582\", \"\"))"));
23+
});
24+
}
25+
}

0 commit comments

Comments
 (0)