[BUG][C#] Shouldn't replace tab, cr, lf in string enum values
Created by: kevinoid
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
The EnumMember.Value generated for csharp (and csharp-netcore) replaces \t, \r, and \n characters with space characters. This causes values sent from the server to fail to deserialize and values sent to the server to not match the specified values.
openapi-generator version
Tested with 4.2.2 and current master (2d24d42e).
OpenAPI declaration file content or url
Example OpenAPI document
{
"swagger": "2.0",
"info": {
"title": "Problematic enum strings example",
"version": "1.0.0"
},
"definitions": {
"ErrorMessage": {
"type": "string",
"enum": [
"RangeError:\tToo many items.",
"TypeError:\tInvalid type.\nCan't count multiple types.",
"TypeError:\tInvalid type.\r\nCan't count multiple types."
]
}
},
"paths": {
"/count": {
"get": {
"operationId": "getCount",
"responses": {
"200": {
"description": "Success",
"schema": {
"type": "integer"
}
},
"default": {
"description": "Error",
"schema": {
"$ref": "#/definitions/ErrorMessage"
}
}
}
}
}
}
}
Command line used for generation
openapi-generator generate -g csharp -i openapi.json -o generated
Steps to reproduce
- Copy example OpenAPI document into
openapi.json. - Run above command.
- Observe that
EnumMember.Valueingenerated/openapi/src/Org.OpenAPITools/Model/ErrorMessage.csdoes not matchenuminopenapi.json.
Related issues/PRs
None that I could find.
Suggest a fix
DefaultCodegen.escapeText could skip removal of \t\r\n or DefaultCodegen.toEnumValue could use a different method for escaping.
Thanks for considering, Kevin