File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed
modules/swagger-jaxrs2/src
main/java/io/swagger/v3/jaxrs2
test/java/io/swagger/v3/jaxrs2 Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 6969import java .util .Optional ;
7070import java .util .Set ;
7171import java .util .TreeSet ;
72+ import java .util .concurrent .CompletionStage ;
7273import java .util .stream .Collectors ;
7374
7475public class Reader implements OpenApiReader {
@@ -1071,7 +1072,7 @@ protected Operation parseMethod(
10711072 Type returnType = method .getGenericReturnType ();
10721073
10731074 if (annotatedMethod != null && annotatedMethod .getType () != null ) {
1074- returnType = annotatedMethod . getType ( );
1075+ returnType = extractTypeFromMethod ( annotatedMethod );
10751076 }
10761077
10771078 final Class <?> subResource = getSubResourceWithJaxRsSubresourceLocatorSpecs (method );
@@ -1133,6 +1134,14 @@ protected Operation parseMethod(
11331134 return operation ;
11341135 }
11351136
1137+ private Type extractTypeFromMethod (AnnotatedMethod annotatedMethod ) {
1138+ if (CompletionStage .class .isAssignableFrom (annotatedMethod .getType ().getRawClass ())) {
1139+ // CompletionStage's 1st generic type is the real return type.
1140+ return annotatedMethod .getType ().getBindings ().getBoundType (0 );
1141+ }
1142+ return annotatedMethod .getType ();
1143+ }
1144+
11361145 protected Content resolveEmptyContent (Produces classProduces , Produces methodProduces ) {
11371146 Content content = new Content ();
11381147 MediaType mediaType = new MediaType ();
Original file line number Diff line number Diff line change 125125import java .util .Map ;
126126import java .util .Optional ;
127127import java .util .Set ;
128+ import java .util .concurrent .CompletableFuture ;
129+ import java .util .concurrent .CompletionStage ;
128130import java .util .concurrent .CopyOnWriteArrayList ;
131+ import java .util .stream .Collectors ;
129132
130133import static org .testng .Assert .assertEquals ;
131134import static org .testng .Assert .assertFalse ;
@@ -717,6 +720,36 @@ public void test1(A a) {
717720 }
718721 }
719722
723+ @ Test
724+ public void testClassWithCompletableFuture () {
725+ Reader reader = new Reader (new OpenAPI ());
726+ OpenAPI openAPI = reader .read (ClassWithCompletableFuture .class );
727+ assertNotNull (openAPI );
728+
729+ assertEquals (
730+ openAPI .getPaths ()
731+ .get ("/myApi" )
732+ .getGet ()
733+ .getResponses ()
734+ .get ("default" )
735+ .getContent ()
736+ .get ("application/json" )
737+ .getSchema ()
738+ .get$ref (),
739+ "#/components/schemas/Ret"
740+ );
741+ }
742+
743+ static class ClassWithCompletableFuture {
744+ @ Path ("/myApi" )
745+ @ Produces ("application/json" )
746+ @ Consumes ("application/json" )
747+ @ GET
748+ public CompletableFuture <Ret > myApi (A a ) {
749+ return CompletableFuture .completedFuture (new Ret ());
750+ }
751+ }
752+
720753 @ Test (description = "test resource with array in response content" )
721754 public void test2497 () {
722755 Reader reader = new Reader (new OpenAPI ());
You can’t perform that action at this time.
0 commit comments