@asyncapi/generator 2.4.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ const nunjucksExport = module.exports;
3
3
 
4
4
  /**
5
5
  * Configures Nunjucks templating system
6
- *
6
+ * @deprecated This method is deprecated. For more details, see the release notes: https://github.com/asyncapi/generator/releases/tag/%40asyncapi%2Fgenerator%402.6.0
7
7
  * @private
8
8
  * @param {boolean} debug flag
9
9
  * @param {string} templateDir path
@@ -17,7 +17,7 @@ nunjucksExport.configureNunjucks = (debug, templateDir) => {
17
17
 
18
18
  /**
19
19
  * Renders the template with nunjucks and returns a string.
20
- *
20
+ * @deprecated This method is deprecated. For more details, see the release notes: https://github.com/asyncapi/generator/releases/tag/%40asyncapi%2Fgenerator%402.6.0
21
21
  * @param {import('@asyncapi/parser').AsyncAPIDocument} asyncapiDocument
22
22
  * @param {string} templateString template filecontent to be rendered with nunjucks
23
23
  * @param {string} filePath path to the template file
@@ -97,7 +97,7 @@ function getParamSuggestion(wrongParam, configParams) {
97
97
  * @param {Object} templateParams All parameters provided to generator
98
98
  */
99
99
  function isProvidedParameterSupported(configParams, templateParams) {
100
- const wrongParams = Object.keys(templateParams || {}).filter(key => !configParams || !configParams[key]);
100
+ const wrongParams = Object.keys(templateParams || {}).filter(key => !configParams?.[key]);
101
101
 
102
102
  if (!wrongParams.length) return;
103
103
  if (!configParams) throw new Error('This template doesn\'t have any params.');
package/lib/utils.js CHANGED
@@ -131,7 +131,7 @@ utils.getGeneratorVersion = () => {
131
131
  * @returns {Boolean} is function asynchronous
132
132
  */
133
133
  utils.isAsyncFunction = (fn) => {
134
- return fn && fn.constructor && fn.constructor.name === 'AsyncFunction';
134
+ return fn?.constructor?.name === 'AsyncFunction';
135
135
  };
136
136
 
137
137
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asyncapi/generator",
3
- "version": "2.4.1",
3
+ "version": "2.6.0",
4
4
  "description": "The AsyncAPI generator. It can generate documentation, code, anything!",
5
5
  "main": "./lib/generator.js",
6
6
  "bin": {
@@ -12,12 +12,11 @@
12
12
  "npm": ">=8.19.0"
13
13
  },
14
14
  "scripts": {
15
- "test": "npm run test:unit && npm run test:integration && npm run test:cli",
15
+ "test": "npm run test:unit && npm run test:integration",
16
16
  "test:unit": "jest --coverage --testPathIgnorePatterns=integration --testPathIgnorePatterns=test-project",
17
17
  "test:dev": "npm run test:unit -- --watchAll",
18
18
  "test:integration": "npm run test:cleanup && jest --testPathPattern=integration --modulePathIgnorePatterns='./__mocks__(?!\\/loglevel\\.js$)'",
19
19
  "test:integration:update": "jest --updateSnapshot --testPathPattern=integration --modulePathIgnorePatterns='./__mocks__(?!\\/loglevel\\.js$)'",
20
- "test:cli": "node cli.js ./test/docs/dummy.yml ./test/test-templates/react-template -o test/output --force-write --debug && test -e test/output/test-file.md",
21
20
  "test:cleanup": "rimraf \"test/temp\"",
22
21
  "docs": "jsdoc2md --partial docs/jsdoc2md-handlebars/custom-sig-name.hbs docs/jsdoc2md-handlebars/main.hbs docs/jsdoc2md-handlebars/docs.hbs docs/jsdoc2md-handlebars/header.hbs docs/jsdoc2md-handlebars/defaultvalue.hbs docs/jsdoc2md-handlebars/link.hbs docs/jsdoc2md-handlebars/params-table.hbs --files lib/generator.js > docs/api.md",
23
22
  "docker:build": "docker build -t asyncapi/generator:latest .",
@@ -49,9 +48,10 @@
49
48
  "license": "Apache-2.0",
50
49
  "homepage": "https://github.com/asyncapi/generator",
51
50
  "dependencies": {
52
- "@asyncapi/generator-react-sdk": "^1.1.1",
51
+ "@asyncapi/generator-react-sdk": "^1.1.2",
53
52
  "@asyncapi/multi-parser": "^2.1.1",
54
53
  "@asyncapi/nunjucks-filters": "*",
54
+ "@asyncapi/generator-hooks": "*",
55
55
  "@asyncapi/parser": "^3.0.14",
56
56
  "@npmcli/arborist": "5.6.3",
57
57
  "@npmcli/config": "^8.0.2",
@@ -81,11 +81,11 @@
81
81
  "eslint-plugin-jest": "^23.8.2",
82
82
  "eslint-plugin-react": "^7.34.1",
83
83
  "eslint-plugin-sonarjs": "^0.5.0",
84
+ "fs-extra": "11.2.0",
84
85
  "jest": "^27.3.1",
85
86
  "jsdoc-to-markdown": "^7.1.1",
86
87
  "markdown-toc": "^1.2.0",
87
88
  "rimraf": "^3.0.2",
88
- "unixify": "^1.0.0",
89
- "fs-extra": "9.1.0"
89
+ "unixify": "^1.0.0"
90
90
  }
91
91
  }
@@ -14,6 +14,400 @@ Version v1 running on production mode
14
14
  "
15
15
  `;
16
16
 
17
+ exports[`Integration testing generateFromFile() to make sure the result of the generation is not changend comparing to snapshot generate using React template 2`] = `
18
+ "asyncapi: '2.3.0'
19
+
20
+ externalDocs:
21
+ description: Find more info here
22
+ url: https://www.asyncapi.com
23
+
24
+ info:
25
+ title: Dummy example with all spec features included
26
+ version: '0.0.1'
27
+ description: |
28
+ This is an example of AsyncAPI specification file that is suppose to include all possible features of the AsyncAPI specification. Do not use it on production.
29
+
30
+ It's goal is to support development of documentation and code generation with the [AsyncAPI Generator](https://github.com/asyncapi/generator/) and [Template projects](https://github.com/search?q=topic%3Aasyncapi+topic%3Agenerator+topic%3Atemplate)
31
+ license:
32
+ name: Apache 2.0
33
+ url: https://www.apache.org/licenses/LICENSE-2.0
34
+ contact:
35
+ name: API Support
36
+ url: http://www.asyncapi.com/support
37
+ email: info@asyncapi.io
38
+ x-twitter: '@AsyncAPISpec'
39
+
40
+ tags:
41
+ - name: root-tag1
42
+ externalDocs:
43
+ description: External docs description 1
44
+ url: https://www.asyncapi.com/
45
+ - name: root-tag2
46
+ description: Description 2
47
+ externalDocs:
48
+ url: \\"https://www.asyncapi.com/\\"
49
+ - name: root-tag3
50
+ - name: root-tag4
51
+ description: Description 4
52
+ - name: root-tag5
53
+ externalDocs:
54
+ url: \\"https://www.asyncapi.com/\\"
55
+
56
+ servers:
57
+ dummy-mqtt:
58
+ $ref: '#/components/servers/dummyMQTT'
59
+ dummy-amqp:
60
+ url: amqp://localhost:{port}
61
+ protocol: amqp
62
+ description: dummy AMQP broker
63
+ protocolVersion: \\"0.9.1\\"
64
+ variables:
65
+ port:
66
+ enum:
67
+ - '15672'
68
+ - '5672'
69
+ security:
70
+ - user-password: []
71
+ dummy-kafka:
72
+ url: http://localhost:{port}
73
+ protocol: kafka
74
+ description: dummy Kafka broker
75
+ variables:
76
+ port:
77
+ default: '9092'
78
+
79
+ defaultContentType: application/json
80
+
81
+ channels:
82
+ dummy/channel/with/{dummy}/parameter/create:
83
+ x-dummy-security:
84
+ $ref: '#/components/securitySchemes/supportedOauthFlows/flows/clientCredentials'
85
+ description: Dummy channel description.
86
+ parameters:
87
+ dummy:
88
+ $ref: '#/components/parameters/dummy'
89
+ publish:
90
+ summary: Inform whenever something dummy is created.
91
+ description: |
92
+ Longer description.
93
+
94
+ Still dummy though.
95
+ operationId: receiveNewDummyInfo
96
+ tags:
97
+ - name: oparation-tag1
98
+ externalDocs:
99
+ description: External docs description 1
100
+ url: https://www.asyncapi.com/
101
+ - name: oparation-tag2
102
+ description: Description 2
103
+ externalDocs:
104
+ url: \\"https://www.asyncapi.com/\\"
105
+ - name: oparation-tag3
106
+ - name: oparation-tag4
107
+ description: Description 4
108
+ - name: oparation-tag5
109
+ externalDocs:
110
+ url: \\"https://www.asyncapi.com/\\"
111
+ traits:
112
+ - $ref: '#/components/operationTraits/kafka'
113
+ message:
114
+ $ref: '#/components/messages/dummyCreated'
115
+
116
+ dummy/channel/without/parameter:
117
+ $ref: '#/components/channels/dummyChannel'
118
+ components:
119
+ servers:
120
+ dummyMQTT:
121
+ url: mqtt://localhost
122
+ protocol: mqtt
123
+ description: dummy MQTT broker
124
+ bindings:
125
+ mqtt:
126
+ clientId: guest
127
+ cleanSession: true
128
+ channels:
129
+ dummyChannel:
130
+ bindings:
131
+ amqp:
132
+ is: routingKey
133
+ subscribe:
134
+ operationId: receiveSystemInfo
135
+ bindings:
136
+ amqp:
137
+ expiration: 100000
138
+ userId: guest
139
+ cc: [ 'user.logs' ]
140
+ priority: 10
141
+ deliveryMode: 2
142
+ mandatory: false
143
+ bcc: [ 'external.audit' ]
144
+ replyTo: user.signedup
145
+ timestamp: true
146
+ ack: false
147
+ bindingVersion: 0.1.0
148
+ message:
149
+ $ref: '#/components/messages/dummyInfo'
150
+ messages:
151
+ dummyCreated:
152
+ name: dummyCreated
153
+ title: Dummy created message
154
+ summary: This is just a dummy create message
155
+ correlationId:
156
+ description: This is a dummy correlation ID.
157
+ location: $message.header#/correlationId
158
+ tags:
159
+ - name: message-tag1
160
+ externalDocs:
161
+ description: External docs description 1
162
+ url: https://www.asyncapi.com/
163
+ - name: message-tag2
164
+ description: Description 2
165
+ externalDocs:
166
+ url: \\"https://www.asyncapi.com/\\"
167
+ - name: message-tag3
168
+ - name: message-tag4
169
+ description: Description 4
170
+ - name: message-tag5
171
+ externalDocs:
172
+ url: \\"https://www.asyncapi.com/\\"
173
+ headers:
174
+ type: object
175
+ properties:
176
+ my-custom-app-header:
177
+ type: string
178
+ correlationId:
179
+ type: string
180
+ payload:
181
+ $ref: \\"#/components/schemas/dummyCreated\\"
182
+ bindings:
183
+ kafka:
184
+ key:
185
+ type: object
186
+ properties:
187
+ id:
188
+ type: string
189
+ format: uuid
190
+ type:
191
+ type: string
192
+ enum: [ 'type1', \\"type2\\" ]
193
+ bindingVersion: '0.1.0'
194
+ amqp:
195
+ contentEncoding: gzip
196
+ messageType: 'user.signup'
197
+ bindingVersion: 0.1.0
198
+ x-response:
199
+ $ref: \\"#/components/messages/dummyInfo\\"
200
+ dummyInfo:
201
+ name: dummyInfo
202
+ title: Dummy system info
203
+ summary: This is just a dummy info message
204
+ correlationId:
205
+ location: $message.header#/correlationId
206
+ description: |
207
+ More description for a dummy message.
208
+
209
+ It is a dummy system info message.
210
+ traits:
211
+ - $ref: '#/components/messageTraits/commonHeaders'
212
+ payload:
213
+ $ref: \\"#/components/schemas/dummyInfo\\"
214
+ examples:
215
+ - name: option1example
216
+ summary: this is dummy summary for option1example
217
+ headers:
218
+ my-app-header: 12
219
+ payload:
220
+ prop1: option1
221
+ sentAt: 2020-01-31T13:24:53Z
222
+ - name: headerExample
223
+ headers:
224
+ my-app-header: 13
225
+ - payload:
226
+ prop1: option2
227
+ sentAt: 2020-01-31T13:24:53Z
228
+
229
+
230
+ schemas:
231
+ dummyCreated:
232
+ type: object
233
+ required:
234
+ - prop2
235
+ x-schema-extensions-as-object:
236
+ type: object
237
+ properties:
238
+ prop1:
239
+ type: string
240
+ prop2:
241
+ type: integer
242
+ minimum: 0
243
+ x-schema-extensions-as-primitive: dummy
244
+ x-schema-extensions-as-array:
245
+ - \\"item1\\"
246
+ - \\"item2\\"
247
+ properties:
248
+ prop1:
249
+ type: integer
250
+ minimum: 0
251
+ description: Dummy prop1
252
+ x-prop1-dummy: dummy extension
253
+ prop2:
254
+ type: string
255
+ description: Dummy prop2
256
+ sentAt:
257
+ $ref: \\"#/components/schemas/sentAt\\"
258
+ dummyArrayWithObject:
259
+ $ref: \\"#/components/schemas/dummyArrayWithObject\\"
260
+ dummyArrayWithArray:
261
+ $ref: \\"#/components/schemas/dummyArrayWithArray\\"
262
+ dummyObject:
263
+ $ref: \\"#/components/schemas/dummyObject\\"
264
+ dummyArrayRank:
265
+ $ref: '#/components/schemas/dummyArrayRank'
266
+ dummyInfo:
267
+ type: object
268
+ required:
269
+ - prop1
270
+ properties:
271
+ prop1:
272
+ type: string
273
+ enum:
274
+ - option1
275
+ - option2
276
+ description: Dummy prop1
277
+ sentAt:
278
+ $ref: \\"#/components/schemas/sentAt\\"
279
+ dummyArrayWithObject:
280
+ type: array
281
+ items:
282
+ $ref: \\"#/components/schemas/dummyInfo\\"
283
+ dummyArrayWithArray:
284
+ type: array
285
+ items:
286
+ - $ref: \\"#/components/schemas/dummyInfo\\"
287
+ - type: string
288
+ - type: number
289
+ dummyObject:
290
+ type: object
291
+ properties:
292
+ dummyObjectProp1:
293
+ $ref: \\"#/components/schemas/sentAt\\"
294
+ dummyObjectProp2:
295
+ $ref: \\"#/components/schemas/dummyRecursiveObject\\"
296
+ dummyObjectProp3:
297
+ type: object
298
+ additionalProperties: true
299
+ dummyObjectProp4:
300
+ type: object
301
+ additionalProperties: false
302
+ dummyRecursiveObject:
303
+ type: object
304
+ properties:
305
+ dummyRecursiveProp1:
306
+ $ref: \\"#/components/schemas/dummyObject\\"
307
+ dummyRecursiveProp2:
308
+ type: string
309
+ sentAt:
310
+ type: string
311
+ format: date-time
312
+ description: Date and time when the message was sent.
313
+ dummyArrayRank:
314
+ type: object
315
+ properties:
316
+ dummyArrayValueRank:
317
+ $ref: '#/components/schemas/dummyArrayValueRank'
318
+ dummyArrayDimensions:
319
+ $ref: '#/components/schemas/dummyArrayArrayDimensions'
320
+ dummyArrayValueRank:
321
+ description: >
322
+ This Attribute indicates whether the val Attribute of the datapoint is an
323
+ array and how many dimensions the array has.
324
+ type: integer
325
+ default: -1
326
+ examples:
327
+ - 2
328
+ oneOf:
329
+ - const: -1
330
+ description: 'Scalar: The value is not an array.'
331
+ - const: 0
332
+ description: 'OneOrMoreDimensions: The value is an array with one or more dimensions.'
333
+ - const: 1
334
+ description: 'OneDimension: The value is an array with one dimension.'
335
+ - const: 2
336
+ description: 'The value is an array with two dimensions.'
337
+ dummyArrayArrayDimensions:
338
+ type: array
339
+ items:
340
+ type: integer
341
+ minimum: 0
342
+ examples:
343
+ - [3, 5]
344
+
345
+ securitySchemes:
346
+ user-password:
347
+ type: userPassword
348
+ apiKey:
349
+ type: apiKey
350
+ in: user
351
+ description: Provide your API key as the user and leave the password empty.
352
+ supportedOauthFlows:
353
+ type: oauth2
354
+ description: Flows to support OAuth 2.0
355
+ flows:
356
+ implicit:
357
+ authorizationUrl: 'https://authserver.example/auth'
358
+ scopes:
359
+ 'dummy:created': Ability to create dummy message
360
+ 'dymmy:read': Ability to read dummy info
361
+ password:
362
+ tokenUrl: 'https://authserver.example/token'
363
+ scopes:
364
+ 'dummy:created': Ability to create dummy message
365
+ 'dymmy:read': Ability to read dummy info
366
+ clientCredentials:
367
+ tokenUrl: 'https://authserver.example/token'
368
+ scopes:
369
+ 'dummy:created': Ability to create dummy message
370
+ 'dymmy:read': Ability to read dummy info
371
+ authorizationCode:
372
+ authorizationUrl: 'https://authserver.example/auth'
373
+ tokenUrl: 'https://authserver.example/token'
374
+ refreshUrl: 'https://authserver.example/refresh'
375
+ scopes:
376
+ 'dummy:created': Ability to create dummy message
377
+ 'dymmy:read': Ability to read dummy info
378
+ openIdConnectWellKnown:
379
+ type: openIdConnect
380
+ openIdConnectUrl: 'https://authserver.example/.well-known'
381
+
382
+ parameters:
383
+ dummy:
384
+ description: The ID of the new dummy message.
385
+ schema:
386
+ type: string
387
+ description: Description that not be rendered, as parameter has explicit description.
388
+
389
+ messageTraits:
390
+ commonHeaders:
391
+ headers:
392
+ type: object
393
+ properties:
394
+ my-app-header:
395
+ type: integer
396
+ minimum: 0
397
+ maximum: 100
398
+ correlationId:
399
+ type: string
400
+
401
+ operationTraits:
402
+ kafka:
403
+ bindings:
404
+ kafka:
405
+ groupId: my-app-group-id
406
+ clientId: my-app-client-id
407
+ bindingVersion: '0.1.0'
408
+ "
409
+ `;
410
+
17
411
  exports[`Integration testing generateFromFile() to make sure the result of the generation is not changend comparing to snapshot generated using Nunjucks template 1`] = `
18
412
  "This is a markdown file for my application.
19
413
  App name is: **Dummy example with all spec features included**
@@ -10,11 +10,11 @@ const dummySpecPath = path.resolve(__dirname, './docs/dummy.yml');
10
10
  const refSpecPath = path.resolve(__dirname, './docs/apiwithref.json');
11
11
  const refSpecFolder = path.resolve(__dirname, './docs/');
12
12
  const crypto = require('crypto');
13
- const mainTestResultPath = 'test/temp/integrationTestResult';
14
- const reactTemplate = 'test/test-templates/react-template';
15
- const nunjucksTemplate = 'test/test-templates/nunjucks-template';
13
+ const mainTestResultPath = path.resolve(__dirname, './temp/integrationTestResult');
14
+ const reactTemplate = path.resolve(__dirname, './test-templates/react-template');
15
+ const nunjucksTemplate = path.resolve(__dirname, './test-templates/nunjucks-template');
16
16
  //temp location where react template is copied for each test that does some mutation on template files
17
- const copyOfReactTemplate = 'test/temp/reactTemplate';
17
+ const copyOfReactTemplate = path.resolve(__dirname, './temp/reactTemplate');
18
18
 
19
19
  describe('Integration testing generateFromFile() to make sure the result of the generation is not changend comparing to snapshot', () => {
20
20
  const generateFolderName = () => {
@@ -62,8 +62,11 @@ describe('Integration testing generateFromFile() to make sure the result of the
62
62
  templateParams: { version: 'v1', mode: 'production' }
63
63
  });
64
64
  await generator.generateFromFile(dummySpecPath);
65
- const file = await readFile(path.join(outputDir, testOutputFile), 'utf8');
66
- expect(file).toMatchSnapshot();
65
+ const mdFile = await readFile(path.join(outputDir, testOutputFile), 'utf8');
66
+ //react template has hooks lib enabled and generation of asyncapi document that was passed as input should work out of the box without adding @asyncapi/generator-hooks to dependencies
67
+ const asyncAPIFile = await readFile(path.join(outputDir, 'asyncapi.yaml'), 'utf8');
68
+ expect(mdFile).toMatchSnapshot();
69
+ expect(asyncAPIFile).toMatchSnapshot();
67
70
  });
68
71
 
69
72
  it('generate json based api with referenced JSON Schema', async () => {
@@ -10,8 +10,8 @@ jest.mock('@asyncapi/generator-react-sdk');
10
10
 
11
11
  describe('React renderer', () => {
12
12
  describe('saveRenderedReactContent', () => {
13
- let util = undefined;
14
- let AsyncReactSDK = undefined;
13
+ let util;
14
+ let AsyncReactSDK;
15
15
  beforeAll(() => {
16
16
  util = require('../lib/utils');
17
17
  AsyncReactSDK = require('@asyncapi/generator-react-sdk');
@@ -11,7 +11,6 @@
11
11
  "test:cleanup": "rimraf \"../temp\""
12
12
  },
13
13
  "devDependencies": {
14
- "fs-extra": "9.1.0",
15
14
  "jest": "28.1.3",
16
15
  "rimraf": "3.0.2"
17
16
  },
@@ -71,6 +71,11 @@ Publish test template to local npm-verdaccio
71
71
  npm config set -- //verdaccio:4873/:_auth=YWRtaW46bmltZGE=
72
72
  npm config set registry http://verdaccio:4873
73
73
 
74
+ echo "##########
75
+ Publish @asyncapi/generator-components to local npm-verdaccio
76
+ ##########"
77
+ npm publish ../../../../packages/components
78
+
74
79
  echo "##########
75
80
  Publishing the correct template as 0.0.1
76
81
  ##########"
@@ -10,7 +10,13 @@ packages:
10
10
  "react-template":
11
11
  access: admin
12
12
  publish: admin
13
+ "@asyncapi/generator-components":
14
+ access: admin
15
+ publish: admin
13
16
  "!react-template":
14
17
  access: admin
15
18
  proxy: npmjs
19
+ "!@asyncapi/generator-components":
20
+ access: admin
21
+ proxy: npmjs
16
22
  log: { type: stdout, format: pretty, level: error }