[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.
This commit is contained in:
Antoine Reilles 2022-03-01 17:17:11 +01:00 committed by GitHub
parent 4daead1aea
commit a5952bfb10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 3 deletions

View File

@ -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}}

View File

@ -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}}

View File

@ -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"),

View File

@ -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<String> status, SecurityContext securityContext);
public Response findPetsByTags(List<String> tags, SecurityContext securityContext);
@Deprecated public Response findPetsByTags(List<String> 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);