-
Notifications
You must be signed in to change notification settings - Fork 803
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
Supporting wildcard and keys fn in JmesPathRuntime #5198
Supporting wildcard and keys fn in JmesPathRuntime #5198
Conversation
@@ -125,6 +128,8 @@ public TypeSpec poetSpec() { | |||
.addAnnotation(SdkInternalApi.class) | |||
.addSuperinterface(ExecutionInterceptor.class); | |||
|
|||
b.addField(logger()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, wondering if we should add logic to only generate operation context params if they exist, potentially including the logger dependency. Do not have time to check exactly what is generated under which circumstances for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added removing empty methods to follow up task
String jmesPathString = ((JrsString) value.getValue()).getValue(); | ||
CodeBlock addParam = CodeBlock.builder() | ||
.add("params.$N(", setterName) | ||
.add(jmesPathGenerator.interpret(jmesPathString, "input")) | ||
.add(matchToParameterType(key)) | ||
.add(")") | ||
.build(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that doing a try catch exception here will absorb any issue in this case we should be doing a fail-fast rather than fail safe for following reasons
- We should immediately fail if there are issues while extracting the value using
JmesPathRuntime
Example : Currently the customization was specified as "value": "Delete.Objects[*].key"
, note that it should have have been "value": "Delete.Objects[*].Key"
Because of this the Binding is not happening and it gets ignored silently with a warning.
However , if we have an exception we get IllegalArgumentException: No such field: key
upfront
java.lang.IllegalArgumentException: No such field: key
at software.amazon.awssdk.services.s3.jmespath.internal.JmesPathRuntime$Value.lambda$field$4(JmesPathRuntime.java:297)
at java.util.Optional.orElseThrow(Optional.java:290)
- This might cause issue while AuthSchemes tries to use it , Auth scheme will not have a way to know if its params were Null because of Exception or if user had not set it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed
assertThat(jmesRuntimeEvents).extracting("message.formattedMessage") | ||
.usingElementComparator(stringContains()) | ||
.contains("emptyKeyListOfString", "missingFieldListOfString") | ||
.contains("No such field: NonExistingMember"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is a NonExistingMember defined should we get an exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
|
||
Arguments.of("List of String parameter from wildcard works as expected", new TestAssertion( | ||
p -> assertThat(p.wildcardKeyListOfString()).isNotEmpty().hasSize(2) | ||
.containsExactly("StringMemberS1", "StringMemberS2"))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we write a test case when only one of the List has entry
Source Json
{
"bucket": "someBucket",
"delete": {
"objects": [
{
"id": "a",
"key": "One"
},
{
"id": "b"
}
]
}
}
JMESPath Expression : delete.objects[*].key
Output
[
"One"
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, had to update the test harness to handle this case.
Can we please add test cases in Acceptor too. Lines 217 to 271 in e46761c
Since we are supporting it now can we add corresponding test for above cases . Or if we only support |
There a few things I want to clean up in a follow-up PR - some renaming, excluding codegen of empty methods etc. I will add this to that list. |
Quality Gate failedFailed conditions |
14dd8d1
into
feature/StringArrayEndpointParams
* 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>
* feat(StringArrayEndpointParams) Codegen String Array Enpoint params and Auth schemes params based on end-point-rule-set.json. (aws#5122) * Support Customization string array endpoint params for S3 access grants, until all SDKs add support for string array. (aws#5137) * new(StringArrayEndpointParams) Codegeneration of OperationContextParams defined for a Operation. (aws#5146) * Extracting existing JMESPath runtime to a separate class (aws#5155) * new(StringArrayEndpointParams) Customization of Operation Context params and adding customizations for S3 (aws#5159) * Converts endpoint param list of string to list of value (aws#5169) * Generates JmesPath expressions for operation context parameters (aws#5172) * Supporting wildcard and keys fn in JmesPathRuntime (aws#5198) * Adds functional tests for list of string auth params (aws#5216) * Changelog --------- Co-authored-by: John Viegas <70235430+joviegas@users.noreply.github.com> Co-authored-by: John Viegas <joviegas@amazon.com>
Motivation and Context
Modifications
wildcard
function, which has existed in the runtime but never been used in waiters, to accept lists which is according to specs: https://jmespath.org/specification.html#wildcard-expressionskeys
function which can return the names ofSdkField
members in anSdkPojo
project
to filter null values from the result. Another alternative would be to just filter nulls when returningstringValues
but I can't think of a Java use-case where we want to preserve the null when evaluating an expression.Testing
Tested in
codegen-generated-classes-test
Testing with incomplete objects where the projected field does not exist in a list projection member didn't work with the approximation of and SdkPojo in the test class. Instead, switched to a modeled pojo that correctly returns null for a field instead of not recognizing field.