kontent-ai / model-generator-js

MIT License
13 stars 9 forks source link

[Brackets] in content type's name are causing the model generator to fail #40

Closed lukas-lacko closed 2 months ago

lukas-lacko commented 1 year ago

Brief bug description

What went wrong?

When running the model generator while having content type with brackets in its name, the error gets thrown:

Repro steps

  1. Prepare content type with brackets in its name such as [Buggy] brackets
  2. Run content generator
  3. See error

SyntaxError: '=' expected. (9:18) 7 | Codename: buggybrackets 8 | /

9 | export type Buggy[brackets] = IContentItem<{ | ^ 10 | /* 11 | Test (text) 12 | * Required: false

...

throw Error(Failed to process content type '${type.codename}' (${type.name})); ^

Error: Failed to process content type 'buggybrackets' (Buggy[brackets])

Expected behavior

The error does not get thrown and the content type with brackets gets generated.

Test environment

Enngage commented 1 year ago

Hi @lukas-lacko,

yeah, we found out that there could be many different characters used across objects which may cause issues. You may use name resolvers (see readme) to manually strip the name of unwanted characters. I'm also expecting to adjust the model generator to strip more unwanted characters so the custom name resolver might not be needed in future releases.

Enngage commented 2 months ago

This is now fixed by default if no custom configuration is used.