kontent-ai / model-generator-js

MIT License
13 stars 9 forks source link

Latest version doesn't allow emoticons in Content Type names #34

Closed kentico-michaelb closed 2 weeks ago

kentico-michaelb commented 1 year ago

Brief bug description

In previous versions, the generator allows for emoticons in Content Type names. It replaced these icons with an underscore in the filename and ignores it completely in the type definition.

In v5.8.0, the attached "SyntaxError: Declaration or statement expected." and "UnhandledPromiseRejectionWarning: SyntaxError: Declaration or statement expected." are thrown.

Repro steps

  1. Create a content type with an emoji as the first character (similar to some of our sample sites)
  2. Install v5.8 of the Model Generator
  3. Run kontent-generate against the project with the newly created content type
  4. See the error

Expected behavior

The model generation will complete and substitute "_" for the emoticons or ignore them completely, as they serve a UI-focused purpose.

Test environment

Additional context

Relates to an open support conversation.

Screenshots

Add links to screenshots, if possible. emoticon_content_type_error.txt

jfeyers commented 1 year ago

I'm having a similar issue with Content Type name having a '+" sign in it. It generates a syntax error:

Failed with error:
SyntaxError: '=' expected. (9:26)
   7 | * Codename: cb_image__text
   8 | */
>  9 | export type CampaignImage+Text = IContentItem<{
Enngage commented 1 year ago

Hey guys,

I'm not yet sure how to handle this, so in the meantime I would recommend you to use the contentTypeResolver configuration option. You can pass a function and you generate fully custom name for your types. You can find an example at:

https://github.com/kontent-ai/model-generator-js#customizing-generated-content-type-names

jfeyers commented 1 year ago

Hey guys,

I'm not yet sure how to handle this, so in the meantime I would recommend you to use the contentTypeResolver configuration option. You can pass a function and you generate fully custom name for your types. You can find an example at:

https://github.com/kontent-ai/model-generator-js#customizing-generated-content-type-names

@Enngage This is not working for me. When I copy the example code, I get the following error:

Failed with error:
TypeError: Cannot read properties of undefined (reading 'codename')
    at Object.contentTypeResolver (file:///C:/Vantage/Source/vantage-client/apps/vantage/scripts/kontent-generate.js:20:62)
    at NameHelper.getDeliveryContentTypeName (C:\Vantage\Source\vantage-client\apps\vantage\node_modules\@kontent-ai\model-generator\dist\cjs\lib\name-helper.js:37:28)
    at C:\Vantage\Source\vantage-client\apps\vantage\node_modules\@kontent-ai\model-generator\dist\cjs\lib\generators\delivery\delivery-mappers.js:9:41
    at C:\Vantage\Source\vantage-client\apps\vantage\node_modules\@kontent-ai\model-generator\dist\cjs\lib\generators\delivery\delivery-content-type.generator.js:456:64
    at Array.map (<anonymous>)
    at DeliveryContentTypeGenerator.getLinkedItemsAllowedTypes (C:\Vantage\Source\vantage-client\apps\vantage\node_modules\@kontent-ai\model-generator\dist\cjs\lib\generators\delivery\delivery-content-type.generator.js:456:53)
    at DeliveryContentTypeGenerator.mapElementType (C:\Vantage\Source\vantage-client\apps\vantage\node_modules\@kontent-ai\model-generator\dist\cjs\lib\generators\delivery\delivery-content-type.generator.js:383:53)      
    at DeliveryContentTypeGenerator.getExtendedElements (C:\Vantage\Source\vantage-client\apps\vantage\node_modules\@kontent-ai\model-generator\dist\cjs\lib\generators\delivery\delivery-content-type.generator.js:431:40) 
    at DeliveryContentTypeGenerator.getContentTypeImports (C:\Vantage\Source\vantage-client\apps\vantage\node_modules\@kontent-ai\model-generator\dist\cjs\lib\generators\delivery\delivery-content-type.generator.js:113:39)
    at DeliveryContentTypeGenerator.getModelCode (C:\Vantage\Source\vantage-client\apps\vantage\node_modules\@kontent-ai\model-generator\dist\cjs\lib\generators\delivery\delivery-content-type.generator.js:173:35)        
file:///C:/Vantage/Source/vantage-client/apps/vantage/scripts/kontent-generate.js:20
  contentTypeResolver: (type) => `content_type_${type.system.codename}`,
Enngage commented 1 year ago

Hi @jfeyers,

The sample was indeed incorrect. I've updated the sample code in readme. I would recommend you to use Visual Studio Code as we are exporting types and you will get nice intellisense to help you write the code.

Enngage commented 2 weeks ago

Issues with emoticons and other special chars have been resolved in the upcoming update.