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

Add validation for intEnum shapes #654

Merged
merged 1 commit into from
Jan 4, 2023

Conversation

milesziemer
Copy link
Contributor

This PR adds an IntegerEnumValidator, IntegerEnumValidationFailure and the relevant tests to the ssdk libs. StructuredMemberWriter was updated to use IntegerEnumValidator when generating shape validators for intEnum shapes.

Local testing:

  • Update js sdk to use Smithy 1.26.4, which has the protocol tests for intEnum
  • Update js sdk to use local version of smithy-typescript-ssdk-libs, specificaly the server protocol test packages
  • Run yarn generate-clients --server-artifacts and yarn test:server-protocols

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@milesziemer milesziemer requested a review from a team as a code owner December 8, 2022 16:23
@milesziemer milesziemer force-pushed the add-int-enum-validation branch from b43c93c to 7acd0e1 Compare December 8, 2022 16:30
This PR adds an IntegerEnumValidator, IntegerEnumValidationFailure and
the relevant tests to the ssdk libs. StructuredMemberWriter was updated
to use IntegerEnumValidator when generating shape validators for intEnum
shapes.

Local testing:
- Update js sdk to use Smithy 1.26.4, which has the protocol tests for
intEnum
- Update js sdk to use local version of smithy-typescript-ssdk-libs,
specificaly the server protocol test packages
- Run `yarn generate-clients --server-artifacts` and
`yarn test:server-protocols`
@milesziemer milesziemer force-pushed the add-int-enum-validation branch from 7acd0e1 to 5cd89ef Compare December 8, 2022 16:32
Comment on lines -476 to +479
if (constraints.isEmpty()) {
boolean shouldWriteIntEnumValidator = shape.isIntEnumShape();

if (constraints.isEmpty() && !shouldWriteIntEnumValidator) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you not able to add it as a constraint instead of adding an override here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not from what I can tell. The constraints are Traits, but there is no trait for intEnum. The EnumTrait is deprecated too, so ideally we would handle enum and intEnum shapes like the other shapes in writeMemberValidator. The issue with that is, there may still be constraint traits on the shape, and for enum shapes, that will still include the @enum trait, so we'd have to like exclude it from the constraints or something. I agree though that handling intEnum like the way I did is a little funky, I'm open to other options. Both intEnum and enum shapes will trigger this guard, which would make it weird to try doing a shape.isIntEnumShape() or shape.isEnumShape() in writeMemberValidator.

@milesziemer milesziemer merged commit c874a2a into smithy-lang:main Jan 4, 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