xuri / xgen

XSD (XML Schema Definition) parser and Go/C/Java/Rust/TypeScript code generator
BSD 3-Clause "New" or "Revised" License
339 stars 80 forks source link

Refactor pluralization logic for TypeScript #17

Closed BatmanAoD closed 4 years ago

BatmanAoD commented 4 years ago

Description

Fixes #15. This PR is a little more intrusive/comprehensive than #16.

This moves all pluralization-related logic for type-generation in TypeScript into the genTypeScriptFieldType method. This required changing the method signature.

I did not change any of the other languages. This approach would not be appropriate for C, where the type and its "pluralization" ([]) are separated by the name of the field.

Related Issue

15

Motivation and Context

There is a lot of repetitive code for handling the Array<> logic. This PR simplifies the code and should make the behavior more consistent.

How Has This Been Tested

The TS reference output has been updated and matches the version in #16.

Types of changes

Also, some refactoring

Checklist

Note: The branch name does not include the issue number. If the suggested fix is welcome but the branch name is a blocker, please let me know and I'll fix it.