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

Flatten shapes when fetching with Model.shape #269

Merged
merged 16 commits into from
Feb 21, 2025
Merged

Flatten shapes when fetching with Model.shape #269

merged 16 commits into from
Feb 21, 2025

Conversation

alextwoods
Copy link
Contributor

@alextwoods alextwoods commented Feb 10, 2025

See @mullermp comment (hijacked PR)

@alextwoods alextwoods changed the title Demo model preproccess that hydrates mixins and apply traits Demo model preproccess that flattens mixins and apply traits Feb 11, 2025
@mullermp mullermp changed the title Demo model preproccess that flattens mixins and apply traits Flatten shapes when fetching with Model.shape Feb 13, 2025
@mullermp mullermp marked this pull request as ready for review February 18, 2025 20:26
@mullermp
Copy link
Contributor

Returns a flattened shape by default (resolving mixins and apply) when using Model.shape.

Uses depth first recursion. Merging is based on DeepMergable

end
end

def apply_member_traits(id, shape)
Copy link
Contributor

Choose a reason for hiding this comment

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

shape.fetch('members', []) will work for shapes like structures and union. I think members for list (member) and map shapes (key, value) are defined differently so need to cover those cases, right?

I forget if this is already resolved from the get-go.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if mixins work for those shapes or not but that's a good call out, I will investigate.

Dir.glob('gems/smithy/spec/fixtures/**/model.smithy') do |model_path|
out_path = model_path.sub('.smithy', '.json')
sh("smithy ast --aut #{model_path} > #{out_path}")
config_files = smithy_build_files.map do |file|
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would there ever be multiple smithy build files? That seems maybe invalid?

Copy link
Contributor

@mullermp mullermp Feb 20, 2025

Choose a reason for hiding this comment

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

The AST command takes a config file and it says multiple ones are merged. The intent was to allow this to be at all folder hierarchies.

if model['shapes'].key?(id)
Flattener.new(model).shape(id)
elsif PRELUDE_SHAPES.key?(id)
PRELUDE_SHAPES[id]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there any possible interaction between mixins and prelude shapes? I don't think there would be, but just want to check.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think so but I'll check.

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried this: Cannot apply smithy.api#mixin to an immutable prelude shape defined in smithy.api.

deep_merge!(hash1, hash2, exclude_traits, context)
end

def deep_merge!(hash1, hash2, exclude_traits, context)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The difference between deep_merge and deep_merge! is confusing - maybe these could use comments?

Copy link
Contributor

Choose a reason for hiding this comment

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

One returns a new hash and the other modifies the current hash, just like merge and merge!. I got inspiration from the rails implementations. I can add that here.

@alextwoods
Copy link
Contributor Author

Changes overall look good but its my own PR so can't leave an approve.

Copy link
Contributor

@jterapin jterapin left a comment

Choose a reason for hiding this comment

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

I forgot to approve during my review so... here it is!

@mullermp mullermp merged commit a3144ca into decaf Feb 21, 2025
8 checks passed
@mullermp mullermp deleted the mixins branch February 21, 2025 00:22
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