Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9521
Closed
Open
Issue created May 19, 2021 by Administrator@rootContributor

[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.

Assignee
Assign to
Time tracking