From 048f78e0c6893ffd7d90b98fc5f8a21e5607be5c Mon Sep 17 00:00:00 2001 From: Tim Quinn Date: Thu, 13 Oct 2022 11:39:59 -0500 Subject: [PATCH] Change generated MP server return type from `Response` to the document-indicated type (#72) Signed-off-by: tim.quinn@oracle.com Signed-off-by: tim.quinn@oracle.com --- .../languages/JavaHelidonCommonCodegen.java | 58 +++++++++++++++++++ .../server/libraries/mp/api.mustache | 3 +- .../server/libraries/mp/apiAbstract.mustache | 2 +- .../server/libraries/mp/apiImpl.mustache | 2 + .../server/libraries/mp/apiMethod.mustache | 19 +++++- .../mp/returnAsyncTypeInterface.mustache | 1 + .../server/libraries/mp/returnTypes.mustache | 2 +- .../JavaHelidonMpServerCodegenTest.java | 51 ++++++++++++++-- .../server/api/AnotherFakeService.java | 4 +- .../server/api/DefaultService.java | 4 +- .../api/FakeClassnameTags123Service.java | 4 +- .../openapitools/server/api/FakeService.java | 36 ++++++------ .../openapitools/server/api/PetService.java | 20 +++---- .../openapitools/server/api/StoreService.java | 10 ++-- .../openapitools/server/api/UserService.java | 18 +++--- 15 files changed, 170 insertions(+), 64 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/returnAsyncTypeInterface.mustache diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaHelidonCommonCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaHelidonCommonCodegen.java index 14495faceff..50519b08370 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaHelidonCommonCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaHelidonCommonCodegen.java @@ -24,8 +24,11 @@ import java.util.Locale; import java.util.Set; import java.util.stream.Collectors; +import io.swagger.v3.oas.models.Operation; +import io.swagger.v3.oas.models.servers.Server; import org.openapitools.codegen.CliOption; import org.openapitools.codegen.CodegenConstants; +import org.openapitools.codegen.CodegenOperation; import org.openapitools.codegen.SupportingFile; import org.openapitools.codegen.languages.features.BeanValidationFeatures; import org.openapitools.codegen.languages.features.PerformBeanValidationFeatures; @@ -52,6 +55,8 @@ public abstract class JavaHelidonCommonCodegen extends AbstractJavaCodegen static final String MICROPROFILE_ROOT_PACKAGE = "rootJavaEEPackage"; static final String MICROPROFILE_ROOT_DEP_PREFIX = "x-helidon-rootJavaEEDepPrefix"; + static final String X_HAS_RETURN_TYPE = "x-helidon-hasReturnType"; + static final String X_RETURN_TYPE_EXAMPLE_VALUE = "x-helidon-exampleReturnTypeValue"; static final String MICROPROFILE_ROOT_PACKAGE_DESC = "Root package name for Java EE"; static final String MICROPROFILE_ROOT_PACKAGE_JAVAX = "javax"; static final String MICROPROFILE_ROOT_PACKAGE_JAKARTA = "jakarta"; @@ -125,6 +130,14 @@ public abstract class JavaHelidonCommonCodegen extends AbstractJavaCodegen setEEPackageAndDependencies(helidonVersion); } + @Override + public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List servers) { + CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers); + op.vendorExtensions.put(X_HAS_RETURN_TYPE, op.returnType != null && !op.returnType.equals("void")); + op.vendorExtensions.put(X_RETURN_TYPE_EXAMPLE_VALUE, chooseExampleReturnTypeValue(op)); + return op; + } + /** * Remove set of options not currently used by any Helidon generator. Should be * called during construction but only on leaf classes. @@ -257,4 +270,49 @@ public abstract class JavaHelidonCommonCodegen extends AbstractJavaCodegen .collect(Collectors.toSet()); forRemoval.forEach(cliOptions::remove); } + + private String chooseExampleReturnTypeValue(CodegenOperation op) { + + // See DefaultCodegen#handleMethodResponse to see how the various op fields related to the return type are set. + if (op.returnType == null) { + return ""; // won't be used anyway in the templates + } + if (op.isMap) { + return "java.util.Collections.emptyMap()"; + } + if (op.isArray) { + return "java.util.Collections.emptyList()"; + } + switch (op.returnType) { + case "Integer": + return "new Integer(0)"; + + case "byte[]": + return "new byte[0]"; + + case "Float": + return "new Float(0.0f)"; + + case "boolean": + return "false"; + + case "Long": + return "new Long(0L)"; + + case "Object": + return "new Object()"; + + case "String": + return "\"\""; + + case "Boolean": + return "new Boolean(false)"; + + case "Double": + return "new Double(0.0d)"; + + default: + return "null"; + } + } } diff --git a/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/api.mustache b/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/api.mustache index 5527f4d8165..495b0cc7599 100644 --- a/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/api.mustache +++ b/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/api.mustache @@ -5,8 +5,9 @@ package {{package}}; {{/imports}} import {{rootJavaEEPackage}}.ws.rs.*; +{{#returnResponse}} import {{rootJavaEEPackage}}.ws.rs.core.Response; - +{{/returnResponse}} {{#supportAsync}} import java.util.concurrent.CompletionStage; import java.util.concurrent.CompletableFuture; diff --git a/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/apiAbstract.mustache b/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/apiAbstract.mustache index bbed9724d48..a2d82121b02 100644 --- a/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/apiAbstract.mustache +++ b/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/apiAbstract.mustache @@ -2,4 +2,4 @@ @Path("{{{path}}}"){{/subresourceOperation}}{{#hasConsumes}} @Consumes({ {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }){{/hasConsumes}}{{#hasProduces}} @Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }){{/hasProduces}} - abstract {{#supportAsync}}{{>returnAsyncTypeInterface}}{{/supportAsync}}{{^supportAsync}}Response{{/supportAsync}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}}, {{/-last}}{{/allParams}}); \ No newline at end of file + {{#useAbstractClass}}abstract {{/useAbstractClass}}{{#supportAsync}}{{>returnAsyncTypeInterface}}{{/supportAsync}}{{^supportAsync}}{{>returnTypes}}{{/supportAsync}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}}, {{/-last}}{{/allParams}}); \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/apiImpl.mustache b/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/apiImpl.mustache index 140daa53eb2..9c9db82b249 100644 --- a/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/apiImpl.mustache +++ b/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/apiImpl.mustache @@ -5,7 +5,9 @@ package {{package}}; {{/imports}} import {{rootJavaEEPackage}}.ws.rs.*; +{{#returnResponse}} import {{rootJavaEEPackage}}.ws.rs.core.Response; +{{/returnResponse}} {{#supportAsync}} import java.util.concurrent.CompletionStage; diff --git a/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/apiMethod.mustache b/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/apiMethod.mustache index 96387ec48e0..b1c07572f6c 100644 --- a/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/apiMethod.mustache +++ b/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/apiMethod.mustache @@ -2,6 +2,21 @@ @Path("{{{path}}}"){{/subresourceOperation}}{{#hasConsumes}} @Consumes({ {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }){{/hasConsumes}}{{#hasProduces}} @Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }){{/hasProduces}} - public {{#supportAsync}}CompletionStage<{{/supportAsync}}Response{{#supportAsync}}>{{/supportAsync}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}) { - return {{#supportAsync}}CompletableFuture.supplyAsync(() -> {{/supportAsync}}Response.ok().entity("magic!").build(){{#supportAsync}}){{/supportAsync}}; + public {{#supportAsync}}{{>returnAsyncTypeInterface}}{{/supportAsync}}{{^supportAsync}}{{>returnTypes}}{{/supportAsync}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}) { + {{#returnResponse}} + return {{#supportAsync}}CompletableFuture.supplyAsync(() -> {{/supportAsync}}Response.ok({{#vendorExtensions.x-helidon-hasReturnType}}/* Pass {{{returnType}}} entity payload */{{/vendorExtensions.x-helidon-hasReturnType}}).build(){{#supportAsync}}){{/supportAsync}}; // Replace with correct business logic. + {{/returnResponse}} + {{^returnResponse}} + {{#vendorExtensions.x-helidon-hasReturnType}} + {{{returnType}}} result = {{{vendorExtensions.x-helidon-exampleReturnTypeValue}}}; // Replace with correct business logic. + {{/vendorExtensions.x-helidon-hasReturnType}} + {{#supportAsync}} + return CompletableFuture.supplyAsync(() -> {{#vendorExtensions.x-helidon-hasReturnType}}result{{/vendorExtensions.x-helidon-hasReturnType}}{{^vendorExtensions.x-helidon-hasReturnType}}null{{/vendorExtensions.x-helidon-hasReturnType}}); + {{/supportAsync}} + {{^supportAsync}} + {{#vendorExtensions.x-helidon-hasReturnType}} + return result; + {{/vendorExtensions.x-helidon-hasReturnType}} + {{/supportAsync}} + {{/returnResponse}} } \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/returnAsyncTypeInterface.mustache b/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/returnAsyncTypeInterface.mustache new file mode 100644 index 00000000000..0da348c7a22 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/returnAsyncTypeInterface.mustache @@ -0,0 +1 @@ +CompletionStage<{{#returnResponse}}Response{{/returnResponse}}{{^returnResponse}}{{#returnContainer}}{{#isMap}}Map{{/isMap}}{{#isArray}}{{{returnContainer}}}<{{{returnBaseType}}}>{{/isArray}}{{/returnContainer}}{{^returnContainer}}{{{returnBaseType}}}{{/returnContainer}}{{/returnResponse}}> \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/returnTypes.mustache b/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/returnTypes.mustache index 433b7334785..87831bd299e 100644 --- a/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/returnTypes.mustache +++ b/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/returnTypes.mustache @@ -1 +1 @@ -{{#returnContainer}}{{#isMap}}Map{{/isMap}}{{#isArray}}{{{returnContainer}}}<{{{returnType}}}>{{/isArray}}{{/returnContainer}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}} \ No newline at end of file +{{#returnResponse}}Response{{/returnResponse}}{{^returnResponse}}{{#returnContainer}}{{#isMap}}Map{{/isMap}}{{#isArray}}{{{returnContainer}}}<{{{returnBaseType}}}>{{/isArray}}{{/returnContainer}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}{{/returnResponse}} \ No newline at end of file diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/helidon/JavaHelidonMpServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/helidon/JavaHelidonMpServerCodegenTest.java index 8f278b64ac4..312d2f9d855 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/helidon/JavaHelidonMpServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/helidon/JavaHelidonMpServerCodegenTest.java @@ -29,6 +29,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Objects; +import java.util.concurrent.CompletableFuture; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -111,13 +112,13 @@ public class JavaHelidonMpServerCodegenTest { .fileContains("public abstract class StoreService") .assertMethod("placeOrder", "Order") .doesNotHaveImplementation() - .hasReturnType("Response"); + .hasReturnType("Order"); JavaFileAssert.assertThat(Paths.get(apiPackage + "/StoreServiceImpl.java")) .fileContains("public class StoreServiceImpl extends StoreService") .assertMethod("placeOrder", "Order") - .hasReturnType("Response") - .bodyContainsLines("return Response.ok().entity(\"magic!\").build();"); + .hasReturnType("Order") + .bodyContainsLines("Order result = null; // Replace with correct business logic.", "return result;"); } @Test @@ -131,7 +132,7 @@ public class JavaHelidonMpServerCodegenTest { JavaFileAssert.assertThat(Paths.get(apiPackage + "/StoreService.java")) .fileContains("public interface StoreService") .assertMethod("placeOrder", "Order") - .hasReturnType("Response"); + .hasReturnType("Order"); } @Test @@ -206,4 +207,46 @@ public class JavaHelidonMpServerCodegenTest { TestUtils.assertFileNotExists(Paths.get(outputPath + "/pom.xml")); } + @Test + public void testReturnResponse() { + generate(createConfigurator().addAdditionalProperty("returnResponse", "true")); + + JavaFileAssert.assertThat(Paths.get(apiPackage + "/PetService.java")) + .fileContains("public interface PetService") + .assertMethod("addPet", "Pet") + .hasReturnType("Response"); + JavaFileAssert.assertThat(Paths.get(apiPackage + "/PetService.java")) + .fileContains("public interface PetService") + .assertMethod("deletePet", "Long", "String", "Long", "String", "Integer", "List", "List") + .hasReturnType("Response"); + + JavaFileAssert.assertThat(Paths.get(apiPackage + "/PetServiceImpl.java")) + .fileContains("public class PetServiceImpl implements PetService") + .assertMethod("addPet", "Pet") + .hasReturnType("Response") + .bodyContainsLines("return Response.ok(/* Pass Pet entity payload */).build(); " + + "// Replace with correct business logic."); + } + + @Test + public void testSupportAsync() { + generate(createConfigurator().addAdditionalProperty("supportAsync", "true")); + + JavaFileAssert.assertThat(Paths.get(apiPackage + "/PetService.java")) + .fileContains("public interface PetService") + .assertMethod("addPet", "Pet") + .hasReturnType("CompletionStage"); + JavaFileAssert.assertThat(Paths.get(apiPackage + "/PetService.java")) + .fileContains("public interface PetService") + .assertMethod("deletePet", "Long", "String", "Long", "String", "Integer", "List", "List") + .hasReturnType("CompletionStage"); + + JavaFileAssert.assertThat(Paths.get(apiPackage + "/PetServiceImpl.java")) + .fileContains("public class PetServiceImpl implements PetService") + .assertMethod("addPet", "Pet") + .hasReturnType("CompletionStage") + .bodyContainsLines("Pet result = null; // Replace with correct business logic.", + "return CompletableFuture.supplyAsync(() -> result);"); + } + } \ No newline at end of file diff --git a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/AnotherFakeService.java b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/AnotherFakeService.java index 2055dd67fb9..259be05eb53 100644 --- a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/AnotherFakeService.java +++ b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/AnotherFakeService.java @@ -15,8 +15,6 @@ package org.openapitools.server.api; import org.openapitools.server.model.Client; import jakarta.ws.rs.*; -import jakarta.ws.rs.core.Response; - import java.io.InputStream; import java.util.Map; @@ -31,5 +29,5 @@ public interface AnotherFakeService { @PATCH @Consumes({ "application/json" }) @Produces({ "application/json" }) - abstract Response call123testSpecialTags(@Valid @NotNull Client client); + Client call123testSpecialTags(@Valid @NotNull Client client); } diff --git a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/DefaultService.java b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/DefaultService.java index 9051caf6f98..d5c2422a841 100644 --- a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/DefaultService.java +++ b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/DefaultService.java @@ -15,8 +15,6 @@ package org.openapitools.server.api; import org.openapitools.server.model.FooGetDefaultResponse; import jakarta.ws.rs.*; -import jakarta.ws.rs.core.Response; - import java.io.InputStream; import java.util.Map; @@ -30,5 +28,5 @@ public interface DefaultService { @GET @Produces({ "application/json" }) - abstract Response fooGet(); + FooGetDefaultResponse fooGet(); } diff --git a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/FakeClassnameTags123Service.java b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/FakeClassnameTags123Service.java index 76291169a5a..0a3aebe9026 100644 --- a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/FakeClassnameTags123Service.java +++ b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/FakeClassnameTags123Service.java @@ -15,8 +15,6 @@ package org.openapitools.server.api; import org.openapitools.server.model.Client; import jakarta.ws.rs.*; -import jakarta.ws.rs.core.Response; - import java.io.InputStream; import java.util.Map; @@ -31,5 +29,5 @@ public interface FakeClassnameTags123Service { @PATCH @Consumes({ "application/json" }) @Produces({ "application/json" }) - abstract Response testClassname(@Valid @NotNull Client client); + Client testClassname(@Valid @NotNull Client client); } diff --git a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/FakeService.java b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/FakeService.java index c7ab3fa2595..130451d090f 100644 --- a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/FakeService.java +++ b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/FakeService.java @@ -27,8 +27,6 @@ import org.openapitools.server.model.Pet; import org.openapitools.server.model.User; import jakarta.ws.rs.*; -import jakarta.ws.rs.core.Response; - import java.io.InputStream; import java.util.Map; @@ -43,85 +41,85 @@ public interface FakeService { @GET @Path("/health") @Produces({ "application/json" }) - abstract Response fakeHealthGet(); + HealthCheckResult fakeHealthGet(); @GET @Path("/http-signature-test") @Consumes({ "application/json", "application/xml" }) - abstract Response fakeHttpSignatureTest(@Valid @NotNull Pet pet, @QueryParam("query_1") String query1, @HeaderParam("header_1") String header1); + void fakeHttpSignatureTest(@Valid @NotNull Pet pet, @QueryParam("query_1") String query1, @HeaderParam("header_1") String header1); @POST @Path("/outer/boolean") @Consumes({ "application/json" }) @Produces({ "*/*" }) - abstract Response fakeOuterBooleanSerialize(@Valid Boolean body); + Boolean fakeOuterBooleanSerialize(@Valid Boolean body); @POST @Path("/outer/composite") @Consumes({ "application/json" }) @Produces({ "*/*" }) - abstract Response fakeOuterCompositeSerialize(@Valid OuterComposite outerComposite); + OuterComposite fakeOuterCompositeSerialize(@Valid OuterComposite outerComposite); @POST @Path("/outer/number") @Consumes({ "application/json" }) @Produces({ "*/*" }) - abstract Response fakeOuterNumberSerialize(@Valid BigDecimal body); + BigDecimal fakeOuterNumberSerialize(@Valid BigDecimal body); @POST @Path("/outer/string") @Consumes({ "application/json" }) @Produces({ "*/*" }) - abstract Response fakeOuterStringSerialize(@Valid String body); + String fakeOuterStringSerialize(@Valid String body); @POST @Path("/property/enum-int") @Consumes({ "application/json" }) @Produces({ "*/*" }) - abstract Response fakePropertyEnumIntegerSerialize(@Valid @NotNull OuterObjectWithEnumProperty outerObjectWithEnumProperty); + OuterObjectWithEnumProperty fakePropertyEnumIntegerSerialize(@Valid @NotNull OuterObjectWithEnumProperty outerObjectWithEnumProperty); @PUT @Path("/body-with-binary") @Consumes({ "image/png" }) - abstract Response testBodyWithBinary(@Valid File body); + void testBodyWithBinary(@Valid File body); @PUT @Path("/body-with-file-schema") @Consumes({ "application/json" }) - abstract Response testBodyWithFileSchema(@Valid @NotNull FileSchemaTestClass fileSchemaTestClass); + void testBodyWithFileSchema(@Valid @NotNull FileSchemaTestClass fileSchemaTestClass); @PUT @Path("/body-with-query-params") @Consumes({ "application/json" }) - abstract Response testBodyWithQueryParams(@QueryParam("query") @NotNull String query, @Valid @NotNull User user); + void testBodyWithQueryParams(@QueryParam("query") @NotNull String query, @Valid @NotNull User user); @PATCH @Consumes({ "application/json" }) @Produces({ "application/json" }) - abstract Response testClientModel(@Valid @NotNull Client client); + Client testClientModel(@Valid @NotNull Client client); @POST @Consumes({ "application/x-www-form-urlencoded" }) - abstract Response testEndpointParameters(@FormParam(value = "number") BigDecimal number, @FormParam(value = "double") Double _double, @FormParam(value = "pattern_without_delimiter") String patternWithoutDelimiter, @FormParam(value = "byte") byte[] _byte, @FormParam(value = "integer") Integer integer, @FormParam(value = "int32") Integer int32, @FormParam(value = "int64") Long int64, @FormParam(value = "float") Float _float, @FormParam(value = "string") String string, @FormParam(value = "binary") InputStream binaryInputStream, @FormParam(value = "date") LocalDate date, @FormParam(value = "dateTime") OffsetDateTime dateTime, @FormParam(value = "password") String password, @FormParam(value = "callback") String paramCallback); + void testEndpointParameters(@FormParam(value = "number") BigDecimal number, @FormParam(value = "double") Double _double, @FormParam(value = "pattern_without_delimiter") String patternWithoutDelimiter, @FormParam(value = "byte") byte[] _byte, @FormParam(value = "integer") Integer integer, @FormParam(value = "int32") Integer int32, @FormParam(value = "int64") Long int64, @FormParam(value = "float") Float _float, @FormParam(value = "string") String string, @FormParam(value = "binary") InputStream binaryInputStream, @FormParam(value = "date") LocalDate date, @FormParam(value = "dateTime") OffsetDateTime dateTime, @FormParam(value = "password") String password, @FormParam(value = "callback") String paramCallback); @GET @Consumes({ "application/x-www-form-urlencoded" }) - abstract Response testEnumParameters(@HeaderParam("enum_header_string_array") List enumHeaderStringArray, @HeaderParam("enum_header_string") @DefaultValue("-efg") String enumHeaderString, @QueryParam("enum_query_string_array") List enumQueryStringArray, @QueryParam("enum_query_string") @DefaultValue("-efg") String enumQueryString, @QueryParam("enum_query_integer") Integer enumQueryInteger, @QueryParam("enum_query_double") Double enumQueryDouble, @QueryParam("enum_query_model_array") List enumQueryModelArray, @FormParam(value = "enum_form_string_array") List enumFormStringArray, @FormParam(value = "enum_form_string") String enumFormString); + void testEnumParameters(@HeaderParam("enum_header_string_array") List enumHeaderStringArray, @HeaderParam("enum_header_string") @DefaultValue("-efg") String enumHeaderString, @QueryParam("enum_query_string_array") List enumQueryStringArray, @QueryParam("enum_query_string") @DefaultValue("-efg") String enumQueryString, @QueryParam("enum_query_integer") Integer enumQueryInteger, @QueryParam("enum_query_double") Double enumQueryDouble, @QueryParam("enum_query_model_array") List enumQueryModelArray, @FormParam(value = "enum_form_string_array") List enumFormStringArray, @FormParam(value = "enum_form_string") String enumFormString); @DELETE - abstract Response testGroupParameters(@QueryParam("required_string_group") @NotNull Integer requiredStringGroup, @HeaderParam("required_boolean_group") @NotNull Boolean requiredBooleanGroup, @QueryParam("required_int64_group") @NotNull Long requiredInt64Group, @QueryParam("string_group") Integer stringGroup, @HeaderParam("boolean_group") Boolean booleanGroup, @QueryParam("int64_group") Long int64Group); + void testGroupParameters(@QueryParam("required_string_group") @NotNull Integer requiredStringGroup, @HeaderParam("required_boolean_group") @NotNull Boolean requiredBooleanGroup, @QueryParam("required_int64_group") @NotNull Long requiredInt64Group, @QueryParam("string_group") Integer stringGroup, @HeaderParam("boolean_group") Boolean booleanGroup, @QueryParam("int64_group") Long int64Group); @POST @Path("/inline-additionalProperties") @Consumes({ "application/json" }) - abstract Response testInlineAdditionalProperties(@Valid @NotNull Map requestBody); + void testInlineAdditionalProperties(@Valid @NotNull Map requestBody); @GET @Path("/jsonFormData") @Consumes({ "application/x-www-form-urlencoded" }) - abstract Response testJsonFormData(@FormParam(value = "param") String param, @FormParam(value = "param2") String param2); + void testJsonFormData(@FormParam(value = "param") String param, @FormParam(value = "param2") String param2); @PUT @Path("/test-query-parameters") - abstract Response testQueryParameterCollectionFormat(@QueryParam("pipe") @NotNull List pipe, @QueryParam("ioutil") @NotNull List ioutil, @QueryParam("http") @NotNull List http, @QueryParam("url") @NotNull List url, @QueryParam("context") @NotNull List context, @QueryParam("allowEmpty") @NotNull String allowEmpty, @QueryParam("language") Map language); + void testQueryParameterCollectionFormat(@QueryParam("pipe") @NotNull List pipe, @QueryParam("ioutil") @NotNull List ioutil, @QueryParam("http") @NotNull List http, @QueryParam("url") @NotNull List url, @QueryParam("context") @NotNull List context, @QueryParam("allowEmpty") @NotNull String allowEmpty, @QueryParam("language") Map language); } diff --git a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/PetService.java b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/PetService.java index 5396af911b6..20b812611b5 100644 --- a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/PetService.java +++ b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/PetService.java @@ -18,8 +18,6 @@ import org.openapitools.server.model.Pet; import java.util.Set; import jakarta.ws.rs.*; -import jakarta.ws.rs.core.Response; - import java.io.InputStream; import java.util.Map; @@ -34,46 +32,46 @@ public interface PetService { @POST @Path("/pet") @Consumes({ "application/json", "application/xml" }) - abstract Response addPet(@Valid @NotNull Pet pet); + void addPet(@Valid @NotNull Pet pet); @DELETE @Path("/pet/{petId}") - abstract Response deletePet(@PathParam("petId") Long petId, @HeaderParam("api_key") String apiKey); + void deletePet(@PathParam("petId") Long petId, @HeaderParam("api_key") String apiKey); @GET @Path("/pet/findByStatus") @Produces({ "application/xml", "application/json" }) - abstract Response findPetsByStatus(@QueryParam("status") @NotNull List status); + List findPetsByStatus(@QueryParam("status") @NotNull List status); @GET @Path("/pet/findByTags") @Produces({ "application/xml", "application/json" }) - abstract Response findPetsByTags(@QueryParam("tags") @NotNull Set tags); + Set findPetsByTags(@QueryParam("tags") @NotNull Set tags); @GET @Path("/pet/{petId}") @Produces({ "application/xml", "application/json" }) - abstract Response getPetById(@PathParam("petId") Long petId); + Pet getPetById(@PathParam("petId") Long petId); @PUT @Path("/pet") @Consumes({ "application/json", "application/xml" }) - abstract Response updatePet(@Valid @NotNull Pet pet); + void updatePet(@Valid @NotNull Pet pet); @POST @Path("/pet/{petId}") @Consumes({ "application/x-www-form-urlencoded" }) - abstract Response updatePetWithForm(@PathParam("petId") Long petId, @FormParam(value = "name") String name, @FormParam(value = "status") String status); + void updatePetWithForm(@PathParam("petId") Long petId, @FormParam(value = "name") String name, @FormParam(value = "status") String status); @POST @Path("/pet/{petId}/uploadImage") @Consumes({ "multipart/form-data" }) @Produces({ "application/json" }) - abstract Response uploadFile(@PathParam("petId") Long petId, @FormParam(value = "additionalMetadata") String additionalMetadata, @FormParam(value = "file") InputStream _fileInputStream); + ModelApiResponse uploadFile(@PathParam("petId") Long petId, @FormParam(value = "additionalMetadata") String additionalMetadata, @FormParam(value = "file") InputStream _fileInputStream); @POST @Path("/fake/{petId}/uploadImageWithRequiredFile") @Consumes({ "multipart/form-data" }) @Produces({ "application/json" }) - abstract Response uploadFileWithRequiredFile(@PathParam("petId") Long petId, @FormParam(value = "requiredFile") InputStream requiredFileInputStream, @FormParam(value = "additionalMetadata") String additionalMetadata); + ModelApiResponse uploadFileWithRequiredFile(@PathParam("petId") Long petId, @FormParam(value = "requiredFile") InputStream requiredFileInputStream, @FormParam(value = "additionalMetadata") String additionalMetadata); } diff --git a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/StoreService.java b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/StoreService.java index df03b4c69c0..a2bc50a77bd 100644 --- a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/StoreService.java +++ b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/StoreService.java @@ -16,8 +16,6 @@ import java.util.Map; import org.openapitools.server.model.Order; import jakarta.ws.rs.*; -import jakarta.ws.rs.core.Response; - import java.io.InputStream; import java.util.Map; @@ -31,21 +29,21 @@ public interface StoreService { @DELETE @Path("/order/{order_id}") - abstract Response deleteOrder(@PathParam("order_id") String orderId); + void deleteOrder(@PathParam("order_id") String orderId); @GET @Path("/inventory") @Produces({ "application/json" }) - abstract Response getInventory(); + Map getInventory(); @GET @Path("/order/{order_id}") @Produces({ "application/xml", "application/json" }) - abstract Response getOrderById(@PathParam("order_id") @Min(1L) @Max(5L) Long orderId); + Order getOrderById(@PathParam("order_id") @Min(1L) @Max(5L) Long orderId); @POST @Path("/order") @Consumes({ "application/json" }) @Produces({ "application/xml", "application/json" }) - abstract Response placeOrder(@Valid @NotNull Order order); + Order placeOrder(@Valid @NotNull Order order); } diff --git a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/UserService.java b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/UserService.java index 3d7b81dcea8..3b907684f9a 100644 --- a/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/UserService.java +++ b/samples/server/petstore/java-helidon-server/mp/src/main/java/org/openapitools/server/api/UserService.java @@ -17,8 +17,6 @@ import java.time.OffsetDateTime; import org.openapitools.server.model.User; import jakarta.ws.rs.*; -import jakarta.ws.rs.core.Response; - import java.io.InputStream; import java.util.Map; @@ -32,38 +30,38 @@ public interface UserService { @POST @Consumes({ "application/json" }) - abstract Response createUser(@Valid @NotNull User user); + void createUser(@Valid @NotNull User user); @POST @Path("/createWithArray") @Consumes({ "application/json" }) - abstract Response createUsersWithArrayInput(@Valid @NotNull List user); + void createUsersWithArrayInput(@Valid @NotNull List user); @POST @Path("/createWithList") @Consumes({ "application/json" }) - abstract Response createUsersWithListInput(@Valid @NotNull List user); + void createUsersWithListInput(@Valid @NotNull List user); @DELETE @Path("/{username}") - abstract Response deleteUser(@PathParam("username") String username); + void deleteUser(@PathParam("username") String username); @GET @Path("/{username}") @Produces({ "application/xml", "application/json" }) - abstract Response getUserByName(@PathParam("username") String username); + User getUserByName(@PathParam("username") String username); @GET @Path("/login") @Produces({ "application/xml", "application/json" }) - abstract Response loginUser(@QueryParam("username") @NotNull String username, @QueryParam("password") @NotNull String password); + String loginUser(@QueryParam("username") @NotNull String username, @QueryParam("password") @NotNull String password); @GET @Path("/logout") - abstract Response logoutUser(); + void logoutUser(); @PUT @Path("/{username}") @Consumes({ "application/json" }) - abstract Response updateUser(@PathParam("username") String username, @Valid @NotNull User user); + void updateUser(@PathParam("username") String username, @Valid @NotNull User user); }