[BUG] Incorrect (de)serialization of reserved words (typescript-angular)
Created by: ramondeklein
Bug Report Checklist
Description
The typescript-angular code generator does escape reserved words, but doesn't annotate these fields so the (de)serializer doesn't properly (de)serializes these fields. Assume that an API defines a Counting
object that only holds an in
field. This specified an object-type called Counting
that has only an in
field. This is emitted like this:
export interface Counting {
_in?: number;
}
Clients will write the _in
field (with an underscore) and it will be serialized as { "_in": 123 }
which won't be understood by the server. The same problem occurs when the server sends { "in": 123 }
and it will be stored in a Javascript object that contains the in
field. But clients will look for the _in
field that is undefined
.
openapi-generator version
This was checked with the latest openapi generator (v5.2.0).
OpenAPI declaration file content or url
{
"openapi": "3.0.1",
"info": {
"title": "TEST",
"version": "v1"
},
"paths": {},
"components": {
"schemas": {
"Counting": {
"type": "object",
"properties": {
"in": {
"type": "integer",
"format": "int32"
}
}
}
}
}
}
Possible fix
The generated code will use the standard Angular HttpClient. Unfortunately, this class uses the standard json functions json.stringify
and json.parse
, so there is no standard way to fix the JSON serialization.
An option could be to annotate the fields (just like the standard typescript
generator does) and to add an Angular HttpInterceptor that performs the actual JSON serialization and takes this mapping into account. It would also require the registration of the HTTP interceptor in the pipeline.
Another option would be to abort code-generation when reserved words are encountered in the model. Now, it silently fails to work and may go unnoticed. Aborting code-generation indicates there is a bug in the code.