aml-org / amf

AMF (AML Modeling Framework) is an open-source library capable of parsing and validating AML metadata documents.
https://a.ml/docs
Other
52 stars 19 forks source link

cannot read property `document` of undefined when calling `amf.plugins.document` #951

Closed jarrodek closed 3 years ago

jarrodek commented 3 years ago

Since the beginning of the project I was always using the following to initialize the API project:

const amf = require('amf-client-js');

amf.plugins.document.WebApi.register();
amf.plugins.document.Vocabularies.register();
amf.plugins.features.AMFValidation.register();

...

The whole tolling for API Console uses this. I just upgraded amf-client-js from 4.7.1 to 4.7.3 and started having erros when parsing API files:

TypeError: Cannot read property 'document' of undefined

Here's the output of running tests with different versions:

4.7.1

ppsztyc@ppsztyc-ltmb5ft api-model-generator % npm test

> @api-components/api-model-generator@0.2.10 test /Users/ppsztyc/workspace/arc/api-model-generator
> mocha 'test/*.test.js' --reporter spec

  API generation
    RAML 1.0 data model generation
      ✓ Generates data model for regular model (360ms)
      ✓ Generates data model for compact model (112ms)
      ✓ generates model with options (Object) (90ms)
      ✓ uses default values (Object) (83ms)
      ✓ generates model with options (Array) (55ms)
      ✓ uses default values (Array) (53ms)
    RAML 0.8 data model generation
      ✓ Generates data model for regular model (78ms)
      ✓ Generates data model for compact model (55ms)
    Api list config file
      ✓ Generates data model for regular model (240ms)
      ✓ Generates data model for compact model (156ms)
    Api list config file with options
      ✓ Generates data model for regular model (53ms)
      ✓ Generates data model for compact model (44ms)
    Function call options overrides file options
      ✓ Generates data model for regular model (50ms)
      ✓ Generates data model for compact model (45ms)
    AsyncAPI 2.0 data model generation
      ✓ Generates data model for regular model (78ms)
      ✓ Generates data model for compact model (80ms)

  16 passing (2s)

Then I am upgrading the client package:

ppsztyc@ppsztyc-ltmb5ft api-model-generator % npm up

+ amf-client-js@4.7.3

(output cleared for readability)

Then the same tests for the current version

4.7.3

[ppsztyc@ppsztyc-ltmb5ft api-model-generator % npm test

> @api-components/api-model-generator@0.2.10 test /Users/ppsztyc/workspace/arc/api-model-generator
> mocha 'test/*.test.js' --reporter spec

TypeError: Cannot read property 'document' of undefined
    at Object.<anonymous> (/Users/ppsztyc/workspace/arc/api-model-generator/index.js:6:13)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/ppsztyc/workspace/arc/api-model-generator/test/api-generation.test.js:5:19)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.exports.requireOrImport (/Users/ppsztyc/workspace/arc/api-model-generator/node_modules/mocha/lib/esm-utils.js:42:12)
    at Object.exports.loadFilesAsync (/Users/ppsztyc/workspace/arc/api-model-generator/node_modules/mocha/lib/esm-utils.js:55:34)
    at Mocha.loadFilesAsync (/Users/ppsztyc/workspace/arc/api-model-generator/node_modules/mocha/lib/mocha.js:473:19)
    at singleRun (/Users/ppsztyc/workspace/arc/api-model-generator/node_modules/mocha/lib/cli/run-helpers.js:125:15)
    at exports.runMocha (/Users/ppsztyc/workspace/arc/api-model-generator/node_modules/mocha/lib/cli/run-helpers.js:190:10)
    at Object.exports.handler (/Users/ppsztyc/workspace/arc/api-model-generator/node_modules/mocha/lib/cli/run.js:362:11)
    at /Users/ppsztyc/workspace/arc/api-model-generator/node_modules/yargs/build/index.cjs:443:71
npm ERR! Test failed.  See above for more details.

This means the API surface has changed between this two patch releases. This also means that there was a breaking change release marked as patch which in a consequence broke tooling built for the previous versions of AMF.

You can check out the project in question here: https://github.com/advanced-rest-client/api-model-generator/blob/master/index.js

nschejtman commented 3 years ago

Hi @jarrodek, we noticed this. You can use 4.7.3-1 instead

jarrodek commented 3 years ago

But this is a pre-release version. I can't use it in a production code @nschejtman

nschejtman commented 3 years ago

4.7.3-1 is actually a hot fix for 4.7.3 meant for production.

We deviated from the traditional semver definition <version core>-<pre-release> and use <version core>-<hot fix> instead