From a5952bfb104e89804ebc7b26cb61d8f3b13ded80 Mon Sep 17 00:00:00 2001 From: Antoine Reilles Date: Tue, 1 Mar 2022 17:17:11 +0100 Subject: [PATCH] [jaxrs-cxf-cdi] mark deprecated api methods (#11755) In the generated java code, it is usefull to have the generated java api use the @Deprecated annotation. This enable to leverage this annotation at runtime to trigger specific logging for instance. In the generated interface, use the @Deprecated annotation. Also, in the jax-rs implementation that links the jax-rs api with the cdi bean implementing the interface, use the @SuppressWarnings("deprecation") annotation. This way the deprecation warning is not shown in generated code. One can use the interface as before: the java compiler can then tell which implementations do implement a deprecated api, using a warning. If the implementation itself also sets the @Deprecated annotation, then there is no warning, unless the implementation is called at another place in the code. --- .../src/main/resources/JavaJaxRS/cxf-cdi/api.mustache | 3 ++- .../src/main/resources/JavaJaxRS/cxf-cdi/apiService.mustache | 2 +- .../src/gen/java/org/openapitools/api/PetApi.java | 1 + .../src/gen/java/org/openapitools/api/PetApiService.java | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf-cdi/api.mustache b/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf-cdi/api.mustache index a3c9c9721ee..b41c719f994 100644 --- a/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf-cdi/api.mustache +++ b/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf-cdi/api.mustache @@ -44,7 +44,8 @@ public class {{classname}} { {{#subresourceOperation}}@Path("{{{path}}}"){{/subresourceOperation}} {{#hasConsumes}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }){{/hasConsumes}} {{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }){{/hasProduces}} - @ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnBaseType}}}.class{{#returnContainer}}, responseContainer = "{{{.}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { + {{#isDeprecated}}@SuppressWarnings("deprecation") + {{/isDeprecated}}@ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnBaseType}}}.class{{#returnContainer}}, responseContainer = "{{{.}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { {{#authMethods}}{{#isOAuth}}@Authorization(value = "{{name}}", scopes = { {{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{^-last}}, {{/-last}}{{/scopes}} }){{^-last}},{{/-last}}{{/isOAuth}} diff --git a/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf-cdi/apiService.mustache b/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf-cdi/apiService.mustache index 4af44698b7c..17fd0813dd3 100644 --- a/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf-cdi/apiService.mustache +++ b/modules/openapi-generator/src/main/resources/JavaJaxRS/cxf-cdi/apiService.mustache @@ -20,7 +20,7 @@ import javax.ws.rs.core.SecurityContext; {{#operations}} public interface {{classname}}Service { {{#operation}} - public Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}}, {{/allParams}}SecurityContext securityContext); + {{#isDeprecated}}@Deprecated {{/isDeprecated}}public Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}}, {{/allParams}}SecurityContext securityContext); {{/operation}} } {{/operations}} diff --git a/samples/server/petstore/jaxrs-cxf-cdi/src/gen/java/org/openapitools/api/PetApi.java b/samples/server/petstore/jaxrs-cxf-cdi/src/gen/java/org/openapitools/api/PetApi.java index 7a6eb967684..76d6eb42505 100644 --- a/samples/server/petstore/jaxrs-cxf-cdi/src/gen/java/org/openapitools/api/PetApi.java +++ b/samples/server/petstore/jaxrs-cxf-cdi/src/gen/java/org/openapitools/api/PetApi.java @@ -87,6 +87,7 @@ public class PetApi { @Path("/findByTags") @Produces({ "application/xml", "application/json" }) + @SuppressWarnings("deprecation") @ApiOperation(value = "Finds Pets by tags", notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List", authorizations = { @Authorization(value = "petstore_auth", scopes = { @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), diff --git a/samples/server/petstore/jaxrs-cxf-cdi/src/gen/java/org/openapitools/api/PetApiService.java b/samples/server/petstore/jaxrs-cxf-cdi/src/gen/java/org/openapitools/api/PetApiService.java index 9b859d24f59..7272b6076d0 100644 --- a/samples/server/petstore/jaxrs-cxf-cdi/src/gen/java/org/openapitools/api/PetApiService.java +++ b/samples/server/petstore/jaxrs-cxf-cdi/src/gen/java/org/openapitools/api/PetApiService.java @@ -22,7 +22,7 @@ public interface PetApiService { public Response addPet(Pet body, SecurityContext securityContext); public Response deletePet(Long petId, String apiKey, SecurityContext securityContext); public Response findPetsByStatus(List status, SecurityContext securityContext); - public Response findPetsByTags(List tags, SecurityContext securityContext); + @Deprecated public Response findPetsByTags(List tags, SecurityContext securityContext); public Response getPetById(Long petId, SecurityContext securityContext); public Response updatePet(Pet body, SecurityContext securityContext); public Response updatePetWithForm(Long petId, String name, String status, SecurityContext securityContext);