Skip to content

Commit 3e69142

Browse files
committed
open-api: Support OpenAPI @io.swagger.v3.oas.annotations.Parameter on method parameters
- fix #3461
1 parent 3db6ec2 commit 3e69142

File tree

3 files changed

+84
-3
lines changed

3 files changed

+84
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,17 @@ public static void parse(ParserContext ctx, OperationExt operation) {
212212
findAnnotationByType(method.visibleAnnotations, Parameter.class).stream()
213213
.findFirst()
214214
.ifPresent(a -> parameters(ctx, operation, singletonList(toMap(a))));
215-
/**
216-
* @RequestBody:
217-
*/
218215
if (method.visibleParameterAnnotations != null) {
219216
for (List<AnnotationNode> paramAnnotations : method.visibleParameterAnnotations) {
217+
/**
218+
* @Parameter:
219+
*/
220+
findAnnotationByType(paramAnnotations, Parameter.class).stream()
221+
.findFirst()
222+
.ifPresent(a -> parameters(ctx, operation, singletonList(toMap(a))));
223+
/**
224+
* @RequestBody:
225+
*/
220226
findAnnotationByType(paramAnnotations, RequestBody.class).stream()
221227
.findFirst()
222228
.ifPresent(a -> requestBody(ctx, operation, toMap(a)));
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.i3461;
7+
8+
import java.util.UUID;
9+
10+
import io.jooby.Jooby;
11+
import io.jooby.annotation.GET;
12+
import io.jooby.annotation.Path;
13+
import io.jooby.annotation.QueryParam;
14+
import io.swagger.v3.oas.annotations.Parameter;
15+
16+
public class App3461 extends Jooby {
17+
18+
@Path("/")
19+
static class Controller {
20+
21+
@GET("/3461")
22+
public String getBlah(
23+
@Parameter(required = true, description = "Param annotation") @QueryParam UUID orgId) {
24+
return "";
25+
}
26+
}
27+
28+
{
29+
mvc(new Controller());
30+
}
31+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.i3461;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
import io.jooby.openapi.OpenAPIResult;
11+
import io.jooby.openapi.OpenAPITest;
12+
13+
public class Issue3461 {
14+
15+
@OpenAPITest(value = App3461.class)
16+
public void shouldParseAvajeBeanScopeControllers(OpenAPIResult result) {
17+
assertEquals(
18+
"openapi: 3.0.1\n"
19+
+ "info:\n"
20+
+ " title: 3461 API\n"
21+
+ " description: 3461 API description\n"
22+
+ " version: \"1.0\"\n"
23+
+ "paths:\n"
24+
+ " /3461:\n"
25+
+ " get:\n"
26+
+ " operationId: getBlah\n"
27+
+ " parameters:\n"
28+
+ " - name: orgId\n"
29+
+ " in: query\n"
30+
+ " description: Param annotation\n"
31+
+ " required: true\n"
32+
+ " schema:\n"
33+
+ " type: string\n"
34+
+ " format: uuid\n"
35+
+ " responses:\n"
36+
+ " \"200\":\n"
37+
+ " description: Success\n"
38+
+ " content:\n"
39+
+ " application/json:\n"
40+
+ " schema:\n"
41+
+ " type: string\n",
42+
result.toYaml());
43+
}
44+
}

0 commit comments

Comments
 (0)