kontent-ai / model-generator-js

MIT License
13 stars 9 forks source link

custom nameResolver could ends as error #19

Closed Simply007 closed 2 years ago

Simply007 commented 3 years ago

Brief bug description

When I run the model generator with codename _3_section_items and using nameResolver as asny value camelCase, pascalCase, snakeCase I get an error.

camelCase or pascalCase

SyntaxError: An identifier or keyword cannot immediately follow a numeric literal. (8:6)
   6 | */
   7 | export type MainMenu = IContentItem<{
>  8 |     3SectionItems: Elements.LinkedItemsElement<IContentItem>;

snakeCase

SyntaxError: Numeric separators are not allowed here. (8:6)
     7 | export type MainMenu = IContentItem<{
>  8 |     3_section_items: Elements.LinkedItemsElement<IContentItem>;

Usage:

    await generateModelsAsync({
        sdkType: 'delivery',
        projectId: process.env.KONTENT_PROJECT_ID,
        addTimestamp: true,
        nameResolver: 'camelCase',
    })

Expected behavior

The model generator does not fail and generates the codename with some prefix.

Additional context

Generation could also fail with a more polished error.

Enngage commented 2 years ago

This has been fixed in the name resolvers in delivery SDK. There is also a test for this specific name (starting with underscore - name )