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

Conversation

shorea
Copy link
Contributor

@shorea shorea commented Jan 26, 2022

This change generates the @deprecated annotation for all APIs marked as deprecated in the C2J model.

Motivation and Context

This adds clear guidance for deprecated APIs in the IDE.

N/A

Modifications

Modifies the code generator to add the @deprecated annotation to client/interface methods that correspond to a deprecated API.

Testing

Added deprecated trait to one of the existing poet test models and modified expected generation files.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • [ x] New feature (non-breaking change which adds functionality)

Checklist

  • [ x] I have read the CONTRIBUTING document
  • [x ] Local run of mvn install succeeds
  • [x ] My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • [x ] I have added tests to cover my changes
  • [x ] All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • [x ] I confirm that this pull request can be released under the Apache 2 license

@shorea shorea requested a review from a team as a code owner January 26, 2022 05:31
Copy link
Contributor

@zoewangg zoewangg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Andrew! 👋🏽 :shipit:

@@ -160,6 +160,7 @@ public final String serviceName() {
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/APostOperation" target="_top">AWS
* API Documentation</a>
*/
@Deprecated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's a deprecatedMessage field. Can we add it in the Javadocs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably update this utility class to support operation models as well:

/**
* If a given member 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(MemberModel member, MethodSpec method) {
if (!member.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(member.getDeprecatedMessage())) {
builder.addJavadoc(" $L", member.getDeprecatedMessage());
}
}
return builder.build();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice @Bennett-Lynch this looks perfect, will make some tweaks to use that.

@zoewangg sure thing! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added those changes. Let me know what you think!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@zoewangg zoewangg enabled auto-merge (squash) January 26, 2022 20:19
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

89.7% 89.7% Coverage
0.0% 0.0% Duplication

@zoewangg zoewangg merged commit acda137 into aws:master Jan 26, 2022
aws-sdk-java-automation added a commit that referenced this pull request Apr 22, 2024
…2ad13ede2

Pull request: release <- staging/bcc21d3e-5a23-4397-8f24-ecc2ad13ede2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants