-
Notifications
You must be signed in to change notification settings - Fork 109
fix: Sanitize Java keywords in generated client #911
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
base: master
Are you sure you want to change the base?
Conversation
|
See the failure on pulpogato/pulpogato#841 for example |
| """ | ||
| |InputArgument ${input.name}Arg = new InputArgument("${input.name}", ${input.name}, false, null); | ||
| |getInputArguments().get("${it.name}").add(${input.name}Arg); | ||
| |InputArgument ${javaReservedKeywordSanitizer.sanitize(input.name)}Arg = new InputArgument( |
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.
nit: consider extracting into a local var and reusing in all 3 places in the modified block
| |InputArgument ${input.name}Arg = new InputArgument("${input.name}", ${input.name}Reference, true, ${getVariableDefinitionType( | ||
| |InputArgument ${javaReservedKeywordSanitizer.sanitize( | ||
| input.name, | ||
| )}Arg = new InputArgument("${input.name}", ${input.name}Reference, true, ${getVariableDefinitionType( |
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.
shall it be sanitized it here as well (${input.name}Reference)?
| | ${javaReservedKeywordSanitizer.sanitize(input.name)}, | ||
| | false, | ||
| | null); | ||
| |getInputArguments().get("${fieldDefinition.name}").add(${input.name}Arg); |
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.
same question: why is it sanitized on line 603 but not here?
sjohnr
left a comment
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.
Hi @rahulsom, thanks for the PR! I added a comment for your review below.
| |InputArgument ${input.name}Arg = new InputArgument("${input.name}", ${input.name}Reference, true, ${getVariableDefinitionType( | ||
| |InputArgument ${javaReservedKeywordSanitizer.sanitize( | ||
| input.name, | ||
| )}Arg = new InputArgument("${input.name}", ${input.name}Reference, true, ${getVariableDefinitionType( |
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 think *Reference param name should be sanitized as well? I'm not sure if this would also be a problem and perhaps we're missing a test case, or this param doesn't need to be sanitized?
Edit: Looks like @iuliiasobolevska beat me to it here. 😄
7745ac2 to
f19b2ec
Compare
|
Thanks @iuliiasobolevska & @sjohnr for the review! Changes are in. |
| .addCode( | ||
| """ | ||
| |this.variableReferences.put("${javaReservedKeywordSanitizer.sanitize(inputValue.name)}", variableRef); | ||
| |this.variableReferences.put("$sanitizedInputName", variableRef); |
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.
My understanding might be off but would we want to instead keep the unsanitized input name here to match the GraphQL input so the query is serialized correctly?
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.
Yep. That makes sense. Updated that. Thanks!
Prior to this change, the generated code would have the right name for the parameter but wrong name in the creation of InputArgument.
```java
InputArgument packageArg = new InputArgument("package", package, false, null);
```
Now we have a test for generated code being compilable, and we handle this case correctly.
f19b2ec to
a1c7ba8
Compare
Prior to this change, the generated code would have the right name for the parameter but wrong name in the creation of InputArgument.
Now we have a test for generated code being compilable, and we handle this case correctly.