From 72b47db85bd18c63a226e08087fd18d9a97a5c5e Mon Sep 17 00:00:00 2001 From: Eric Sword Date: Tue, 12 Mar 2024 11:53:43 -0400 Subject: [PATCH 1/2] add forRemoval to server side --- .../java/services/JerseyServiceGenerator.java | 13 +++++++++---- .../services/UndertowServiceInterfaceGenerator.java | 11 ++++++++++- .../test/resources/test/api/TestService.java.jersey | 2 +- .../test/api/TestService.java.jersey.jakarta | 2 +- .../test/api/TestService.java.jersey.prefix | 2 +- .../api/TestService.java.jersey_require_not_null | 2 +- .../resources/test/api/TestService.java.undertow | 2 +- .../test/api/TestService.java.undertow.prefix | 2 +- 8 files changed, 25 insertions(+), 11 deletions(-) diff --git a/conjure-java-core/src/main/java/com/palantir/conjure/java/services/JerseyServiceGenerator.java b/conjure-java-core/src/main/java/com/palantir/conjure/java/services/JerseyServiceGenerator.java index f4b5422e8..cf534e9a1 100644 --- a/conjure-java-core/src/main/java/com/palantir/conjure/java/services/JerseyServiceGenerator.java +++ b/conjure-java-core/src/main/java/com/palantir/conjure/java/services/JerseyServiceGenerator.java @@ -187,10 +187,15 @@ private MethodSpec generateServiceMethod( .build()); } - endpointDef - .getDeprecated() - .ifPresent( - deprecatedDocsValue -> methodBuilder.addAnnotation(ClassName.get("java.lang", "Deprecated"))); + endpointDef.getDeprecated().ifPresent(_deprecatedValue -> { + if (endpointDef.getTags().contains("deprecated-for-removal")) { + methodBuilder.addAnnotation(AnnotationSpec.builder(Deprecated.class) + .addMember("forRemoval", "true") + .build()); + } else { + methodBuilder.addAnnotation(Deprecated.class); + } + }); methodBuilder.addAnnotations(ConjureAnnotations.getClientEndpointAnnotations(endpointDef)); diff --git a/conjure-java-core/src/main/java/com/palantir/conjure/java/services/UndertowServiceInterfaceGenerator.java b/conjure-java-core/src/main/java/com/palantir/conjure/java/services/UndertowServiceInterfaceGenerator.java index 1cdac642e..202d30691 100644 --- a/conjure-java-core/src/main/java/com/palantir/conjure/java/services/UndertowServiceInterfaceGenerator.java +++ b/conjure-java-core/src/main/java/com/palantir/conjure/java/services/UndertowServiceInterfaceGenerator.java @@ -36,6 +36,7 @@ import com.palantir.conjure.spec.ServiceDefinition; import com.palantir.tokens.auth.AuthHeader; import com.palantir.tokens.auth.BearerToken; +import com.squareup.javapoet.AnnotationSpec; import com.squareup.javapoet.ClassName; import com.squareup.javapoet.JavaFile; import com.squareup.javapoet.MethodSpec; @@ -94,7 +95,15 @@ private MethodSpec generateServiceInterfaceMethod( .addParameters(createServiceMethodParameters(endpointDef, safetyEvaluator, typeMapper)) .addAnnotations(ConjureAnnotations.incubating(endpointDef)); - endpointDef.getDeprecated().ifPresent(deprecatedDocsValue -> methodBuilder.addAnnotation(Deprecated.class)); + endpointDef.getDeprecated().ifPresent(_deprecatedValue -> { + if (endpointDef.getTags().contains("deprecated-for-removal")) { + methodBuilder.addAnnotation(AnnotationSpec.builder(Deprecated.class) + .addMember("forRemoval", "true") + .build()); + } else { + methodBuilder.addAnnotation(Deprecated.class); + } + }); methodBuilder.addJavadoc("$L", ServiceGenerators.getJavaDocWithRequestLine(endpointDef)); diff --git a/conjure-java-core/src/test/resources/test/api/TestService.java.jersey b/conjure-java-core/src/test/resources/test/api/TestService.java.jersey index e81053738..74517ee93 100644 --- a/conjure-java-core/src/test/resources/test/api/TestService.java.jersey +++ b/conjure-java-core/src/test/resources/test/api/TestService.java.jersey @@ -132,7 +132,7 @@ public interface TestService { */ @GET @Path("catalog/datasets/{datasetRid}/branchesDeprecatedForRemoval") - @Deprecated + @Deprecated(forRemoval = true) @ClientEndpoint(method = "GET", path = "/catalog/datasets/{datasetRid}/branchesDeprecatedForRemoval") Set getBranchesDeprecatedForRemoval( @HeaderParam("Authorization") @NotNull AuthHeader authHeader, diff --git a/conjure-java-core/src/test/resources/test/api/TestService.java.jersey.jakarta b/conjure-java-core/src/test/resources/test/api/TestService.java.jersey.jakarta index 672e50665..1e80c1d1d 100644 --- a/conjure-java-core/src/test/resources/test/api/TestService.java.jersey.jakarta +++ b/conjure-java-core/src/test/resources/test/api/TestService.java.jersey.jakarta @@ -131,7 +131,7 @@ public interface TestService { */ @GET @Path("catalog/datasets/{datasetRid}/branchesDeprecatedForRemoval") - @Deprecated + @Deprecated(forRemoval = true) @ClientEndpoint(method = "GET", path = "/catalog/datasets/{datasetRid}/branchesDeprecatedForRemoval") Set getBranchesDeprecatedForRemoval( @HeaderParam("Authorization") AuthHeader authHeader, diff --git a/conjure-java-core/src/test/resources/test/api/TestService.java.jersey.prefix b/conjure-java-core/src/test/resources/test/api/TestService.java.jersey.prefix index b802ea43e..8482aa8e2 100644 --- a/conjure-java-core/src/test/resources/test/api/TestService.java.jersey.prefix +++ b/conjure-java-core/src/test/resources/test/api/TestService.java.jersey.prefix @@ -131,7 +131,7 @@ public interface TestService { */ @GET @Path("catalog/datasets/{datasetRid}/branchesDeprecatedForRemoval") - @Deprecated + @Deprecated(forRemoval = true) @ClientEndpoint(method = "GET", path = "/catalog/datasets/{datasetRid}/branchesDeprecatedForRemoval") Set getBranchesDeprecatedForRemoval( @HeaderParam("Authorization") AuthHeader authHeader, diff --git a/conjure-java-core/src/test/resources/test/api/TestService.java.jersey_require_not_null b/conjure-java-core/src/test/resources/test/api/TestService.java.jersey_require_not_null index e81053738..74517ee93 100644 --- a/conjure-java-core/src/test/resources/test/api/TestService.java.jersey_require_not_null +++ b/conjure-java-core/src/test/resources/test/api/TestService.java.jersey_require_not_null @@ -132,7 +132,7 @@ public interface TestService { */ @GET @Path("catalog/datasets/{datasetRid}/branchesDeprecatedForRemoval") - @Deprecated + @Deprecated(forRemoval = true) @ClientEndpoint(method = "GET", path = "/catalog/datasets/{datasetRid}/branchesDeprecatedForRemoval") Set getBranchesDeprecatedForRemoval( @HeaderParam("Authorization") @NotNull AuthHeader authHeader, diff --git a/conjure-java-core/src/test/resources/test/api/TestService.java.undertow b/conjure-java-core/src/test/resources/test/api/TestService.java.undertow index c03732ec4..828fafcde 100644 --- a/conjure-java-core/src/test/resources/test/api/TestService.java.undertow +++ b/conjure-java-core/src/test/resources/test/api/TestService.java.undertow @@ -79,7 +79,7 @@ public interface TestService { * @param datasetRid A valid dataset resource identifier. * @deprecated use getBranches instead */ - @Deprecated + @Deprecated(forRemoval = true) Set getBranchesDeprecatedForRemoval(AuthHeader authHeader, @Safe ResourceIdentifier datasetRid); /** @apiNote {@code GET /catalog/datasets/{datasetRid}/branches/{branch:.+}/resolve} */ diff --git a/conjure-java-core/src/test/resources/test/api/TestService.java.undertow.prefix b/conjure-java-core/src/test/resources/test/api/TestService.java.undertow.prefix index d455893b2..a793aa3ef 100644 --- a/conjure-java-core/src/test/resources/test/api/TestService.java.undertow.prefix +++ b/conjure-java-core/src/test/resources/test/api/TestService.java.undertow.prefix @@ -79,7 +79,7 @@ public interface TestService { * @param datasetRid A valid dataset resource identifier. * @deprecated use getBranches instead */ - @Deprecated + @Deprecated(forRemoval = true) Set getBranchesDeprecatedForRemoval(AuthHeader authHeader, @Safe ResourceIdentifier datasetRid); /** @apiNote {@code GET /catalog/datasets/{datasetRid}/branches/{branch:.+}/resolve} */ From 42a0d3d99133d52e2cde022831d0227e43a81dcb Mon Sep 17 00:00:00 2001 From: Eric Sword Date: Tue, 12 Mar 2024 14:41:26 -0400 Subject: [PATCH 2/2] add suppression --- .../UndertowServiceHandlerGenerator.java | 18 ++++++++++++------ .../api/TestServiceEndpoints.java.undertow | 2 +- .../TestServiceEndpoints.java.undertow.prefix | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/conjure-java-core/src/main/java/com/palantir/conjure/java/services/UndertowServiceHandlerGenerator.java b/conjure-java-core/src/main/java/com/palantir/conjure/java/services/UndertowServiceHandlerGenerator.java index 54f6622f4..ca88c6a0f 100644 --- a/conjure-java-core/src/main/java/com/palantir/conjure/java/services/UndertowServiceHandlerGenerator.java +++ b/conjure-java-core/src/main/java/com/palantir/conjure/java/services/UndertowServiceHandlerGenerator.java @@ -234,12 +234,18 @@ private TypeSpec generateEndpointHandler( .addCode(endpointInvocation( endpointDefinition, typeDefinitions, typeMapper, returnTypeMapper, safetyEvaluator)); - endpointDefinition - .getDeprecated() - .ifPresent(deprecatedDocsValue -> - handleMethodBuilder.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class) - .addMember("value", "$S", "deprecation") - .build())); + endpointDefinition.getDeprecated().ifPresent(_deprecatedValue -> { + if (endpointDefinition.getTags().contains("deprecated-for-removal")) { + handleMethodBuilder.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class) + .addMember("value", "$S", "deprecation") + .addMember("value", "$S", "removal") + .build()); + } else { + handleMethodBuilder.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class) + .addMember("value", "$S", "deprecation") + .build()); + } + }); MethodSpec.Builder ctorBuilder = MethodSpec.constructorBuilder() .addParameter(UndertowRuntime.class, RUNTIME_VAR_NAME) diff --git a/conjure-java-core/src/test/resources/test/api/TestServiceEndpoints.java.undertow b/conjure-java-core/src/test/resources/test/api/TestServiceEndpoints.java.undertow index 8b4e9513e..9d9c71a94 100644 --- a/conjure-java-core/src/test/resources/test/api/TestServiceEndpoints.java.undertow +++ b/conjure-java-core/src/test/resources/test/api/TestServiceEndpoints.java.undertow @@ -653,7 +653,7 @@ public final class TestServiceEndpoints implements UndertowService { } @Override - @SuppressWarnings("deprecation") + @SuppressWarnings({"deprecation", "removal"}) public void handleRequest(HttpServerExchange exchange) throws IOException { AuthHeader authHeader = runtime.auth().header(exchange); RequestContext requestContext = runtime.contexts().createContext(exchange, this); diff --git a/conjure-java-core/src/test/resources/test/api/TestServiceEndpoints.java.undertow.prefix b/conjure-java-core/src/test/resources/test/api/TestServiceEndpoints.java.undertow.prefix index bfa51c67d..26eab31a1 100644 --- a/conjure-java-core/src/test/resources/test/api/TestServiceEndpoints.java.undertow.prefix +++ b/conjure-java-core/src/test/resources/test/api/TestServiceEndpoints.java.undertow.prefix @@ -653,7 +653,7 @@ public final class TestServiceEndpoints implements UndertowService { } @Override - @SuppressWarnings("deprecation") + @SuppressWarnings({"deprecation", "removal"}) public void handleRequest(HttpServerExchange exchange) throws IOException { AuthHeader authHeader = runtime.auth().header(exchange); RequestContext requestContext = runtime.contexts().createContext(exchange, this);