-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[scala][http4s] fix escaping of reserved words for correct model dese… #21518
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
d3de2ae
to
de9ff5a
Compare
thanks for the pr can you please review the CI build failure when you've time? |
7153a80
to
738f4d0
Compare
} | ||
}; | ||
|
||
return compiler.withEscaper(SCALA); |
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.
instead of overriding processCompiler, what about adding lambda function to additional properties?
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 created
private static class BacktickLambda extends AbstractScalaCodegen.CustomLambda {
@Override
public String formatFragment(String fragment) {
if (fragment.startsWith("`") && fragment.endsWith("`")) {
String unescaped = fragment.substring(1, fragment.length() - 1);
return "`" + Escapers.HTML.escape(unescaped) + "`";
}
return Escapers.HTML.escape(fragment);
}
}
added it to the properties
additionalProperties.put("fnBacktick", new BacktickLambda());
After that, I used it in the templates
{{#fnBacktick}}{{paramName}}{{/fnBacktick}}
and I ended up with non-compiling code
case class User(
`type`: String
)
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 found solution about overriding processCompiler here
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.
RE:
{{#fnBacktick}}{{paramName}}{{/fnBacktick}}
what about using the following instead to use the original value instead of HTML-escaped value?
{{#fnBacktick}}{{{paramName}}}{{/fnBacktick}}
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.
done
738f4d0
to
e60c51a
Compare
There is an example of correct openAPI specification:
JSON response is generated for this OpenAPI specification:
This is incorrect since we specified that the field should be named
type
, not_type
.I changed the escaping of reserved words to standard Scala backticks notation so that the JSON decoder could properly map the domain to JSON.
PR checklist
master
(upcoming7.x.0
minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)Hello! 👋
I'd love to get your eyes on this PR when you have a moment.
Thanks in advance!
@clasnake (2017/07), @shijinkui (2018/01), @ramzimaalej (2018/03), @chameleon82 (2020/03), @Bouillie (2020/04) @Fish86 (2023/06)