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

Generates JmesPath expressions for operation context parameters #5172

Merged

Conversation

cenedhryn
Copy link
Contributor

Motivation and Context

Endpoint parameters of type stringarray are supported for operation level traits only, normally via the OperationContextParam trait, which uses a JmesPath expression to find and potentially transform a part of an SdkPojo in order to create a corresponding endpoint parameter

Modifications

  • Modifies endpoint resolver interceptor codegen to interpret the value of the OperationContextParam as a JmesPath expression string
  • The result of this JmesPath expression will be evaluated at runtime, and stored in the endpoint param.
  • Unlike waiters, the codegen JmesPath must contain the value of the expression. In order to know what type of value is required, we match the operationContextParameter with it's corresponding endpoint ParameterModel (same key) since the type for that is known.
  • The JmesPathRuntime now has support for returning the value as any of the three supported types of endpoint parameter.
  • In addition, the JmesPath generator now supports wildcard and the keys function. This means that the codegen side supports it, but the capability is lacking at runtime (future PR).

Testing

codegen-generated-classes-test has a new test class that evaluates that the value of the OperationContextParams are set correctly. The test cases contain the minimal subset of JmesPath that is required for OperationContextParams and already exists in the codebase:

  • identifier
  • subexpression

@cenedhryn cenedhryn requested a review from a team as a code owner May 1, 2024 22:52
assertThat(new Value(singletonList("a")).length()).isEqualTo(new Value(1));
}

// @Test
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 just saw this - will need it for next PR

import software.amazon.awssdk.services.restjsonwithwaiters.jmespath.internal.JmesPathRuntime.Value;
import software.amazon.awssdk.utils.Pair;

class JmesPathRuntimeValueTest {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably should not have renamed this class, but here we are. There is nothing removed.

case "stringarray":
return CodeBlock.of(".stringValues()");
default:
return CodeBlock.of("");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we throw UnsupportedOperationException?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think that's better. Good suggestion.

case BOOLEAN:
return booleanValue.toString();
default:
throw new IllegalStateException();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add more information in the exception even though it's unlikely to happen?

@cenedhryn cenedhryn merged commit f9724c3 into feature/StringArrayEndpointParams May 3, 2024
6 of 16 checks passed
@cenedhryn cenedhryn deleted the salande/opconparam-parse-jmespath branch May 13, 2024 00:52
cenedhryn added a commit that referenced this pull request May 13, 2024
* feat(StringArrayEndpointParams) Codegen String Array Enpoint params and Auth schemes params based on end-point-rule-set.json. (#5122)

* Support Customization string array endpoint params for S3 access grants, until all SDKs add support for string array. (#5137)

* new(StringArrayEndpointParams) Codegeneration of OperationContextParams defined for a Operation. (#5146)

* Extracting existing JMESPath runtime to a separate class (#5155)

* new(StringArrayEndpointParams) Customization of Operation Context params and adding customizations for S3 (#5159)

* Converts endpoint param list of string to list of value (#5169)

* Generates JmesPath expressions for operation context parameters (#5172)

* Supporting wildcard and keys fn in JmesPathRuntime (#5198)

* Adds functional tests for list of string auth params (#5216)

* Changelog

---------

Co-authored-by: John Viegas <70235430+joviegas@users.noreply.github.com>
Co-authored-by: John Viegas <joviegas@amazon.com>
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.

None yet

2 participants