Skip to content

Improve support for empty and non-ASCII-alphabetic properties, enum values, and definitions #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 2, 2021

Conversation

ucarion
Copy link
Contributor

@ucarion ucarion commented Apr 1, 2021

This PR fixes #16 as well as related issues.

At its base, this PR does two things:

  1. For TypeScript properties in particular, where the name assignment system isn't used at all, this PR adds code that detects properties that are potentially invalid TypeScript identifiers, and escapes those property names.
  2. For all other targets and cases (including TypeScript), this PR alters the identifier assignment code to better handle generating names from strings like "", "1foo", " ", or "\uFDFD".

The name generating logic now has the following invariants:

  1. Non-ASCII alphanumerics are always considered "whitespace", in the sense that they are stripped from names and are considered the boundary of a logical "word".
  2. Logical "words" can only start with ASCII alphabetics. Leading ASCII digits in words are always stripped.
  3. If a name has no non-empty logical "words" within it, then the name will be generated from the logical words "default" and "name", producing default_name, defaultName, etc. depending on the target's chosen casing.

Test cases that exercise these cases are added to all targets. However, Java+Jackson does not support empty property names or enum values, and Go does not support non-ASCII-alphanumeric property names. For this reason, each target's test cases are handled separately. All targets are required to support non-ASCII-alphanumeric definition names, however.

@ucarion ucarion merged commit 82bb8a0 into master Apr 2, 2021
@ucarion ucarion deleted the ucarion/typescript-invalid-properties branch April 2, 2021 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

jtd-codegen generates invalid typescript if the empty string is allowed as an enum value
1 participant