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

fixup jmespath multiselect codegen #551

Merged
merged 3 commits into from
Nov 6, 2024
Merged

Conversation

lucix-aws
Copy link
Contributor

@lucix-aws lucix-aws commented Nov 6, 2024

  • fix up various codegen issues w/ jmespath multiselect around shape lookup and null typing
    • remove the selective deref logic we previously had when mapping string array endpoint params in operation context param bindings - this is no longer necessary, since jmespath projection and multiselect implicitly filter nil, and string array params are []string, the types will always align
  • fix endpoint rules generator to not try to dereference string slices inside conditions

@lucix-aws lucix-aws requested review from a team as code owners November 6, 2024 15:46
@lucix-aws lucix-aws self-assigned this Nov 6, 2024
Copy link
Contributor

@Madrigal Madrigal left a comment

Choose a reason for hiding this comment

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

It would be great if we could also add some test to operationContextParams. Not necessarily as part of this PR

writer.write("""
if $2L != nil {
$1L = append($1L, *$2L)
}""", ident, projected.ident);
$1L = append($1L, $3L$2L)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: let's not do 1-3-2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed a commit to reflow this block to have the numbers go by order of first appearance, which coincidentally means that it's now append(2,3,1) but I think overall makes more sense.

// of string, etc.
// we may need to pull the member shapes back out later, but they're not guaranteed to be in the model - so keep a
// shadow map of synthetic -> member to short-circuit the model lookup
private final Map<Shape, Shape> synthetics = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

For my general knowledge, but do shapes in the model usually get updated, or are they write-only? I would suspect that shapes are mostly a dictionary of things you've seen where you only ever add entries, but I'm not sure if they'd be a case where a shape would also get updated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Every construct in smithy in-code is immutable. The only way to change something is by going toBuilder() and then re-build()ing to create a new instance. So there's no way to just add these synthetics to the model in place (nor do I think we should, that would run the risk of them getting picked up elsewhere). Not sure if that answers your question.

Copy link
Contributor

Choose a reason for hiding this comment

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

It does, but just to clarify. I'm not asking about the Smithy interface, I'm asking about the general mental model for building shapes

I'm not asking to add the synthetics into the model in place. We're building here a lookup map, and I was curious about the Smithy model allowed updates to existing model shapes, something like "you had shape A which was a list(string). Now it's a list(bool)`. This would mean that a lookup map may also need to be updated instead of just being write-once. I suspect this isn't valid just because I can't think of a use case where you'd want that.

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 I see. Yeah, once we're in this code, the model (and all of its shapes) are essentially fixed.

var expr = JmespathExpression.parse(def.getPath());

return writer -> {
var generator = new GoJmespathExpressionGenerator(ctx, writer);

writer.write("func() {"); // contain the scope for each binding
var result = generator.generate(expr, new GoJmespathExpressionGenerator.Variable(input, "in"));

if (param.getType().equals(ParameterType.STRING_ARRAY)) {
// projections can result in either []string OR []*string -- if the latter, we have to unwrap
Copy link
Contributor

Choose a reason for hiding this comment

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

For context: discussed offline and this is done because projections don't have nulls, so they don't have *string members

@@ -27,15 +27,15 @@

public final class ShapeUtil {
public static final StringShape STRING_SHAPE = StringShape.builder()
.id("smithy.api#String")
.id("smithy.api#PrimitiveString")
Copy link
Contributor

Choose a reason for hiding this comment

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

I know we talked about these offline, and since these tests work I guess this is fine, but I couldn't find any docs about the existence of this type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK I finally found it. It's in the prelude model, not the preamble model, I was searching the wrong thing - https://smithy.io/2.0/spec/model.html#prelude

@lucix-aws lucix-aws merged commit 253cd26 into main Nov 6, 2024
11 checks passed
@lucix-aws lucix-aws deleted the fix-jmespathmultiselect branch November 6, 2024 16:48
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