Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for managed JAX-RS subresource locators #2169

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading