jsontypedef / json-typedef-codegen

A CLI tool that generates code from JSON Typedef schemas
https://jsontypedef.com/docs/tools/jtd-codegen
MIT License
160 stars 31 forks source link

Fix whitespace across all generated languages #8

Closed ucarion closed 3 years ago

ucarion commented 3 years ago

This PR refactors all code generation to be done with manual printing. This is a necessary evil in order to get "perfect" whitespace generation. For the most part, this means that generated code will always be well-formatted, except for a few cases with very long names or for languages (such as TypeScript) where there is no widely-agreed-upon format for generated code.

This PR also refactors name generation to "normalize" text before attempting to convert it to snake/camel/etc case. This improves the quality of generated names in the face of schemas that use screaming snake case for property or mapping names. The external teeter package is now used only for the purposes of singularizing names.

This PR also includes a comment on the top of every file, noting that the file was generated by jtd-codegen. This can help make it easier to onboard onto a jtd-codegen-using codebase, because it's clear what's hand-written and what's not.

In addition, specifically for Python:

  1. Fixes the style to use for Python dataclass attributes. It's snake case, not pascal case.
  2. Removes dead code in the Python implementation.

This PR makes backwards-incompatible changes to generated Python code. If we were not in v0.X, this would require a major version bump.