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 8aadc5b98..80f049f59 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 @@ -51,6 +51,7 @@ import com.palantir.conjure.visitor.TypeVisitor; 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.CodeBlock; import com.squareup.javapoet.FieldSpec; @@ -205,6 +206,18 @@ private TypeSpec generateEndpointHandler(EndpointDefinition endpointDefinition, List typeDefinitions, TypeMapper typeMapper, TypeMapper returnTypeMapper) { + MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("handleRequest") + .addAnnotation(Override.class) + .addModifiers(Modifier.PUBLIC) + .addParameter(HttpServerExchange.class, EXCHANGE_VAR_NAME) + .addException(IOException.class) + .addCode(endpointInvocation(endpointDefinition, typeDefinitions, typeMapper, returnTypeMapper)); + + endpointDefinition.getDeprecated().ifPresent(deprecatedDocsValue -> methodBuilder.addAnnotation( + AnnotationSpec.builder(SuppressWarnings.class) + .addMember("value", "$S", "deprecation") + .build())); + return TypeSpec.classBuilder(endpointToHandlerClassName(endpointDefinition.getEndpointName())) .addModifiers(Modifier.PRIVATE) .addSuperinterface(HttpHandler.class) @@ -212,13 +225,7 @@ private TypeSpec generateEndpointHandler(EndpointDefinition endpointDefinition, .filter(def -> def.getParamType().accept(ParameterTypeVisitor.IS_BODY)) .map(def -> createTypeField(typeMapper, def)) .collect(Collectors.toList())) - .addMethod(MethodSpec.methodBuilder("handleRequest") - .addAnnotation(Override.class) - .addModifiers(Modifier.PUBLIC) - .addParameter(HttpServerExchange.class, EXCHANGE_VAR_NAME) - .addException(IOException.class) - .addCode(endpointInvocation(endpointDefinition, typeDefinitions, typeMapper, returnTypeMapper)) - .build()) + .addMethod(methodBuilder.build()) .build(); } 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 ce595dba2..10ac9cb7b 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 @@ -300,6 +300,7 @@ public final class TestServiceEndpoints implements Service { private class GetBranchesDeprecatedHandler implements HttpHandler { @Override + @SuppressWarnings("deprecation") public void handleRequest(HttpServerExchange exchange) throws IOException { AuthHeader authHeader = Auth.header(exchange); Map pathParams =