codegen: add <> -> 'Not_Equal' to specialCharReplacements#12801
Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom Jul 11, 2022
Merged
codegen: add <> -> 'Not_Equal' to specialCharReplacements#12801wing328 merged 1 commit intoOpenAPITools:masterfrom
<> -> 'Not_Equal' to specialCharReplacements#12801wing328 merged 1 commit intoOpenAPITools:masterfrom
Conversation
Member
|
Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors. Let me know if you need help fixing it. |
506fd03 to
310f2a3
Compare
This is a fairly common alternative to `!=`, e.g. in SQL or in DevExtreme filters. Previously, if one of an enum's variant was just '<>', its entire name would be sanitized away, resulting in an empty string as symbol name and therefore a syntax error.
310f2a3 to
10f7205
Compare
Contributor
Author
|
yeah my bad, I fixed the author metadata |
Member
|
LGTM. Will update samples after merging. |
Member
|
Samples updated via 244a459 |
Contributor
Author
|
nice, thank you |
5 tasks
wing328
pushed a commit
that referenced
this pull request
Jul 10, 2024
* codegen: add == -> 'Double_Equal' to specialCharReplacements The double equal '==' is a common operator in a few contexts (specific use case for me is haystack operators). Currently if this value appears in an enum its name gets sanitized to empty and generates invalid syntax. Very similar to #12801 * makes java underscore test more flexible Given the name and purpose of this test, maybe it is better to test that the generated value is not an underscore rather than to test that it _is_ a specific (and possibly arbitrary) substitute value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
<>is a fairly common alternative to!=, e.g. in SQL or in DevExtreme filters.Previously, if one of an enum's variant was just '<>', its entire name would be sanitized away,
resulting in an empty string as symbol name and therefore a syntax error.
I have an OpenAPI schema that looks something like this:
{ // ... "components" : { "schemas" : { "FilterOp" : { "enum" : [ "=", "<>", ">", ">=", "<", "<=", "contains", "notcontains", "startswith", "endswith" ], "type" : "string" }, // ... } } }The OpenAPI-Typescript-Generator currently emits the following code:
Which has an empty string for the symbol name of the '<>' enum variant and therefore does not compile. This happens because
AbstractTypeScriptClientCodegen#toEnumVarNamesanitizes invalid characters usingsanitizeName, and<>consists of such invalid characters only, resulting in an empty string.For a fixed set of strings defined in
specialCharReplacementsthis is solved by providing replacement. I opted for adding a replacement for<>there. With that change the following code is emitted instead (Not_Equalgets sanitized toNotEqual):This merge request solely fixes a specific usecase I have. It does not fix this issue in general, which is that
sanitizeNameinDefaultCodegenmay always result in an empty string for some inputs. I do not know how that would be best addressed.