Created by: Felk
<> 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:
/**
*
* @export
* @enum {string}
*/
export enum FilterOp {
Equal = '=',
= '<>',
GreaterThan = '>',
GreaterThanOrEqualTo = '>=',
LessThan = '<',
LessThanOrEqualTo = '<=',
Contains = 'contains',
Notcontains = 'notcontains',
Startswith = 'startswith',
Endswith = 'endswith'
}
Which has an empty string for the symbol name of the '<>' enum variant and therefore does not compile. This happens because AbstractTypeScriptClientCodegen#toEnumVarName sanitizes invalid characters using sanitizeName, and <> consists of such invalid characters only, resulting in an empty string.
For a fixed set of strings defined in specialCharReplacements this is solved by providing replacement. I opted for adding a replacement for <> there. With that change the following code is emitted instead (Not_Equal gets sanitized to NotEqual):
/**
*
* @export
* @enum {string}
*/
export enum FilterOp {
Equal = '=',
NotEqual = '<>',
GreaterThan = '>',
GreaterThanOrEqualTo = '>=',
LessThan = '<',
LessThanOrEqualTo = '<=',
Contains = 'contains',
Notcontains = 'notcontains',
Startswith = 'startswith',
Endswith = 'endswith'
}
This merge request solely fixes a specific usecase I have. It does not fix this issue in general, which is that sanitizeName in DefaultCodegen may always result in an empty string for some inputs. I do not know how that would be best addressed.