This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit dcee4097b14b7493b7885cf3a3b32e44828616fe Author: wujimin <[email protected]> AuthorDate: Thu Dec 21 11:30:53 2017 +0800 JAV-582 support generate swagger from return CompletableFuture method --- .../response/CompletableFutureProcessor.java | 27 +++++++++++++++++++ ...mb.swagger.generator.core.ResponseTypeProcessor | 18 +++++++++++++ .../swagger/generator/core/TestSwaggerUtils.java | 5 ++++ .../response/TestCompletableFutureProcessor.java | 31 ++++++++++++++++++++++ .../swagger/generator/core/schema/Schema.java | 5 ++++ .../src/test/resources/schemas/allMethod.yaml | 9 +++++++ .../test/resources/schemas/completableFuture.yaml | 21 +++++++++++++++ 7 files changed, 116 insertions(+) diff --git a/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/generator/core/processor/response/CompletableFutureProcessor.java b/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/generator/core/processor/response/CompletableFutureProcessor.java new file mode 100644 index 0000000..bd745c5 --- /dev/null +++ b/swagger/swagger-generator/generator-core/src/main/java/io/servicecomb/swagger/generator/core/processor/response/CompletableFutureProcessor.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.servicecomb.swagger.generator.core.processor.response; + +import java.util.concurrent.CompletableFuture; + +public class CompletableFutureProcessor extends AbstractOneGenericResponseProcessor { + @Override + public Class<?> getResponseType() { + return CompletableFuture.class; + } +} diff --git a/swagger/swagger-generator/generator-core/src/main/resources/META-INF/services/io.servicecomb.swagger.generator.core.ResponseTypeProcessor b/swagger/swagger-generator/generator-core/src/main/resources/META-INF/services/io.servicecomb.swagger.generator.core.ResponseTypeProcessor new file mode 100644 index 0000000..7f9c7b8 --- /dev/null +++ b/swagger/swagger-generator/generator-core/src/main/resources/META-INF/services/io.servicecomb.swagger.generator.core.ResponseTypeProcessor @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +io.servicecomb.swagger.generator.core.processor.response.CompletableFutureProcessor \ No newline at end of file diff --git a/swagger/swagger-generator/generator-core/src/test/java/io/servicecomb/swagger/generator/core/TestSwaggerUtils.java b/swagger/swagger-generator/generator-core/src/test/java/io/servicecomb/swagger/generator/core/TestSwaggerUtils.java index 1b523ad..94aa039 100644 --- a/swagger/swagger-generator/generator-core/src/test/java/io/servicecomb/swagger/generator/core/TestSwaggerUtils.java +++ b/swagger/swagger-generator/generator-core/src/test/java/io/servicecomb/swagger/generator/core/TestSwaggerUtils.java @@ -213,6 +213,11 @@ public class TestSwaggerUtils { } @Test + public void testCompletableFuture() { + testSchemaMethod("completableFuture", "testCompletableFuture"); + } + + @Test public void testDate() { SwaggerGenerator generator = testSchemaMethod("date", "testDate"); JavassistUtils.detach("gen.cse.ms.ut.SchemaIntf"); diff --git a/swagger/swagger-generator/generator-core/src/test/java/io/servicecomb/swagger/generator/core/processor/response/TestCompletableFutureProcessor.java b/swagger/swagger-generator/generator-core/src/test/java/io/servicecomb/swagger/generator/core/processor/response/TestCompletableFutureProcessor.java new file mode 100644 index 0000000..294b8d5 --- /dev/null +++ b/swagger/swagger-generator/generator-core/src/test/java/io/servicecomb/swagger/generator/core/processor/response/TestCompletableFutureProcessor.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.servicecomb.swagger.generator.core.processor.response; + +import java.util.concurrent.CompletableFuture; + +import org.junit.Assert; +import org.junit.Test; + +public class TestCompletableFutureProcessor { + CompletableFutureProcessor processor = new CompletableFutureProcessor(); + + @Test + public void getResponseType() { + Assert.assertEquals(CompletableFuture.class, processor.getResponseType()); + } +} diff --git a/swagger/swagger-generator/generator-core/src/test/java/io/servicecomb/swagger/generator/core/schema/Schema.java b/swagger/swagger-generator/generator-core/src/test/java/io/servicecomb/swagger/generator/core/schema/Schema.java index 95d09d6..914c0de 100644 --- a/swagger/swagger-generator/generator-core/src/test/java/io/servicecomb/swagger/generator/core/schema/Schema.java +++ b/swagger/swagger-generator/generator-core/src/test/java/io/servicecomb/swagger/generator/core/schema/Schema.java @@ -22,6 +22,7 @@ import java.util.Date; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.CompletableFuture; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; @@ -156,6 +157,10 @@ public class Schema { } + public CompletableFuture<String> testCompletableFuture() { + return null; + } + public void testAllType(AllType obj) { } diff --git a/swagger/swagger-generator/generator-core/src/test/resources/schemas/allMethod.yaml b/swagger/swagger-generator/generator-core/src/test/resources/schemas/allMethod.yaml index 3514fa8..0ab203d 100644 --- a/swagger/swagger-generator/generator-core/src/test/resources/schemas/allMethod.yaml +++ b/swagger/swagger-generator/generator-core/src/test/resources/schemas/allMethod.yaml @@ -209,6 +209,15 @@ paths: responses: 200: description: "response of 200" + /testCompletableFuture: + post: + operationId: "testCompletableFuture" + parameters: [] + responses: + 200: + description: "response of 200" + schema: + type: "string" /testDouble: post: operationId: "testDouble" diff --git a/swagger/swagger-generator/generator-core/src/test/resources/schemas/completableFuture.yaml b/swagger/swagger-generator/generator-core/src/test/resources/schemas/completableFuture.yaml new file mode 100644 index 0000000..3168264 --- /dev/null +++ b/swagger/swagger-generator/generator-core/src/test/resources/schemas/completableFuture.yaml @@ -0,0 +1,21 @@ +--- +swagger: "2.0" +info: + version: "1.0.0" + title: "swagger definition for io.servicecomb.swagger.generator.core.schema.Schema" + x-java-interface: "gen.cse.ms.ut.SchemaIntf" +basePath: "/Schema" +consumes: +- "application/json" +produces: +- "application/json" +paths: + /testCompletableFuture: + post: + operationId: "testCompletableFuture" + parameters: [] + responses: + 200: + description: "response of 200" + schema: + type: "string" -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
