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

Parameter Validation #256

Merged
merged 26 commits into from
Feb 11, 2025
Merged

Parameter Validation #256

merged 26 commits into from
Feb 11, 2025

Conversation

mullermp
Copy link
Contributor

Adds parameter validation based on API rules.

Copy link
Contributor

@alextwoods alextwoods left a comment

Choose a reason for hiding this comment

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

Overall approach makes sense and looks good.

@@ -91,7 +91,30 @@ def member(name)
class IntegerShape < Shape; end

# Represents an IntEnum shape.
class IntEnumShape < EnumShape; end
class IntEnumShape < Shape
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inheriting from EnumShape and StructureShape makes is_a? checks order dependent for visiting. While this is duplicating, it's safer.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we wanted to reduce the duplicaiton, we could do use an include with some sort of ShapeWithMembers module or something. But the duplication is minimal and fine.

return PRELUDE_SHAPES_MAP[id] if PRELUDE_SHAPES_MAP.key?(id)

Model::Shape.relative_id(id)
Model::Shape.name(id).camelize
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixes a bug where constants in add_member are not camelized and do not exist.

@@ -4,95 +4,18 @@

module ClientHelper
Copy link
Contributor Author

@mullermp mullermp Feb 9, 2025

Choose a reason for hiding this comment

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

I went back and forth on this but I'm happy with the result - I went too far with the refactor and dialed it back some. I think that the smithy spec_helper/client_helper should work only on fixtures. The purpose of those is to verify that the generated code/files are correct. I prefer the explicit module name declaration in the tests for smithy's spec_helper. I think having smithy-client rely on another gem's spec helper was funky, so I pulled out sample_shapes into smithy-clients client_helper, and I think it's ok to have two. At this point, when using this helper, we can assume the generated code is correct. The quick runtime client generation is great for smithy-client tests and does not need fixtures in my opinion, as we probably want to change model values during tests.

@mullermp mullermp marked this pull request as ready for review February 9, 2025 18:09
Copy link
Contributor

@alextwoods alextwoods left a comment

Choose a reason for hiding this comment

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

Nice - looks good overall - just minor comments.

@@ -91,7 +91,30 @@ def member(name)
class IntegerShape < Shape; end

# Represents an IntEnum shape.
class IntEnumShape < EnumShape; end
class IntEnumShape < Shape
Copy link
Contributor

Choose a reason for hiding this comment

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

If we wanted to reduce the duplicaiton, we could do use an include with some sort of ShapeWithMembers module or something. But the duplication is minimal and fine.

describe 'floats' do
it 'accepts a float' do
validate(float: 123.0)
validate({ float: 123 },
Copy link
Contributor

Choose a reason for hiding this comment

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

This validation feels weird to me - it seems like we should accept an integer 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.

In v3 we do both param validation and param conversion. Param validation should ensure strictness-ish and param conversion can convert integers given to float shapes as floats. This makes error messaging cleaner maybe. Unless you have a different idea.

Object.const_get(namespace)
rescue Exception => e # rubocop:disable Lint/RescueException
Object.const_get(module_name)
rescue LoadError => e
Copy link
Contributor

Choose a reason for hiding this comment

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

Does LoadError cover all of the syntax errors that could happen during eval?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so. At this point we assume generated code is valid.

@mullermp mullermp merged commit bbf9676 into decaf Feb 11, 2025
6 checks passed
@mullermp mullermp deleted the validation branch February 11, 2025 00:57
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.

2 participants