Skip to content
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

fix: remove invalid defaults for some services #1112

Conversation

milesziemer
Copy link
Contributor

Issue #

N/A

Description of changes

Adds a customization that removes default values from certain shapes for some services. These default values could cause
issues if the service expects a value > 0. Removing the default means these values aren't set under the hood causing unexpected request failures.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@milesziemer milesziemer requested a review from a team as a code owner November 16, 2023 21:10
@milesziemer milesziemer force-pushed the remove-defaults-for-invalid-range-traits branch 2 times, most recently from 6c5d483 to dacde52 Compare November 16, 2023 22:22
Copy link
Contributor

@ianbotsf ianbotsf left a comment

Choose a reason for hiding this comment

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

Looks pretty good, thanks @milesziemer.

Comment on lines 37 to 65
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean {
val serviceId = settings.service
return serviceId in removeDefaultsFrom
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Can be simplified:

override fun enabledForService(model: Model, settings: KotlinSettings) =
    settings.service in removeDefaultsFrom

Comment on lines 69 to 73
private fun shouldRemoveRootDefault(shape: Shape, removeDefaultsFrom: Set<ShapeId>): Boolean =
shape !is MemberShape && removeDefaultsFrom.contains(shape.id) && shape.hasTrait<DefaultTrait>()

private fun shouldRemoveMemberDefault(shape: Shape, removeDefaultsFrom: Set<ShapeId>): Boolean =
shape is MemberShape && removeDefaultsFrom.contains(shape.target) && shape.hasTrait<DefaultTrait>()
Copy link
Contributor

Choose a reason for hiding this comment

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

Style:

  • removeDefaultsFrom.contains(shape.id)shape.id in removeDefaultsFrom
  • removeDefaultsFrom.contains(shape.target)shape.target in removeDefaultsFrom

import software.amazon.smithy.model.traits.DefaultTrait
import kotlin.test.assertFalse

class RemoveDefaultsTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: This test could be improved by verifying it doesn't remove defaults from shapes not in the set and that it also removes them from member shapes.

@milesziemer milesziemer force-pushed the remove-defaults-for-invalid-range-traits branch 3 times, most recently from ad40494 to 21e392c Compare November 17, 2023 15:59
@aajtodd aajtodd mentioned this pull request Nov 17, 2023
Adds an integration that removes the default value from certain
shapes in some services where the default value is 0, but the
service expects a value > 0.
@milesziemer milesziemer force-pushed the remove-defaults-for-invalid-range-traits branch from 21e392c to 6aebd1c Compare November 17, 2023 17:29
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 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@aajtodd
Copy link
Contributor

aajtodd commented Nov 17, 2023

closing in favor of #1116

@aajtodd aajtodd closed this Nov 17, 2023
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