kontent-ai / model-generator-js

MIT License
13 stars 9 forks source link

Unable to generate models - Cannot read properties of undefined (reading 'sortTaxonomyTerms') #42

Closed macdermott closed 1 year ago

macdermott commented 1 year ago

Brief bug description

Unable to generate models when calling generateModelsAsync - the error "Cannot read properties of undefined (reading 'sortTaxonomyTerms')" is thrown. v6.2.0 works with the same call to generateModelsAsync.

Repro steps

  1. Call generateModelsAsync with the following parameters (API keys have been removed)
    function generateModels() {
    const models = generateModelsAsync({
    sdkType: 'delivery',
    environmentId: ,
    apiKey: ,
    isEnterpriseSubscription: false,
    elementResolver: 'snakeCase',
    contentTypeResolver: (type) => `${upperFirst(camelCase(type.codename))}Model`,
    taxonomyTypeResolver: (taxonomy) => `${upperFirst(camelCase(taxonomy.codename))}Taxonomy`,
    contentTypeFileResolver:"pascalCase",
    exportProjectSettings : {
      exportWorkflows:false,
      exportCollections:false,
      exportAssetFolders:false,
      exportLanguages:false,
      exportRoles:false,
      exportWebhooks:false
    }
    });
  2. The following error is generated
    
    /Users/ged/project/node_modules/@kontent-ai/model-generator/dist/cjs/lib/generators/project/project.generator.js:467
        const sortedTerms = sortConfig.sortTaxonomyTerms
                                       ^

TypeError: Cannot read properties of undefined (reading 'sortTaxonomyTerms') at ProjectGenerator.getProjectTaxonomiesTerms (/Users/ged/project/node_modules/@kontent-ai/model-generator/dist/cjs/lib/generators/project/project.generator.js:467:40) at ProjectGenerator.getProjectTaxonomies (/Users/ged/project/node_modules/@kontent-ai/model-generator/dist/cjs/lib/generators/project/project.generator.js:413:24) at ProjectGenerator.getProjectModelCode (/Users/ged/project/node_modules/@kontent-ai/model-generator/dist/cjs/lib/generators/project/project.generator.js:166:28) at ProjectGenerator.generateProjectModel (/Users/ged/project/node_modules/@kontent-ai/model-generator/dist/cjs/lib/generators/project/project.generator.js:9:35) at /Users/ged/project/node_modules/@kontent-ai/model-generator/dist/cjs/lib/generator.js:138:74 at Generator.next () at fulfilled (/Users/ged/project/node_modules/@kontent-ai/model-generator/dist/cjs/lib/generator.js:5:58) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)`


### Expected behavior

Models are generated
### Test environment

 - Platform/OS: macOS 13.4.1
 - Browser N/A
 - Version v6.3.0 of @kontent-ai/model-generator library

### Additional context

Add any other context about the problem here.

### Screenshots

Add links to screenshots, if possible.
Enngage commented 1 year ago

Hey @macdermott,

There is a new sortConfig option which is why it fails on your end. I've made the config optional in the latest version.

You could also fix it by providing the option such as:

await generateModelsAsync({
    sdkType: 'delivery',
    environmentId: 'x',
    isEnterpriseSubscription: true,
    apiKey: 'yyy',
    addTimestamp: true,
    elementResolver: 'camelCase',
    sortConfig: {
      sortTaxonomyTerms: true
    }
})
macdermott commented 1 year ago

This worked perfectly. Thank you!