Skip to content

Commit

Permalink
Add support for managed JAX-RS subresource locators (#2169)
Browse files Browse the repository at this point in the history
* Add support for managed JAX-RS subresource locators

* Resolve the return type first

* Add tests for managed JAX-RS sub resource

---------

Co-authored-by: Brian Setz <[email protected]>
Co-authored-by: Michael Edgar <[email protected]>
  • Loading branch information
3 people authored Jan 22, 2025
1 parent 29a50ba commit e29e2d5
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,13 @@ private void processSubResource(final ClassInfo resourceClass,
OpenAPI openApi,
List<Parameter> locatorPathParameters,
Set<String> tagRefs) {
final Type methodReturnType = context.getResourceTypeResolver().resolve(method.returnType());

// Extract the method return type, if the method return type is Class<?> then extract the type parameter.
Type methodReturnType = context.getResourceTypeResolver().resolve(method.returnType());
if (methodReturnType.kind() == Type.Kind.PARAMETERIZED_TYPE
&& methodReturnType.asParameterizedType().name().equals(DotName.createSimple(Class.class))) {
methodReturnType = methodReturnType.asParameterizedType().arguments().get(0);
}

if (Type.Kind.VOID.equals(methodReturnType.kind())) {
// Can sub-resource locators return a CompletionStage?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void testJavaxResteasyMultipartInput() throws IOException, JSONException {
test.io.smallrye.openapi.runtime.scanner.javax.MainTestResource.class,
test.io.smallrye.openapi.runtime.scanner.javax.Sub1TestResource.class,
test.io.smallrye.openapi.runtime.scanner.javax.Sub2TestResource.class,
test.io.smallrye.openapi.runtime.scanner.javax.Sub3TestResource.class,
test.io.smallrye.openapi.runtime.scanner.javax.RecursiveLocatorResource.class);
}

Expand All @@ -42,6 +43,7 @@ void testJakartaResteasyMultipartInput() throws IOException, JSONException {
test.io.smallrye.openapi.runtime.scanner.jakarta.MainTestResource.class,
test.io.smallrye.openapi.runtime.scanner.jakarta.Sub1TestResource.class,
test.io.smallrye.openapi.runtime.scanner.jakarta.Sub2TestResource.class,
test.io.smallrye.openapi.runtime.scanner.jakarta.Sub3TestResource.class,
test.io.smallrye.openapi.runtime.scanner.jakarta.RecursiveLocatorResource.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ public Sub2TestResource<T> getSub2(@PathParam("sub2-id") String sub2Id) {
return new Sub2TestResource<T>();
}

@Path(value = "/sub3/{sub3-id}")
public Class<Sub3TestResource> getSub3(@PathParam("sub3-id") String sub3Id) {
return Sub3TestResource.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package test.io.smallrye.openapi.runtime.scanner.jakarta;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;

@SuppressWarnings(value = "unused")
public class Sub3TestResource {

@GET
@Path(value = "{subsubid}")
public String getSub3(@PathParam("sub3-id") String sub3Id, @PathParam(value = "subsubid") String subsubid) {
return "Sub3TestResource";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ public Sub2TestResource<T> getSub2(@PathParam("sub2-id") String sub2Id) {
return new Sub2TestResource<T>();
}

@Path(value = "/sub3/{sub3-id}")
public Class<Sub3TestResource> getSub3(@PathParam("sub3-id") String sub3Id) {
return Sub3TestResource.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package test.io.smallrye.openapi.runtime.scanner.javax;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

@SuppressWarnings(value = "unused")
public class Sub3TestResource {

@GET
@Path(value = "{subsubid}")
public String getSub3(@PathParam("sub3-id") String sub3Id, @PathParam(value = "subsubid") String subsubid) {
return "Sub3TestResource";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,93 @@
}
]
},
"/resource{resource}/sub/{id}{idMatrix}/sub3/{sub3-id}/{subsubid}" : {
"parameters" : [ {
"style" : "matrix",
"explode" : true,
"schema" : {
"type" : "object",
"properties" : {
"r0m0" : {
"$ref" : "#/components/schemas/LocalDateTime"
},
"r0m1" : {
"$ref" : "#/components/schemas/LocalDateTime"
}
}
},
"name" : "resource",
"in" : "path",
"required" : true
}, {
"description" : "Resource Identifier",
"name" : "id",
"in" : "path",
"required" : true,
"schema" : {
"type" : "string"
}
}, {
"style" : "matrix",
"explode" : true,
"schema" : {
"type" : "object",
"properties" : {
"m1" : {
"type" : "string"
},
"m2" : {
"type" : "integer",
"format" : "int32"
}
}
},
"name" : "idMatrix",
"in" : "path",
"required" : true
}, {
"name" : "q1",
"in" : "query",
"schema" : {
"type" : "string"
}
}, {
"name" : "q2",
"in" : "query",
"schema" : {
"type" : "string"
}
} ],
"get" : {
"parameters" : [ {
"name" : "sub3-id",
"in" : "path",
"required" : true,
"schema" : {
"type" : "string"
}
}, {
"name" : "subsubid",
"in" : "path",
"required" : true,
"schema" : {
"type" : "string"
}
} ],
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"*/*" : {
"schema" : {
"type" : "string"
}
}
}
}
}
}
},
"/resource{resource}/sub0": {
"get": {
"parameters": [
Expand Down

0 comments on commit e29e2d5

Please sign in to comment.