Skip to content

Adding @Deprecated annotation when API is marked as deprecated #2991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public Map<String, OperationModel> constructOperations() {

operationModel.setOperationName(operationName);
operationModel.setDeprecated(op.isDeprecated());
operationModel.setDeprecatedMessage(op.getDeprecatedMessage());
operationModel.setDocumentation(op.getDocumentation());
operationModel.setIsAuthenticated(isAuthenticated(op));
operationModel.setAuthType(op.getAuthtype());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class OperationModel extends DocumentationModel {

private boolean deprecated;

private String deprecatedMessage;

private VariableModel input;

private ReturnTypeModel returnType;
Expand Down Expand Up @@ -84,6 +86,14 @@ public void setDeprecated(boolean deprecated) {
this.deprecated = deprecated;
}

public String getDeprecatedMessage() {
return deprecatedMessage;
}

public void setDeprecatedMessage(String deprecatedMessage) {
this.deprecatedMessage = deprecatedMessage;
}

public String getDocs(IntermediateModel model,
ClientType clientType) {
return OperationDocs.getDocs(model, this, clientType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class Operation {

private boolean deprecated;

private String deprecatedMessage;

private Http http;

private Input input;
Expand Down Expand Up @@ -67,6 +69,14 @@ public void setDeprecated(boolean deprecated) {
this.deprecated = deprecated;
}

public String getDeprecatedMessage() {
return deprecatedMessage;
}

public void setDeprecatedMessage(String deprecatedMessage) {
this.deprecatedMessage = deprecatedMessage;
}

public Http getHttp() {
return http;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import software.amazon.awssdk.codegen.poet.PoetExtensions;
import software.amazon.awssdk.codegen.poet.PoetUtils;
import software.amazon.awssdk.codegen.poet.eventstream.EventStreamUtils;
import software.amazon.awssdk.codegen.poet.model.DeprecationUtils;
import software.amazon.awssdk.codegen.utils.PaginatorUtils;
import software.amazon.awssdk.core.SdkClient;
import software.amazon.awssdk.core.async.AsyncRequestBody;
Expand Down Expand Up @@ -179,7 +180,9 @@ private Stream<MethodSpec> operationsAndSimpleMethods(OperationModel operationMo
methods.addAll(traditionalMethods(operationModel));
methods.addAll(overloadMethods(operationModel));
methods.addAll(paginatedMethods(operationModel));
return methods.stream();
return methods.stream()
// Add Deprecated annotation if needed to all overloads
.map(m -> DeprecationUtils.checkDeprecated(operationModel, m));
}

private List<MethodSpec> paginatedMethods(OperationModel opModel) {
Expand Down Expand Up @@ -406,7 +409,7 @@ private MethodSpec.Builder methodSignatureWithReturnType(OperationModel opModel)
*/
private MethodSpec.Builder interfaceMethodSignature(OperationModel opModel) {
return methodSignatureWithReturnType(opModel)
.addModifiers(Modifier.PUBLIC, Modifier.DEFAULT);
.addModifiers(Modifier.PUBLIC, Modifier.DEFAULT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static MethodSpec consumerBuilderVariant(MethodSpec spec, String javadoc) {
MethodSpec.Builder result = MethodSpec.methodBuilder(spec.name)
.returns(spec.returnType)
.addExceptions(spec.exceptions)
.addAnnotations(spec.annotations)
.addJavadoc(javadoc)
.addModifiers(Modifier.PUBLIC, Modifier.DEFAULT)
.addTypeVariables(spec.typeVariables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import software.amazon.awssdk.codegen.poet.ClassSpec;
import software.amazon.awssdk.codegen.poet.PoetExtensions;
import software.amazon.awssdk.codegen.poet.PoetUtils;
import software.amazon.awssdk.codegen.poet.model.DeprecationUtils;
import software.amazon.awssdk.codegen.utils.PaginatorUtils;
import software.amazon.awssdk.core.ResponseBytes;
import software.amazon.awssdk.core.ResponseInputStream;
Expand Down Expand Up @@ -176,7 +177,10 @@ private List<MethodSpec> operationMethodSpec(OperationModel opModel) {
methods.addAll(streamingSimpleMethods(opModel));
methods.addAll(paginatedMethods(opModel));

return methods;
return methods.stream()
// Add Deprecated annotation if needed to all overloads
.map(m -> DeprecationUtils.checkDeprecated(opModel, m))
.collect(toList());
}

private MethodSpec simpleMethod(OperationModel opModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.squareup.javapoet.MethodSpec;
import java.util.List;
import software.amazon.awssdk.codegen.model.intermediate.MemberModel;
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
import software.amazon.awssdk.utils.StringUtils;

public final class DeprecationUtils {
Expand Down Expand Up @@ -49,6 +50,24 @@ public static MethodSpec checkDeprecated(MemberModel member, MethodSpec method)
return builder.build();
}

/**
* If a given operation is modeled as deprecated, add the {@link Deprecated} annotation to the method and, if the method
* already has existing Javadoc, append a section with the {@code @deprecated} tag.
*/
public static MethodSpec checkDeprecated(OperationModel operation, MethodSpec method) {
if (!operation.isDeprecated() || method.annotations.contains(DEPRECATED)) {
return method;
}
MethodSpec.Builder builder = method.toBuilder().addAnnotation(DEPRECATED);
if (!method.javadoc.isEmpty()) {
builder.addJavadoc(LF + "@deprecated");
if (StringUtils.isNotBlank(operation.getDeprecatedMessage())) {
builder.addJavadoc(" $L", operation.getDeprecatedMessage());
}
}
return builder.build();
}

public static List<MethodSpec> checkDeprecated(MemberModel member, List<MethodSpec> methods) {
return methods.stream().map(methodSpec -> checkDeprecated(member, methodSpec)).collect(toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"shape": "InvalidInputException"
}
],
"deprecated": true,
"deprecatedMessage": "This API is deprecated, use something else",
"documentation": "<p>Performs a post operation to the query service and has no output</p>"
},
"GetWithoutRequiredMembers": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ static JsonAsyncClientBuilder builder() {
* @sample JsonAsyncClient.APostOperation
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/APostOperation" target="_top">AWS
* API Documentation</a>
*
* @deprecated This API is deprecated, use something else
*/
@Deprecated
default CompletableFuture<APostOperationResponse> aPostOperation(APostOperationRequest aPostOperationRequest) {
throw new UnsupportedOperationException();
}
Expand Down Expand Up @@ -128,7 +131,10 @@ default CompletableFuture<APostOperationResponse> aPostOperation(APostOperationR
* @sample JsonAsyncClient.APostOperation
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/APostOperation" target="_top">AWS
* API Documentation</a>
*
* @deprecated This API is deprecated, use something else
*/
@Deprecated
default CompletableFuture<APostOperationResponse> aPostOperation(Consumer<APostOperationRequest.Builder> aPostOperationRequest) {
return aPostOperation(APostOperationRequest.builder().applyMutation(aPostOperationRequest).build());
}
Expand Down Expand Up @@ -1449,4 +1455,4 @@ default CompletableFuture<StreamingOutputOperationResponse> streamingOutputOpera
default JsonUtilities utilities() {
throw new UnsupportedOperationException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ static JsonClientBuilder builder() {
* @sample JsonClient.APostOperation
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/APostOperation" target="_top">AWS
* API Documentation</a>
*
* @deprecated This API is deprecated, use something else
*/
@Deprecated
default APostOperationResponse aPostOperation(APostOperationRequest aPostOperationRequest) throws InvalidInputException,
AwsServiceException, SdkClientException, JsonException {
throw new UnsupportedOperationException();
Expand Down Expand Up @@ -119,7 +122,10 @@ default APostOperationResponse aPostOperation(APostOperationRequest aPostOperati
* @sample JsonClient.APostOperation
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/APostOperation" target="_top">AWS
* API Documentation</a>
*
* @deprecated This API is deprecated, use something else
*/
@Deprecated
default APostOperationResponse aPostOperation(Consumer<APostOperationRequest.Builder> aPostOperationRequest)
throws InvalidInputException, AwsServiceException, SdkClientException, JsonException {
return aPostOperation(APostOperationRequest.builder().applyMutation(aPostOperationRequest).build());
Expand Down Expand Up @@ -1377,4 +1383,4 @@ static ServiceMetadata serviceMetadata() {
default JsonUtilities utilities() {
throw new UnsupportedOperationException();
}
}
}