Skip to content

Commit 0bad11c

Browse files
open-api: support jakarta.ws.rs.DefaultValue handling
1 parent 39d1112 commit 0bad11c

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed

modules/jooby-openapi/src/main/java/io/jooby/internal/openapi/AnnotationParser.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ public Optional<String> getDefaultValue(List<AnnotationNode> annotations) {
122122
}
123123
}
124124
}
125+
return getJakartaDefaultValue(annotations);
126+
}
127+
128+
public Optional<String> getJakartaDefaultValue(List<AnnotationNode> annotations) {
129+
List<Class> names =
130+
Stream.of(annotations()).filter(it -> it.getName().startsWith("jakarta.ws.rs")).toList();
131+
for (var a : annotations) {
132+
if (a.values != null) {
133+
var matches = names.stream().anyMatch(it -> "Ljakarta/ws/rs/DefaultValue;".equals(a.desc));
134+
if (matches) {
135+
return AnnotationUtils.findAnnotationValue(a, "value").map(Objects::toString);
136+
}
137+
}
138+
}
125139
return Optional.empty();
126140
}
127141

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 issues.i3835;
7+
8+
import io.jooby.Jooby;
9+
10+
import static io.jooby.openapi.MvcExtensionGenerator.toMvcExtension;
11+
12+
public class App3835Jakarta extends Jooby {
13+
{
14+
mvc(toMvcExtension(C3835Jakarta.class));
15+
}
16+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 issues.i3835;
7+
8+
import jakarta.ws.rs.DefaultValue;
9+
import jakarta.ws.rs.GET;
10+
import jakarta.ws.rs.Path;
11+
import jakarta.ws.rs.QueryParam;
12+
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
@Path("/3835")
17+
public class C3835Jakarta {
18+
19+
/**
20+
* Search/scan index.
21+
*
22+
* @param q Search string. Defaults to <code>*</code>
23+
* @return Search result.
24+
*/
25+
@GET
26+
public Map<String, Object> search(
27+
@QueryParam("q") @DefaultValue("*") String q,
28+
@QueryParam("pageSize") @DefaultValue("20") int pageSize,
29+
@QueryParam("page") @DefaultValue("1") int page,
30+
@QueryParam("options") @DefaultValue("--a") List<String> options) {
31+
return null;
32+
}
33+
}

modules/jooby-openapi/src/test/java/issues/i3835/Issue3835.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,56 @@ public void shouldGenerateCorrectName(OpenAPIResult result) {
6363
type: object\
6464
""");
6565
}
66+
67+
@OpenAPITest(value = App3835Jakarta.class)
68+
public void shouldGenerateJakartaDefaultValues(OpenAPIResult result) {
69+
assertThat(result.toYaml())
70+
.isEqualToIgnoringNewLines(
71+
"""
72+
openapi: 3.0.1
73+
info:
74+
title: 3835Jakarta API
75+
description: 3835Jakarta API description
76+
version: "1.0"
77+
paths:
78+
/3835:
79+
get:
80+
summary: Search/scan index.
81+
operationId: search
82+
parameters:
83+
- name: q
84+
in: query
85+
description: Search string. Defaults to *
86+
schema:
87+
type: string
88+
default: '*'
89+
- name: pageSize
90+
in: query
91+
schema:
92+
type: integer
93+
format: int32
94+
default: 20
95+
- name: page
96+
in: query
97+
schema:
98+
type: integer
99+
format: int32
100+
default: 1
101+
- name: options
102+
in: query
103+
schema:
104+
type: array
105+
items:
106+
type: string
107+
responses:
108+
"200":
109+
description: Search result.
110+
content:
111+
application/json:
112+
schema:
113+
type: object
114+
additionalProperties:
115+
type: object\
116+
""");
117+
}
66118
}

0 commit comments

Comments
 (0)