openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[typescript][typescript-node] Serialize/deserialize maps and nullable types correctly

Open simon-abbott opened this issue 1 year ago • 0 comments

There was an edge case in the ObjectSerializer in both the typescript and typescript-node generators where schema objects (object types defined in schema.components) were not properly deserialized if they were contained within a map (an object with additionalProperties) or a nullable array (an array where every entry is either a schema object or null). In these cases the ObjectSerializer would short-circuit and not actually deserialize the object. This results in the snake_cased keys in the API not being converted to the camelCase variants actually documented in the generated typescript types.

I have included tests that cover this (and other) potential encoding and decoding edge cases. I'm sure I didn't cover every possible example, but I did confirm that as-written it will prevent a regression of this issue.

Note: I also removed the TS config setting suppressImplicitAnyIndexErrors from the templates. This was done because suppressImplicitAnyIndexErrors is deprecated, and trying to build with it causes the typescript compiler to error, which was blocking the typescript-node tests from running.

PR checklist

  • [x] Read the contribution guidelines.
  • [x] Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • [x] Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH) Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • [x] File the PR against the correct branch: master (upcoming 7.6.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • [x] If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Mentioning the TS committee members as per the checklist:

@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka

simon-abbott avatar Aug 15 '24 18:08 simon-abbott