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

fix for operationContextParam codegen #1475

Merged
merged 2 commits into from
Dec 19, 2024

Conversation

kuhe
Copy link
Contributor

@kuhe kuhe commented Dec 19, 2024

Internal JS-5629

This PR fixes codegen for operationContextParam by changing the path expression result into a mapping function based on the command's input. The getter functions are made non-throwing so as not to perform unintentional client side validation.

@kuhe kuhe requested a review from a team as a code owner December 19, 2024 15:39
*/
export interface OperationContextParamInstruction {
type: "operationContextParams";
get(input: any): any;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can I assume that the path expression is solely based on the input? No other parameters are needed, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. As per internal documentation

The operationContextParams trait defines one or more context parameters that MUST be bound to values specified in the operation input using a JMESPath expression

@kuhe kuhe force-pushed the fix/operationContextParams branch from b40efff to 3b3ba74 Compare December 19, 2024 15:57
@@ -344,7 +344,7 @@ private void generateEndpointParameterInstructionProvider() {
operationContextParamValues.forEach((name, jmesPathForInputInJs) -> {
writer.write(
"""
$L: { type: \"operationContextParams\", name: $L },
$L: { type: \"operationContextParams\", get: (input?: any) => $L },
Copy link
Contributor Author

@kuhe kuhe Dec 19, 2024

Choose a reason for hiding this comment

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

These need to be functions because there is no this at the time the instruction is evaluated. The instruction sits in the global/module scope due to the use of classBuilder to create commands.

export class XCommand extends $Command.
  classBuilder<...>()
  .ep({
    ...commonParams,
    MemberName: { type: "operationContextParams", get: (input?: any) => ... },
  })
  ...
  .build() {
  protected declare static __types: { ... }
}

@kuhe kuhe merged commit e27d42d into smithy-lang:main Dec 19, 2024
11 checks passed
@kuhe kuhe deleted the fix/operationContextParams branch December 19, 2024 17:15
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