@asyncapi/generator 3.1.1 → 3.2.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.
Files changed (30) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/docs/api_components.md +1233 -0
  3. package/docs/generator-template.md +75 -65
  4. package/docs/model-generation.md +1 -1
  5. package/docs/usage.md +9 -9
  6. package/docs/versioning.md +1 -2
  7. package/lib/conditionalGeneration.js +3 -6
  8. package/lib/templates/bakedInTemplates/core-template-client-kafka-java-quarkus/README.md +1 -1
  9. package/lib/templates/bakedInTemplates/core-template-client-kafka-java-quarkus/package.json +1 -2
  10. package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/package.json +0 -1
  11. package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/.ageneratorrc +1 -1
  12. package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/README.md +1 -1
  13. package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/package.json +2 -3
  14. package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/README.md +1 -1
  15. package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/CompileOperationSchemas.js +7 -0
  16. package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/CompileOperationSchemas.js.map +1 -1
  17. package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/template/client.js.js +7 -0
  18. package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/template/client.js.js.map +1 -1
  19. package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/components/CompileOperationSchemas.js +7 -0
  20. package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/package.json +4 -4
  21. package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/ReceiveOperationsDiscriminators.js +1 -5
  22. package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/ReceiveOperationsDiscriminators.js.map +1 -1
  23. package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/Send.js +2 -2
  24. package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/Send.js.map +1 -1
  25. package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/template/client.py.js +3 -7
  26. package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/template/client.py.js.map +1 -1
  27. package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/ReceiveOperationsDiscriminators.js +3 -6
  28. package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/Send.js +2 -2
  29. package/lib/templates/bakedInTemplates/core-template-client-websocket-python/package.json +0 -1
  30. package/package.json +4 -4
@@ -9,7 +9,7 @@ Suppose you can only sleep when the AC in your bedroom is set to 22 °C, and you
9
9
 
10
10
  In this tutorial:
11
11
 
12
- - You'll use the [Eclipse Mosquito](https://test.mosquitto.org) **MQTT broker**, which you'll connect to subscribe and publish messages using an MQTT client.
12
+ - You'll use the [Eclipse Mosquitto](https://test.mosquitto.org) **MQTT broker**, which you'll connect to subscribe and publish messages using an MQTT client.
13
13
  - You'll use [Python Paho-MQTT](https://pypi.org/project/paho-mqtt/) as the **MQTT client** in this project.
14
14
  - You'll create a React template that will use the MQTT broker to allow you to monitor your bedroom's temperature and notify you when the temperature drops or rises above 22 °C.
15
15
  - Lastly, create a reusable component for the output code's `sendTemperatureDrop` and `sendTemperatureRise` functions.
@@ -44,7 +44,7 @@ Before you create the template, you'll need to have an [AsyncAPI document](https
44
44
 
45
45
  ``` yml
46
46
 
47
- asyncapi: 2.6.0
47
+ asyncapi: 3.0.1
48
48
 
49
49
  info:
50
50
  title: Temperature Service
@@ -53,22 +53,26 @@ info:
53
53
 
54
54
  servers:
55
55
  dev:
56
- url: test.mosquitto.org #in case you're using local mosquitto instance, change this value to localhost.
56
+ host: test.mosquitto.org #in case you're using local mosquitto instance, change this value to localhost.
57
57
  protocol: mqtt
58
58
 
59
59
  channels:
60
- temperature/changed:
61
- description: Updates the bedroom temperature in the database when the temperatures drops or goes up.
62
- publish:
63
- operationId: temperatureChange
64
- message:
60
+ temperatureChanged:
61
+ address: temperature/changed
62
+ messages:
63
+ temperatureChange:
65
64
  description: Message that is being sent when the temperature in the bedroom changes.
66
65
  payload:
67
- type: object
68
- additionalProperties: false
69
- properties:
70
- temperatureId:
71
- type: string
66
+ $ref: '#/components/schemas/temperatureId'
67
+ description: Updates the bedroom temperature in the database when the temperatures drops or goes up.
68
+
69
+ operations:
70
+ temperatureChange:
71
+ action: receive
72
+ summary: Message sent to the broker when the temperature is changed.
73
+ channel:
74
+ $ref: '#/channels/temperatureChanged'
75
+
72
76
  components:
73
77
  schemas:
74
78
  temperatureId:
@@ -112,8 +116,8 @@ The **package.json** file is used to define the dependencies for your template.
112
116
  "version": "0.0.1",
113
117
  "description": "A template that generates a Python MQTT client using MQTT.",
114
118
  "generator": {
115
- "apiVersion": "v1",
116
- "generator": ">=1.10.0 <2.0.0",
119
+ "apiVersion": "v3",
120
+ "generator": ">=2.0.0 <4.0.0",
117
121
  "supportedProtocols": ["mqtt"]
118
122
  },
119
123
  "dependencies": {
@@ -326,8 +330,8 @@ In **package.json** you can have the scripts property that you invoke by calling
326
330
  "test": "npm run test:clean && npm run test:generate && npm run test:start"
327
331
  },
328
332
  "generator": {
329
- "apiVersion": "v1",
330
- "generator": ">=1.10.0 <2.0.0",
333
+ "apiVersion": "v3",
334
+ "generator": ">=2.0.0 <4.0.0",
331
335
  "supportedProtocols": ["mqtt"]
332
336
  },
333
337
  "dependencies": {
@@ -357,7 +361,7 @@ You often have different runtime environments in programming, e.g., development
357
361
  ```yml
358
362
  servers:
359
363
  dev:
360
- url: test.mosquitto.org
364
+ host: test.mosquitto.org
361
365
  protocol: mqtt
362
366
  ```
363
367
 
@@ -391,7 +395,7 @@ Update your `test:generate` script in **package.json** to include the server par
391
395
  "test:generate": "asyncapi generate fromTemplate test/fixtures/asyncapi.yml ./ --output test/project --force-write --param server=dev"
392
396
  ```
393
397
 
394
- You can now replace the static broker from `mqttBroker = 'test.mosquitto.org'` to `mqttBroker = "${asyncapi.servers().get(params.server).url()}"` in **index.js**.
398
+ You can now replace the static broker from `mqttBroker = 'test.mosquitto.org'` to `mqttBroker = "${asyncapi.servers().get(params.server).host()}"` in **index.js**.
395
399
 
396
400
  Now the template code looks like this:
397
401
 
@@ -405,7 +409,7 @@ export default function ({ asyncapi, params }) {
405
409
  <File name="client.py">
406
410
  {`import paho.mqtt.client as mqtt
407
411
 
408
- mqttBroker = "${asyncapi.servers().get(params.server).url()}"
412
+ mqttBroker = "${asyncapi.servers().get(params.server).host()}"
409
413
 
410
414
  class TemperatureServiceClient:
411
415
  def __init__(self):
@@ -436,7 +440,7 @@ export default function ({ asyncapi, params }) {
436
440
  // 2
437
441
  <Text newLines={2}>import paho.mqtt.client as mqtt</Text>
438
442
  // 3
439
- <Text newLines={2}>mqttBroker = "{asyncapi.servers().get(params.server).url()}"</Text>
443
+ <Text newLines={2}>mqttBroker = "{asyncapi.servers().get(params.server).host()}"</Text>
440
444
  // 4
441
445
  <Text newLines={2}>class {asyncapi.info().title().replaceAll(' ', '')}Client:</Text>
442
446
  // 5
@@ -483,23 +487,23 @@ class TemperatureServiceClient:
483
487
 
484
488
  ```
485
489
 
486
- You'll then need to template to dynamically generate `sendTemperatureDrop` and `sendTemperatureRise` functions in the generated code based off the AsyncAPI document content. The goal is to write template code that returns functions for channels that the Temperature Service application is subscribed to. The template code to generate these functions will look like this:
490
+ You'll then need a template to dynamically generate `sendTemperatureDrop` and `sendTemperatureRise` functions in the generated code based off the AsyncAPI document content. The goal is to write template code that returns functions for operations marked with `action: receive`, using their associated channels. The template code to generate these functions will look like this:
487
491
 
488
492
  ```js
489
493
  <Text indent={2} newLines={2}>
490
- <TopicFunction channels={asyncapi.channels().filterByReceive()} />
494
+ <TopicFunction operations={asyncapi.operations().filterByReceive()} />
491
495
  </Text>
492
496
  ```
493
497
 
494
- It's recommended to put reusable components outside the template directory in a new directory called components. You'll create a component that will dynamically generate functions in the output for as many channels as there are in your AsyncAPI document that contains a `publish` operation. Add the following code in the **python-mqtt-client-template/components/TopicFunction.js** file, after creating the **python-mqtt-client-template/components/** directory:
498
+ It's recommended to put reusable components outside the template directory in a new directory called components. You'll create a component that will dynamically generate functions in the output for as many operations as there are in your AsyncAPI document that are marked with `action: receive`. Add the following code in the **python-mqtt-client-template/components/TopicFunction.js** file, after creating the **python-mqtt-client-template/components/** directory:
495
499
 
496
500
  ```js
497
501
  /*
498
502
  * This component returns a block of functions that user can use to send messages to specific topic.
499
- * As input it requires a list of Channel models from the parsed AsyncAPI document
503
+ * As input it requires a list of Operation models from the parsed AsyncAPI document marked with `action: receive`.
500
504
  */
501
- export function TopicFunction({ channels }) {
502
- const topicsDetails = getTopics(channels);
505
+ export function TopicFunction({ operations }) {
506
+ const topicsDetails = getTopics(operations);
503
507
  let functions = '';
504
508
 
505
509
  topicsDetails.forEach((t) => {
@@ -518,25 +522,28 @@ export function TopicFunction({ channels }) {
518
522
  *
519
523
  * As input it requires a list of Channel models from the parsed AsyncAPI document
520
524
  */
521
- function getTopics(channels) {
522
- const channelsCanSendTo = channels;
525
+ function getTopics(operations) {
523
526
  let topicsDetails = [];
524
527
 
525
- channelsCanSendTo.forEach((ch) => {
526
- const topic = {};
527
- const operationId = ch.operations().filterByReceive()[0].id();
528
- topic.name = operationId.charAt(0).toUpperCase() + operationId.slice(1);
529
- topic.topic = ch.address();
530
-
531
- topicsDetails.push(topic);
532
- })
533
-
528
+ operations.forEach((op) => {
529
+ const channels = op.channels().all();
530
+ if (!channels.length) return;
531
+
532
+ const channel = channels[0];
533
+ const operationId = op.operationId() || op.id();
534
+
535
+ topicsDetails.push({
536
+ name: operationId.charAt(0).toUpperCase() + operationId.slice(1),
537
+ topic: channel.address()
538
+ });
539
+ });
540
+
534
541
  return topicsDetails;
535
542
  }
536
543
  ```
537
544
 
538
- `{ channels }`: the `TopicFunction` component accepts a custom prop called channels and in your template code
539
- `getTopics(channels)`: Returns a list of objects, one for each channel with two properties; name and topic. The **name** holds information about the `operationId` provided in the AsyncAPI document while the **topic** holds information about the address of the topic.
545
+ `{ operations }`: the `TopicFunction` component accepts a custom prop called operations and in your template code
546
+ `getTopics(operations)`: Returns a list of objects, one for each operation with two properties; name and topic. The **name** holds information about the `operationId` provided in the AsyncAPI document (or a generated ID if operationId is not set) while the **topic** holds information about the address of the topic from the operation's associated channel.
540
547
 
541
548
  Import the `TopicFunction` component in your template code in **index.js** and add the template code to generate the functions to topics that the `Temperature Service` application is subscribed to. In your case, the final version of your template code should look like this:
542
549
 
@@ -549,7 +556,7 @@ export default function ({ asyncapi, params }) {
549
556
  <File name="client.py">
550
557
  <Text newLines={2}>import paho.mqtt.client as mqtt</Text>
551
558
 
552
- <Text newLines={2}>mqttBroker = "{asyncapi.servers().get(params.server).url()}"</Text>
559
+ <Text newLines={2}>mqttBroker = "{asyncapi.servers().get(params.server).host()}"</Text>
553
560
 
554
561
  <Text newLines={2}>class {asyncapi.info().title().replaceAll(' ', '')}Client:</Text>
555
562
 
@@ -560,7 +567,7 @@ export default function ({ asyncapi, params }) {
560
567
  </Text>
561
568
 
562
569
  <Text indent={2} newLines={2}>
563
- <TopicFunction channels={asyncapi.channels().filterByReceive()} />
570
+ <TopicFunction operations={asyncapi.operations().filterByReceive()} />
564
571
  </Text>
565
572
  </File>
566
573
  )
@@ -587,7 +594,7 @@ python-mqtt-client-template
587
594
 
588
595
  Run `npm test` on your terminal to ensure everything works as expected.
589
596
 
590
- In the next section, you'll add another channel to **asyncapi.yml** file called `temperature/dropped` and `temperature/risen` then run the template again to make sure it still works as expected.
597
+ In the next section, you'll add another channel to **asyncapi.yml** file called `temperatureDropped` and `temperatureRisen` then run the template again to make sure it still works as expected.
591
598
 
592
599
  #### 5d. Update AsyncAPI document
593
600
 
@@ -595,31 +602,34 @@ Update the AsyncAPI document to use two channels:
595
602
 
596
603
  ```yml
597
604
  channels:
598
- temperature/dropped:
599
- description: Notifies the user when the temperature drops past a certain point.
600
- publish:
601
- operationId: temperatureDrop
602
- message:
605
+ temperatureDropped:
606
+ address: temperature/dropped
607
+ messages:
608
+ temperatureDrop:
603
609
  description: Message that is being sent when the temperature drops past a certain point.
604
610
  payload:
605
- type: object
606
- additionalProperties: false
607
- properties:
608
- temperatureId:
609
- type: string
610
-
611
- temperature/risen:
612
- description: Notifies the user when the temperature rises past a certain point.
613
- publish:
614
- operationId: temperatureRise
615
- message:
611
+ $ref: '#/components/schemas/temperatureId'
612
+ description: Notifies the user when the temperature drops past a certain point.
613
+ temperatureRisen:
614
+ address: temperature/risen
615
+ messages:
616
+ temperatureRise:
616
617
  description: Message that is being sent when the temperature rises past a certain point.
617
618
  payload:
618
- type: object
619
- additionalProperties: false
620
- properties:
621
- temperatureId:
622
- type: string
619
+ $ref: '#/components/schemas/temperatureId'
620
+ description: Notifies the user when the temperature rises past a certain point.
621
+
622
+ operations:
623
+ temperatureDrop:
624
+ action: receive
625
+ summary: Message sent to the broker when the temperature is dropped.
626
+ channel:
627
+ $ref: '#/channels/temperatureDropped'
628
+ temperatureRise:
629
+ action: receive
630
+ summary: Message sent to the broker when the temperature is risen.
631
+ channel:
632
+ $ref: '#/channels/temperatureRisen'
623
633
  ```
624
634
 
625
635
  And update your test script in test.py to test the two functions as below:
@@ -644,6 +654,6 @@ Temperature rise detected 66943992 sent to temperature/risen
644
654
 
645
655
  Great job completing this tutorial! You have learnt how to use an AsyncAPI file to create a Python MQTT template and used it with the Paho-MQTT library in Python to connect to an MQTT broker and publish messages.😃
646
656
 
647
- If you want to tinker with a completed template and see what it would look like in production, check out the [Paho-MQTT template](https://github.com/derberg/python-mqtt-client-template/tree/v1.0.0). You can also check out the accompanying [article about creating MQTT client code](https://www.brainfart.dev/blog/asyncapi-codegen-python).
657
+ If you want to tinker with a completed template and see what it would look like in production, check out the [Paho-MQTT template](https://github.com/Harsh16gupta/asyncapi-v3-template-final).
648
658
 
649
659
  You can also check out the [MQTT beginners guide](https://medium.com/python-point/mqtt-basics-with-python-examples-7c758e605d4) tutorial to learn more about asynchronous messaging using MQTT.
@@ -5,7 +5,7 @@ weight: 200
5
5
 
6
6
  This guide will walk you through the process of enabling models/types generation in a template by using [Modelina](https://www.asyncapi.com/tools/modelina).
7
7
 
8
- Modelina is an AsyncAPI library designed for generating data models using inputs such as [AsyncAPI](generator/asyncapi-document), OpenAPI, or JSON schema inputs. Its functionality revolves around creating data models from the provided AsyncAPI document and the model template, which defines message payloads. It is better to use Modelina in your template to handle model generation rather than providing custom templates.
8
+ Modelina is an AsyncAPI library designed for generating data models using inputs such as [AsyncAPI](asyncapi-document), OpenAPI, or JSON schema inputs. Its functionality revolves around creating data models from the provided AsyncAPI document and the model template, which defines message payloads. It is better to use Modelina in your template to handle model generation rather than providing custom templates.
9
9
 
10
10
  You can integrate the work shown in this guide into a template by following the [tutorial about creating a template](https://www.asyncapi.com/docs/tools/generator/generator-template).
11
11
 
package/docs/usage.md CHANGED
@@ -40,29 +40,29 @@ asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template
40
40
 
41
41
  **The shortest possible syntax:**
42
42
  ```bash
43
- asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template@3.0.0 --use-new-generator
43
+ asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template@3.5.4
44
44
  ```
45
45
 
46
46
  **Generating from a URL:**
47
47
  ```bash
48
- asyncapi generate fromTemplate https://bit.ly/asyncapi @asyncapi/html-template@3.0.0 --use-new-generator
48
+ asyncapi generate fromTemplate https://bit.ly/asyncapi @asyncapi/html-template@3.5.4
49
49
  ```
50
50
 
51
51
  **Specify where to put the result:**
52
52
  ```bash
53
- asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template@3.0.0 --use-new-generator -o ./docs
53
+ asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template@3.5.4 -o ./docs
54
54
  ```
55
55
 
56
56
  **Passing parameters to templates:**
57
57
  ```bash
58
- asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template@3.0.0 --use-new-generator -o ./docs -p title='Hello from param'
58
+ asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template@3.5.4 -o ./docs -p title='Hello from param'
59
59
  ```
60
60
 
61
- In the template you can use it like this: ` {{ params.title }}`
61
+ In the template you can use it like this: `{{ params.title }}`
62
62
 
63
63
  **Disabling the hooks:**
64
64
  ```bash
65
- asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template@3.0.0 --use-new-generator -o ./docs -d generate:before generate:after=foo,bar
65
+ asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template@3.5.4 -o ./docs -d generate:before generate:after=foo,bar
66
66
  ```
67
67
 
68
68
  The generator skips all hooks of the `generate:before` type and `foo`, `bar` hooks of the `generate:after` type.
@@ -81,7 +81,7 @@ asyncapi generate fromTemplate asyncapi.yaml https://github.com/asyncapi/html-te
81
81
 
82
82
  **Map schema references from baseUrl to local folder:**
83
83
  ```bash
84
- asyncapi generate fromTemplate test/docs/apiwithref.json @asyncapi/html-template@3.0.0 --use-new-generator -o ./build/ --force-write --map-base-url https://schema.example.com/crm/:./test/docs/
84
+ asyncapi generate fromTemplate test/docs/apiwithref.json @asyncapi/html-template@3.5.4 -o ./build/ --force-write --map-base-url https://schema.example.com/crm/:./test/docs/
85
85
  ```
86
86
 
87
87
  The parameter `--map-base-url` maps external schema references to local folders.
@@ -104,7 +104,7 @@ docker run --rm -it \
104
104
  --user=root \
105
105
  -v ${PWD}/test/fixtures/asyncapi_v1.yml:/app/asyncapi.yml \
106
106
  -v ${PWD}/output:/app/output \
107
- asyncapi/cli generate fromTemplate -o /app/output /app/asyncapi.yml @asyncapi/html-template@3.0.0 --use-new-generator --force-write
107
+ asyncapi/cli generate fromTemplate -o /app/output /app/asyncapi.yml @asyncapi/html-template@3.5.4 --force-write
108
108
  ```
109
109
  Note: Use ``` ` ``` instead of `\` for Windows.
110
110
 
@@ -115,7 +115,7 @@ Note: Use ``` ` ``` instead of `\` for Windows.
115
115
  Use the following npx command on your terminal:
116
116
 
117
117
  ```bash
118
- npx -p @asyncapi/cli asyncapi generate fromTemplate ./asyncapi.yaml @asyncapi/html-template@3.0.0 --use-new-generator
118
+ npx -p @asyncapi/cli asyncapi generate fromTemplate ./asyncapi.yaml @asyncapi/html-template@3.5.4
119
119
  ```
120
120
 
121
121
  ## Using as a module/package
@@ -18,10 +18,9 @@ It is better to lock a specific version of the template and the generator if you
18
18
  Generate HTML with the latest AsyncAPI CLI using the html-template.
19
19
  ```
20
20
  npm install -g @asyncapi/cli
21
- asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template@3.0.0 --use-new-generator
21
+ asyncapi generate fromTemplate asyncapi.yaml @asyncapi/html-template@3.5.4
22
22
  ```
23
23
 
24
- > AsyncAPI CLI has multiple versions of the generator, and to use the latest version, you may need to pass the `--use-new-generator` flag. For more details you can also check [asyncapi generate fromTemplate ASYNCAPI TEMPLATE](https://www.asyncapi.com/docs/tools/cli/usage#asyncapi-generate-fromtemplate-asyncapi-template)
25
24
 
26
25
  Generate HTML using a particular version of the AsyncAPI CLI using the html-template.
27
26
 
@@ -42,7 +42,8 @@ async function isGenerationConditionMet (
42
42
  return conditionalSubjectGeneration(
43
43
  asyncapiDocument,
44
44
  templateConfig,
45
- matchedConditionPath
45
+ matchedConditionPath,
46
+ templateParams
46
47
  );
47
48
  }
48
49
  return conditionalParameterGeneration(templateConfig,matchedConditionPath,templateParams);
@@ -111,9 +112,7 @@ async function conditionalSubjectGeneration (
111
112
  const server = templateParams.server && asyncapiDocument.servers().get(templateParams.server);
112
113
  const source = jmespath.search({
113
114
  ...asyncapiDocument.json(),
114
- ...{
115
- server: server ? server.json() : undefined,
116
- },
115
+ server: server ? server.json() : undefined,
117
116
  }, subject);
118
117
 
119
118
  if (!source) {
@@ -140,7 +139,6 @@ async function validateStatus(
140
139
  if (!validation) {
141
140
  return false;
142
141
  }
143
-
144
142
  const isValid = validation(argument);
145
143
 
146
144
  if (!isValid) {
@@ -151,7 +149,6 @@ async function validateStatus(
151
149
  // TODO: https://github.com/asyncapi/generator/issues/1553
152
150
  log.debug(logMessage.conditionalFilesMatched(matchedConditionPath));
153
151
  }
154
-
155
152
  return false;
156
153
  }
157
154
  return true;
@@ -26,7 +26,7 @@
26
26
  1. Navigate to `packages/templates/clients/kafka/java/quarkus`
27
27
  2. Install with `npm install`
28
28
  3. Navigate back to `./generator`
29
- 4. Generate the template client with `node .\apps\generator\cli.js <path-to-custom-document> .\packages\templates\clients\kafka\java\quarkus\ -o outputClient --force-write --param server=<custom-server>`
29
+ 4. Generate the template client with `node .\apps\generator\test\cli.js <path-to-custom-document> .\packages\templates\clients\kafka\java\quarkus\ -o outputClient --force-write --param server=<custom-server>`
30
30
  5. Navigate to `outputClient` or any other name you gave the output folder
31
31
  6. Navigate to the docker folder with `cd src/main/docker` and find the `docker-compose.yaml` file.
32
32
  7. Start the kafka broker by runnning `docker-compose up -d`. Make sure you have docker desktop up and running.
@@ -32,8 +32,7 @@
32
32
  "eslint": "^6.8.0",
33
33
  "eslint-plugin-jest": "^23.8.2",
34
34
  "eslint-plugin-react": "^7.34.1",
35
- "eslint-plugin-sonarjs": "^0.5.0",
36
- "jest-esm-transformer": "^1.0.0"
35
+ "eslint-plugin-sonarjs": "^0.5.0"
37
36
  },
38
37
  "babel": {
39
38
  "presets": [
@@ -21,7 +21,6 @@
21
21
  "@babel/core": "^7.26.0",
22
22
  "@babel/preset-env": "^7.26.0",
23
23
  "@babel/preset-react": "^7.25.9",
24
- "jest-esm-transformer": "^1.0.0",
25
24
  "eslint": "^6.8.0",
26
25
  "eslint-plugin-jest": "^23.8.2",
27
26
  "eslint-plugin-react": "^7.34.1",
@@ -2,7 +2,7 @@ apiVersion: v3
2
2
  parameters:
3
3
  server:
4
4
  description: The name of the server described in AsyncAPI document
5
- required: false
5
+ required: true
6
6
  appendClientSuffix:
7
7
  description: Add 'Client' suffix at the end of the class name. This option has no effect if 'customClientName' is specified.
8
8
  required: false
@@ -75,7 +75,7 @@ You can use our AsyncAPI's credentials to access different set of events produce
75
75
  2. Navigate to `packages/templates/clients/websocket/java/quarkus`
76
76
  3. Install with `npm install`
77
77
  4. Navigate back to `./generator`
78
- 5. Generate the template client with `node .\apps\generator\cli.js <path-to-custom-document> .\packages\templates\clients\websocket\java\quarkus\ -o outputClient --force-write --param server=<custom-server>`
78
+ 5. Generate the template client with `node .\apps\generator\test\cli.js <path-to-custom-document> .\packages\templates\clients\websocket\java\quarkus\ -o outputClient --force-write --param server=<custom-server>`
79
79
  6. Navigate to `outputClient` or any other name you gave the output folder
80
80
  7. Run `mvn quarkus:dev`
81
81
  8. See the output in the terminal
@@ -12,7 +12,7 @@
12
12
  "author": "Shuaib Salad <sh.salat@gmail.com>",
13
13
  "license": "Apache-2.0",
14
14
  "scripts": {
15
- "test": "jest --coverage --passWithNoTests",
15
+ "test": "jest --coverage",
16
16
  "test:update": "npm run test -- -u",
17
17
  "lint": "eslint --max-warnings 0 --config ../../../../../../.eslintrc --ignore-path ../../../../../../.eslintignore .",
18
18
  "lint:fix": "eslint --fix --max-warnings 0 --config ../../../../../../.eslintrc --ignore-path ../../../../../../.eslintignore ."
@@ -33,8 +33,7 @@
33
33
  "eslint": "^6.8.0",
34
34
  "eslint-plugin-jest": "^23.8.2",
35
35
  "eslint-plugin-react": "^7.34.1",
36
- "eslint-plugin-sonarjs": "^0.5.0",
37
- "jest-esm-transformer": "^1.0.0"
36
+ "eslint-plugin-sonarjs": "^0.5.0"
38
37
  },
39
38
  "babel": {
40
39
  "presets": [
@@ -7,4 +7,4 @@ You can test this template:
7
7
  4. Install with `npm install` and run test with `npm run test`
8
8
  5. Start example script that uses a client library generated by the test: `node example.js`
9
9
 
10
- > By default this is testing against Hoppscotch echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change first line to `const WSClient = require('./tests/temp/snapshotTestResult/client_postman/client.js');` and run `node example.js` again. You will see example still works but now it is using a different API. This is possible since both AsyncAPI documents define the same name of operation for sending messages: `sendEchoMessage` so each client generated has the same API.
10
+ > By default this is testing against Hoppscotch echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change first line to `const WSClient = require('./test/temp/snapshotTestResult/client_postman/client.js');` and run `node example.js` again. You will see example still works but now it is using a different API. This is possible since both AsyncAPI documents define the same name of operation for sending messages: `sendEchoMessage` so each client generated has the same API.
@@ -38,6 +38,13 @@ async compileOperationSchemas() {
38
38
  console.log('Schemas initialized successfully for operations:', this.sendOperationsId.join(', '));
39
39
  } catch (error) {
40
40
  console.error('Error initializing schemas:', error);
41
+ this.schemasCompiled = false;
42
+ if (error instanceof Error) {
43
+ error.message = \`Schema compilation failed: \${error.message}\`;
44
+ throw error;
45
+ } else {
46
+ throw new Error(\`Schema compilation failed: \${String(error)}\`);
47
+ }
41
48
  }
42
49
  }`
43
50
  })
@@ -1 +1 @@
1
- {"version":3,"file":"CompileOperationSchemas.js","sources":["../../../../../../../../packages/templates/clients/websocket/javascript/components/CompileOperationSchemas.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function CompileOperationSchemas({ sendOperations }) {\n if (!sendOperations || sendOperations.length === 0) {\n return null;\n } \n\n return (\n <>\n <Text indent={2} newLines={2}>\n {\n `/**\n * Initialize and compile all schemas for operations defined.\n * This should be called once after creating the client instance.\n * Subsequent calls will be ignored if schemas are already compiled.\n * \n * @returns {Promise<void>}\n * @throws {Error} If schema compilation fails for any operation\n */\nasync compileOperationSchemas() {\n if (this.schemasCompiled) {\n return;\n }\n\n try {\n // Compile schemas for all send operations\n for (const operationId of this.sendOperationsId) {\n this.compiledSchemas[operationId] = await compileSchemasByOperationId(asyncapiFilepath, operationId);\n }\n this.schemasCompiled = true;\n console.log('Schemas initialized successfully for operations:', this.sendOperationsId.join(', '));\n } catch (error) {\n console.error('Error initializing schemas:', error);\n }\n}`\n }\n </Text>\n </>\n );\n}\n"],"names":["CompileOperationSchemas","sendOperations","length","_jsx","_Fragment","children","Text","indent","newLines"],"mappings":";;;;;;;;AAEO,SAASA,uBAAuBA,CAAC;AAAEC,EAAAA,cAAAA;AAAe,CAAC,EAAE;EAC1D,IAAI,CAACA,cAAc,IAAIA,cAAc,CAACC,MAAM,KAAK,CAAC,EAAE;AAClD,IAAA,OAAO,IAAI,CAAA;AACb,GAAA;EAEA,oBACEC,cAAA,CAAAC,mBAAA,EAAA;IAAAC,QAAA,eACEF,cAAA,CAACG,sBAAI,EAAA;AAACC,MAAAA,MAAM,EAAE,CAAE;AAACC,MAAAA,QAAQ,EAAE,CAAE;AAAAH,MAAAA,QAAA,EAEzB,CAAA;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAA,CAAA;KAEY,CAAA;AAAC,GACP,CAAC,CAAA;AAEP;;;;"}
1
+ {"version":3,"file":"CompileOperationSchemas.js","sources":["../../../../../../../../packages/templates/clients/websocket/javascript/components/CompileOperationSchemas.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function CompileOperationSchemas({ sendOperations }) {\n if (!sendOperations || sendOperations.length === 0) {\n return null;\n } \n\n return (\n <>\n <Text indent={2} newLines={2}>\n {\n `/**\n * Initialize and compile all schemas for operations defined.\n * This should be called once after creating the client instance.\n * Subsequent calls will be ignored if schemas are already compiled.\n * \n * @returns {Promise<void>}\n * @throws {Error} If schema compilation fails for any operation\n */\nasync compileOperationSchemas() {\n if (this.schemasCompiled) {\n return;\n }\n\n try {\n // Compile schemas for all send operations\n for (const operationId of this.sendOperationsId) {\n this.compiledSchemas[operationId] = await compileSchemasByOperationId(asyncapiFilepath, operationId);\n }\n this.schemasCompiled = true;\n console.log('Schemas initialized successfully for operations:', this.sendOperationsId.join(', '));\n } catch (error) {\n console.error('Error initializing schemas:', error);\n this.schemasCompiled = false;\n if (error instanceof Error) {\n error.message = \\`Schema compilation failed: \\${error.message}\\`;\n throw error;\n } else {\n throw new Error(\\`Schema compilation failed: \\${String(error)}\\`);\n }\n }\n}`\n }\n </Text>\n </>\n );\n}\n"],"names":["CompileOperationSchemas","sendOperations","length","_jsx","_Fragment","children","Text","indent","newLines"],"mappings":";;;;;;;;AAEO,SAASA,uBAAuBA,CAAC;AAAEC,EAAAA,cAAAA;AAAe,CAAC,EAAE;EAC1D,IAAI,CAACA,cAAc,IAAIA,cAAc,CAACC,MAAM,KAAK,CAAC,EAAE;AAClD,IAAA,OAAO,IAAI,CAAA;AACb,GAAA;EAEA,oBACEC,cAAA,CAAAC,mBAAA,EAAA;IAAAC,QAAA,eACEF,cAAA,CAACG,sBAAI,EAAA;AAACC,MAAAA,MAAM,EAAE,CAAE;AAACC,MAAAA,QAAQ,EAAE,CAAE;AAAAH,MAAAA,QAAA,EAEzB,CAAA;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAA,CAAA;KAEY,CAAA;AAAC,GACP,CAAC,CAAA;AAEP;;;;"}
@@ -71,6 +71,13 @@ async compileOperationSchemas() {
71
71
  console.log('Schemas initialized successfully for operations:', this.sendOperationsId.join(', '));
72
72
  } catch (error) {
73
73
  console.error('Error initializing schemas:', error);
74
+ this.schemasCompiled = false;
75
+ if (error instanceof Error) {
76
+ error.message = \`Schema compilation failed: \${error.message}\`;
77
+ throw error;
78
+ } else {
79
+ throw new Error(\`Schema compilation failed: \${String(error)}\`);
80
+ }
74
81
  }
75
82
  }`
76
83
  })
@@ -1 +1 @@
1
- {"version":3,"file":"client.js.js","sources":["../../../../../../../../packages/templates/clients/websocket/javascript/components/Constructor.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/ModuleExport.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/CompileOperationSchemas.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/ClientClass.js","../../../../../../../../packages/templates/clients/websocket/javascript/template/client.js.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function Constructor({ serverUrl, sendOperations }) {\n const sendOperationsId = sendOperations.map((operation) => operation.id());\n const sendOperationsArray = JSON.stringify(sendOperationsId);\n\n return (\n <Text indent={2}>\n {\n `/*\n * Constructor to initialize the WebSocket client\n * @param {string} url - The WebSocket server URL. Use it if the server URL is different from the default one taken from the AsyncAPI document.\n*/\nconstructor(url) {\n this.url = url || '${serverUrl}';\n this.websocket = null;\n this.messageHandlers = [];\n this.errorHandlers = [];\n this.compiledSchemas = {};\n this.schemasCompiled = false;\n this.sendOperationsId = ${sendOperationsArray};\n}\n`\n }\n </Text>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function ModuleExport({ clientName }) {\n return (\n <Text>\n {\n `module.exports = ${clientName};`\n }\n </Text>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function CompileOperationSchemas({ sendOperations }) {\n if (!sendOperations || sendOperations.length === 0) {\n return null;\n } \n\n return (\n <>\n <Text indent={2} newLines={2}>\n {\n `/**\n * Initialize and compile all schemas for operations defined.\n * This should be called once after creating the client instance.\n * Subsequent calls will be ignored if schemas are already compiled.\n * \n * @returns {Promise<void>}\n * @throws {Error} If schema compilation fails for any operation\n */\nasync compileOperationSchemas() {\n if (this.schemasCompiled) {\n return;\n }\n\n try {\n // Compile schemas for all send operations\n for (const operationId of this.sendOperationsId) {\n this.compiledSchemas[operationId] = await compileSchemasByOperationId(asyncapiFilepath, operationId);\n }\n this.schemasCompiled = true;\n console.log('Schemas initialized successfully for operations:', this.sendOperationsId.join(', '));\n } catch (error) {\n console.error('Error initializing schemas:', error);\n }\n}`\n }\n </Text>\n </>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\nimport { Constructor } from './Constructor';\nimport { CloseConnection, RegisterMessageHandler, RegisterErrorHandler, SendOperations, Connect, HandleMessage } from '@asyncapi/generator-components';\nimport { ModuleExport } from './ModuleExport';\nimport { CompileOperationSchemas } from './CompileOperationSchemas';\n\nexport function ClientClass({ clientName, serverUrl, title, sendOperations }) {\n return (\n <Text>\n <Text newLines={2}>\n {`class ${clientName} {`}\n </Text>\n <Constructor serverUrl={serverUrl} sendOperations={sendOperations} />\n <Connect language=\"javascript\" title={title} />\n <RegisterMessageHandler \n language=\"javascript\" \n methodParams={['handler']}\n />\n <RegisterErrorHandler\n language=\"javascript\" \n methodParams={['handler']}\n />\n <HandleMessage \n language=\"javascript\" \n methodParams={['message', 'cb']}\n />\n <CompileOperationSchemas sendOperations={sendOperations} />\n <SendOperations \n language=\"javascript\" \n sendOperations={sendOperations} \n clientName={clientName} \n />\n <CloseConnection language=\"javascript\" />\n <Text>\n {'}'}\n </Text>\n <ModuleExport clientName={clientName} />\n </Text>\n );\n}\n","import { File } from '@asyncapi/generator-react-sdk';\nimport { getClientName, getServerUrl, getServer, getInfo, getTitle } from '@asyncapi/generator-helpers';\nimport { FileHeaderInfo, DependencyProvider } from '@asyncapi/generator-components';\nimport { ClientClass } from '../components/ClientClass';\n\nexport default function ({ asyncapi, params }) {\n const server = getServer(asyncapi.servers(), params.server);\n const info = getInfo(asyncapi);\n const title = getTitle(asyncapi);\n const clientName = getClientName(asyncapi, params.appendClientSuffix, params.customClientName);\n const serverUrl = getServerUrl(server);\n const sendOperations = asyncapi.operations().filterBySend();\n const asyncapiFilepath = `${params.asyncapiFileDir}/asyncapi.yaml`;\n return (\n <File name={params.clientFileName}>\n <FileHeaderInfo\n info={info}\n server={server}\n language=\"javascript\"\n />\n <DependencyProvider\n language=\"javascript\"\n additionalDependencies={['const path = require(\\'path\\');', `const asyncapiFilepath = path.resolve(__dirname, '${asyncapiFilepath}');`]}\n />\n <ClientClass clientName={clientName} serverUrl={serverUrl} title={title} sendOperations={sendOperations} />\n </File>\n );\n}\n"],"names":["Constructor","serverUrl","sendOperations","sendOperationsId","map","operation","id","sendOperationsArray","JSON","stringify","_jsx","Text","indent","children","ModuleExport","clientName","CompileOperationSchemas","length","_Fragment","newLines","ClientClass","title","_jsxs","Connect","language","RegisterMessageHandler","methodParams","RegisterErrorHandler","HandleMessage","SendOperations","CloseConnection","asyncapi","params","server","getServer","servers","info","getInfo","getTitle","getClientName","appendClientSuffix","customClientName","getServerUrl","operations","filterBySend","asyncapiFilepath","asyncapiFileDir","File","name","clientFileName","FileHeaderInfo","DependencyProvider","additionalDependencies"],"mappings":";;;;;;;;AAEO,SAASA,WAAWA,CAAC;EAAEC,SAAS;AAAEC,EAAAA,cAAAA;AAAe,CAAC,EAAE;AACzD,EAAA,MAAMC,gBAAgB,GAAGD,cAAc,CAACE,GAAG,CAAEC,SAAS,IAAKA,SAAS,CAACC,EAAE,EAAE,CAAC,CAAA;AAC1E,EAAA,MAAMC,mBAAmB,GAAGC,IAAI,CAACC,SAAS,CAACN,gBAAgB,CAAC,CAAA;EAE5D,oBACEO,cAAA,CAACC,sBAAI,EAAA;AAACC,IAAAA,MAAM,EAAE,CAAE;AAAAC,IAAAA,QAAA,EAEZ,CAAA;AACR;AACA;AACA;AACA;AACA,qBAAA,EAAuBZ,SAAS,CAAA;AAChC;AACA;AACA;AACA;AACA;AACA,0BAAA,EAA4BM,mBAAmB,CAAA;AAC/C;AACA,CAAA;AAAC,GAES,CAAC,CAAA;AAEX;;ACxBO,SAASO,YAAYA,CAAC;AAAEC,EAAAA,UAAAA;AAAW,CAAC,EAAE;EAC3C,oBACEL,cAAA,CAACC,sBAAI,EAAA;IAAAE,QAAA,EAED,oBAAoBE,UAAU,CAAA,CAAA,CAAA;AAAG,GAE/B,CAAC,CAAA;AAEX;;ACRO,SAASC,uBAAuBA,CAAC;AAAEd,EAAAA,cAAAA;AAAe,CAAC,EAAE;EAC1D,IAAI,CAACA,cAAc,IAAIA,cAAc,CAACe,MAAM,KAAK,CAAC,EAAE;AAClD,IAAA,OAAO,IAAI,CAAA;AACb,GAAA;EAEA,oBACEP,cAAA,CAAAQ,mBAAA,EAAA;IAAAL,QAAA,eACEH,cAAA,CAACC,sBAAI,EAAA;AA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AAe;IAAApC,QAAA,EAAA,cAChCH,cAAA,CAACwC,kCAAc,EAAA;AACbd,MAAAA,IAAI,EAAEA,IAAK;AACXH,MAAAA,MAAM,EAAEA,MAAO;AACfT,MAAAA,QAAQ,EAAC,YAAA;AAAY,KACtB,CAAC,eACFd,cAAA,CAACyC,sCAAkB,EAAA;AACjB3B,MAAAA,QAAQ,EAAC,YAAY;AACrB4B,MAAAA,sBAAsB,EAAE,CAAC,iCAAiC,EAAE,CAAA,kDAAA,EAAqDP,gBAAgB,CAAK,GAAA,CAAA,CAAA;AAAE,KACzI,CAAC,eACFnC,cAAA,CAACU,WAAW,EAAA;AAACL,MAAAA,UAAU,EAAEA,UAAW;AAACd,MAAAA,SAAS,EAAEA,SAAU;AAACoB,MAAAA,KAAK,EAAEA,KAAM;AAACnB,MAAAA,cAAc,EAAEA,cAAAA;AAAe,KAAE,CAAC,CAAA;AAAA,GACvG,CAAC,CAAA;AAEX;;;;"}
1
+ {"version":3,"file":"client.js.js","sources":["../../../../../../../../packages/templates/clients/websocket/javascript/components/Constructor.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/ModuleExport.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/CompileOperationSchemas.js","../../../../../../../../packages/templates/clients/websocket/javascript/components/ClientClass.js","../../../../../../../../packages/templates/clients/websocket/javascript/template/client.js.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function Constructor({ serverUrl, sendOperations }) {\n const sendOperationsId = sendOperations.map((operation) => operation.id());\n const sendOperationsArray = JSON.stringify(sendOperationsId);\n\n return (\n <Text indent={2}>\n {\n `/*\n * Constructor to initialize the WebSocket client\n * @param {string} url - The WebSocket server URL. Use it if the server URL is different from the default one taken from the AsyncAPI document.\n*/\nconstructor(url) {\n this.url = url || '${serverUrl}';\n this.websocket = null;\n this.messageHandlers = [];\n this.errorHandlers = [];\n this.compiledSchemas = {};\n this.schemasCompiled = false;\n this.sendOperationsId = ${sendOperationsArray};\n}\n`\n }\n </Text>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function ModuleExport({ clientName }) {\n return (\n <Text>\n {\n `module.exports = ${clientName};`\n }\n </Text>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function CompileOperationSchemas({ sendOperations }) {\n if (!sendOperations || sendOperations.length === 0) {\n return null;\n } \n\n return (\n <>\n <Text indent={2} newLines={2}>\n {\n `/**\n * Initialize and compile all schemas for operations defined.\n * This should be called once after creating the client instance.\n * Subsequent calls will be ignored if schemas are already compiled.\n * \n * @returns {Promise<void>}\n * @throws {Error} If schema compilation fails for any operation\n */\nasync compileOperationSchemas() {\n if (this.schemasCompiled) {\n return;\n }\n\n try {\n // Compile schemas for all send operations\n for (const operationId of this.sendOperationsId) {\n this.compiledSchemas[operationId] = await compileSchemasByOperationId(asyncapiFilepath, operationId);\n }\n this.schemasCompiled = true;\n console.log('Schemas initialized successfully for operations:', this.sendOperationsId.join(', '));\n } catch (error) {\n console.error('Error initializing schemas:', error);\n this.schemasCompiled = false;\n if (error instanceof Error) {\n error.message = \\`Schema compilation failed: \\${error.message}\\`;\n throw error;\n } else {\n throw new Error(\\`Schema compilation failed: \\${String(error)}\\`);\n }\n }\n}`\n }\n </Text>\n </>\n );\n}\n","import { Text } from '@asyncapi/generator-react-sdk';\nimport { Constructor } from './Constructor';\nimport { CloseConnection, RegisterMessageHandler, RegisterErrorHandler, SendOperations, Connect, HandleMessage } from '@asyncapi/generator-components';\nimport { ModuleExport } from './ModuleExport';\nimport { CompileOperationSchemas } from './CompileOperationSchemas';\n\nexport function ClientClass({ clientName, serverUrl, title, sendOperations }) {\n return (\n <Text>\n <Text newLines={2}>\n {`class ${clientName} {`}\n </Text>\n <Constructor serverUrl={serverUrl} sendOperations={sendOperations} />\n <Connect language=\"javascript\" title={title} />\n <RegisterMessageHandler \n language=\"javascript\" \n methodParams={['handler']}\n />\n <RegisterErrorHandler\n language=\"javascript\" \n methodParams={['handler']}\n />\n <HandleMessage \n language=\"javascript\" \n methodParams={['message', 'cb']}\n />\n <CompileOperationSchemas sendOperations={sendOperations} />\n <SendOperations \n language=\"javascript\" \n sendOperations={sendOperations} \n clientName={clientName} \n />\n <CloseConnection language=\"javascript\" />\n <Text>\n {'}'}\n </Text>\n <ModuleExport clientName={clientName} />\n </Text>\n );\n}\n","import { File } from '@asyncapi/generator-react-sdk';\nimport { getClientName, getServerUrl, getServer, getInfo, getTitle } from '@asyncapi/generator-helpers';\nimport { FileHeaderInfo, DependencyProvider } from '@asyncapi/generator-components';\nimport { ClientClass } from '../components/ClientClass';\n\nexport default function ({ asyncapi, params }) {\n const server = getServer(asyncapi.servers(), params.server);\n const info = getInfo(asyncapi);\n const title = getTitle(asyncapi);\n const clientName = getClientName(asyncapi, params.appendClientSuffix, params.customClientName);\n const serverUrl = getServerUrl(server);\n const sendOperations = asyncapi.operations().filterBySend();\n const asyncapiFilepath = `${params.asyncapiFileDir}/asyncapi.yaml`;\n return (\n <File name={params.clientFileName}>\n <FileHeaderInfo\n info={info}\n server={server}\n language=\"javascript\"\n />\n <DependencyProvider\n language=\"javascript\"\n additionalDependencies={['const path = require(\\'path\\');', `const asyncapiFilepath = path.resolve(__dirname, '${asyncapiFilepath}');`]}\n />\n <ClientClass clientName={clientName} serverUrl={serverUrl} title={title} sendOperations={sendOperations} />\n </File>\n );\n}\n"],"names":["Constructor","serverUrl","sendOperations","sendOperationsId","map","operation","id","sendOperationsArray","JSON","stringify","_jsx","Text","indent","children","ModuleExport","clientName","CompileOperationSchemas","length","_Fragment","newLines","ClientClass","title","_jsxs","Connect","language","RegisterMessageHandler","methodParams","RegisterErrorHandler","HandleMessage","SendOperations","CloseConnection","asyncapi","params","server","getServer","servers","info","getInfo","getTitle","getClientName","appendClientSuffix","customClientName","getServerUrl","operations","filterBySend","asyncapiFilepath","asyncapiFileDir","File","name","clientFileName","FileHeaderInfo","DependencyProvider","additionalDependencies"],"mappings":";;;;;;;;AAEO,SAASA,WAAWA,CAAC;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,YAAY;AACrB4B,MAAAA,sBAAsB,EAAE,CAAC,iCAAiC,EAAE,CAAA,kDAAA,EAAqDP,gBAAgB,CAAK,GAAA,CAAA,CAAA;AAAE,KACzI,CAAC,eACFnC,cAAA,CAACU,WAAW,EAAA;AAACL,MAAAA,UAAU,EAAEA,UAAW;AAACd,MAAAA,SAAS,EAAEA,SAAU;AAACoB,MAAAA,KAAK,EAAEA,KAAM;AAACnB,MAAAA,cAAc,EAAEA,cAAAA;AAAe,KAAE,CAAC,CAAA;AAAA,GACvG,CAAC,CAAA;AAEX;;;;"}
@@ -31,6 +31,13 @@ async compileOperationSchemas() {
31
31
  console.log('Schemas initialized successfully for operations:', this.sendOperationsId.join(', '));
32
32
  } catch (error) {
33
33
  console.error('Error initializing schemas:', error);
34
+ this.schemasCompiled = false;
35
+ if (error instanceof Error) {
36
+ error.message = \`Schema compilation failed: \${error.message}\`;
37
+ throw error;
38
+ } else {
39
+ throw new Error(\`Schema compilation failed: \${String(error)}\`);
40
+ }
34
41
  }
35
42
  }`
36
43
  }
@@ -11,10 +11,11 @@
11
11
  "author": "Lukasz Gornicki <lpgornicki@gmail.com>",
12
12
  "license": "Apache-2.0",
13
13
  "dependencies": {
14
+ "@asyncapi/generator-components": "0.5.0",
14
15
  "@asyncapi/generator-helpers": "1.1.0",
15
16
  "@asyncapi/generator-react-sdk": "*",
16
- "@asyncapi/generator-components": "0.5.0",
17
- "@asyncapi/keeper": "0.5.0"
17
+ "@asyncapi/keeper": "0.5.0",
18
+ "ws": "^8.19.0"
18
19
  },
19
20
  "devDependencies": {
20
21
  "@asyncapi/parser": "^3.4.0",
@@ -25,8 +26,7 @@
25
26
  "eslint": "^6.8.0",
26
27
  "eslint-plugin-jest": "^23.8.2",
27
28
  "eslint-plugin-react": "^7.34.1",
28
- "eslint-plugin-sonarjs": "^0.5.0",
29
- "jest-esm-transformer": "^1.0.0"
29
+ "eslint-plugin-sonarjs": "^0.5.0"
30
30
  },
31
31
  "babel": {
32
32
  "presets": [
@@ -10,11 +10,7 @@ var jsxRuntime = require('/home/runner/work/generator/generator/node_modules/rea
10
10
  function ReceiveOperationsDiscriminators({
11
11
  receiveOperations
12
12
  }) {
13
- const hasOperations = Array.isArray(receiveOperations) && receiveOperations.length > 0;
14
- if (!hasOperations) {
15
- return null;
16
- }
17
- const operationDiscriminators = generatorHelpers.getMessageDiscriminatorsFromOperations(receiveOperations);
13
+ const operationDiscriminators = Array.isArray(receiveOperations) && receiveOperations.length > 0 ? generatorHelpers.getMessageDiscriminatorsFromOperations(receiveOperations) : [];
18
14
  const serializedDiscriminators = JSON.stringify(operationDiscriminators);
19
15
  return /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
20
16
  indent: 2,