@asyncapi/generator 3.1.2 → 3.2.1
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.
- package/CHANGELOG.md +21 -1
- package/docs/api_components.md +1258 -0
- package/docs/generator-template.md +75 -65
- package/docs/model-generation.md +1 -1
- package/docs/usage.md +9 -9
- package/docs/versioning.md +1 -2
- package/lib/conditionalGeneration.js +3 -6
- package/lib/generator.js +16 -1
- package/lib/templates/bakedInTemplates/core-template-client-kafka-java-quarkus/package.json +1 -2
- package/lib/templates/bakedInTemplates/core-template-client-websocket-dart/package.json +3 -2
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/.ageneratorrc +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/package.json +5 -4
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/README.md +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/package.json +6 -4
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/ReceiveOperationsDiscriminators.js +1 -5
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/ReceiveOperationsDiscriminators.js.map +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/Send.js +2 -2
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/components/Send.js.map +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/template/client.py.js +3 -7
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/__transpiled/template/client.py.js.map +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/ReceiveOperationsDiscriminators.js +3 -6
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/components/Send.js +2 -2
- package/lib/templates/bakedInTemplates/core-template-client-websocket-python/package.json +3 -2
- package/lib/templates/bakedInTemplates.js +9 -3
- package/package.json +3 -3
|
@@ -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
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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": "
|
|
116
|
-
"generator": ">=
|
|
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": "
|
|
330
|
-
"generator": ">=
|
|
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
|
-
|
|
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).
|
|
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).
|
|
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).
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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({
|
|
502
|
-
const topicsDetails = getTopics(
|
|
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(
|
|
522
|
-
const channelsCanSendTo = channels;
|
|
525
|
+
function getTopics(operations) {
|
|
523
526
|
let topicsDetails = [];
|
|
524
527
|
|
|
525
|
-
|
|
526
|
-
const
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
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
|
-
`{
|
|
539
|
-
`getTopics(
|
|
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).
|
|
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
|
|
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 `
|
|
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
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
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
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
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
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
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/
|
|
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.
|
package/docs/model-generation.md
CHANGED
|
@@ -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](
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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: `
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
package/docs/versioning.md
CHANGED
|
@@ -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.
|
|
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;
|
package/lib/generator.js
CHANGED
|
@@ -401,7 +401,22 @@ class Generator {
|
|
|
401
401
|
*/
|
|
402
402
|
async configureTemplate() {
|
|
403
403
|
if (this.compile) {
|
|
404
|
-
|
|
404
|
+
// Set BROWSERSLIST_ROOT_PATH to prevent browserslist from searching
|
|
405
|
+
// outside the template directory. This fixes issues with pnpm where
|
|
406
|
+
// browserslist would incorrectly parse pnpm shim files as config.
|
|
407
|
+
// See: https://github.com/asyncapi/cli/issues/1781
|
|
408
|
+
const previousRootPath = process.env.BROWSERSLIST_ROOT_PATH;
|
|
409
|
+
process.env.BROWSERSLIST_ROOT_PATH = this.templateDir;
|
|
410
|
+
try {
|
|
411
|
+
await configureReact(this.templateDir, this.templateContentDir, TRANSPILED_TEMPLATE_LOCATION);
|
|
412
|
+
} finally {
|
|
413
|
+
// Restore previous value if it existed
|
|
414
|
+
if (previousRootPath === undefined) {
|
|
415
|
+
delete process.env.BROWSERSLIST_ROOT_PATH;
|
|
416
|
+
} else {
|
|
417
|
+
process.env.BROWSERSLIST_ROOT_PATH = previousRootPath;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
405
420
|
}
|
|
406
421
|
}
|
|
407
422
|
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest --coverage --passWithNoTests",
|
|
7
7
|
"test:update": "npm run test -- -u",
|
|
8
|
+
"test:integration": "npm --prefix ../test/integration-test run test:dart",
|
|
9
|
+
"test:integration:update": "npm --prefix ../test/integration-test run test:dart:update",
|
|
8
10
|
"lint": "eslint --max-warnings 0 --config ../../../../../.eslintrc --ignore-path ../../../../../.eslintignore .",
|
|
9
11
|
"lint:fix": "eslint --fix --max-warnings 0 --config ../../../../../.eslintrc --ignore-path ../../../../../.eslintignore ."
|
|
10
12
|
},
|
|
@@ -13,7 +15,7 @@
|
|
|
13
15
|
"dependencies": {
|
|
14
16
|
"@asyncapi/generator-react-sdk": "*",
|
|
15
17
|
"@asyncapi/generator-helpers": "1.1.0",
|
|
16
|
-
"@asyncapi/generator-components": "0.
|
|
18
|
+
"@asyncapi/generator-components": "0.6.0"
|
|
17
19
|
},
|
|
18
20
|
"devDependencies": {
|
|
19
21
|
"@asyncapi/parser": "^3.4.0",
|
|
@@ -21,7 +23,6 @@
|
|
|
21
23
|
"@babel/core": "^7.26.0",
|
|
22
24
|
"@babel/preset-env": "^7.26.0",
|
|
23
25
|
"@babel/preset-react": "^7.25.9",
|
|
24
|
-
"jest-esm-transformer": "^1.0.0",
|
|
25
26
|
"eslint": "^6.8.0",
|
|
26
27
|
"eslint-plugin-jest": "^23.8.2",
|
|
27
28
|
"eslint-plugin-react": "^7.34.1",
|
package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/.ageneratorrc
CHANGED
|
@@ -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:
|
|
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
|
package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/package.json
CHANGED
|
@@ -12,14 +12,16 @@
|
|
|
12
12
|
"author": "Shuaib Salad <sh.salat@gmail.com>",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"scripts": {
|
|
15
|
-
"test": "jest --coverage
|
|
15
|
+
"test": "jest --coverage",
|
|
16
16
|
"test:update": "npm run test -- -u",
|
|
17
|
+
"test:integration": "npm --prefix ../../test/integration-test run test:java-quarkus",
|
|
18
|
+
"test:integration:update": "npm --prefix ../../test/integration-test run test:java-quarkus:update",
|
|
17
19
|
"lint": "eslint --max-warnings 0 --config ../../../../../../.eslintrc --ignore-path ../../../../../../.eslintignore .",
|
|
18
20
|
"lint:fix": "eslint --fix --max-warnings 0 --config ../../../../../../.eslintrc --ignore-path ../../../../../../.eslintignore ."
|
|
19
21
|
},
|
|
20
22
|
"dependencies": {
|
|
21
23
|
"@asyncapi/generator-helpers": "1.1.0",
|
|
22
|
-
"@asyncapi/generator-components": "0.
|
|
24
|
+
"@asyncapi/generator-components": "0.6.0",
|
|
23
25
|
"@asyncapi/generator-react-sdk": "^1.1.2"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
@@ -33,8 +35,7 @@
|
|
|
33
35
|
"eslint": "^6.8.0",
|
|
34
36
|
"eslint-plugin-jest": "^23.8.2",
|
|
35
37
|
"eslint-plugin-react": "^7.34.1",
|
|
36
|
-
"eslint-plugin-sonarjs": "^0.5.0"
|
|
37
|
-
"jest-esm-transformer": "^1.0.0"
|
|
38
|
+
"eslint-plugin-sonarjs": "^0.5.0"
|
|
38
39
|
},
|
|
39
40
|
"babel": {
|
|
40
41
|
"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('./
|
|
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.
|
package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/package.json
CHANGED
|
@@ -5,16 +5,19 @@
|
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest --coverage --passWithNoTests",
|
|
7
7
|
"test:update": "npm run test -- -u",
|
|
8
|
+
"test:integration": "npm --prefix ../test/integration-test run test:javascript",
|
|
9
|
+
"test:integration:update": "npm --prefix ../test/integration-test run test:javascript:update",
|
|
8
10
|
"lint": "eslint --max-warnings 0 --config ../../../../../.eslintrc --ignore-path ../../../../../.eslintignore .",
|
|
9
11
|
"lint:fix": "eslint --fix --max-warnings 0 --config ../../../../../.eslintrc --ignore-path ../../../../../.eslintignore ."
|
|
10
12
|
},
|
|
11
13
|
"author": "Lukasz Gornicki <lpgornicki@gmail.com>",
|
|
12
14
|
"license": "Apache-2.0",
|
|
13
15
|
"dependencies": {
|
|
16
|
+
"@asyncapi/generator-components": "0.6.0",
|
|
14
17
|
"@asyncapi/generator-helpers": "1.1.0",
|
|
15
18
|
"@asyncapi/generator-react-sdk": "*",
|
|
16
|
-
"@asyncapi/
|
|
17
|
-
"
|
|
19
|
+
"@asyncapi/keeper": "0.5.0",
|
|
20
|
+
"ws": "^8.19.0"
|
|
18
21
|
},
|
|
19
22
|
"devDependencies": {
|
|
20
23
|
"@asyncapi/parser": "^3.4.0",
|
|
@@ -25,8 +28,7 @@
|
|
|
25
28
|
"eslint": "^6.8.0",
|
|
26
29
|
"eslint-plugin-jest": "^23.8.2",
|
|
27
30
|
"eslint-plugin-react": "^7.34.1",
|
|
28
|
-
"eslint-plugin-sonarjs": "^0.5.0"
|
|
29
|
-
"jest-esm-transformer": "^1.0.0"
|
|
31
|
+
"eslint-plugin-sonarjs": "^0.5.0"
|
|
30
32
|
},
|
|
31
33
|
"babel": {
|
|
32
34
|
"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
|
|
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,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReceiveOperationsDiscriminators.js","sources":["../../../../../../../../packages/templates/clients/websocket/python/components/ReceiveOperationsDiscriminators.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\nimport { getMessageDiscriminatorsFromOperations } from '@asyncapi/generator-helpers';\n\n/**\n * Component that generates initialization code for receive operation discriminators.\n * \n * @param {Object} props - Component properties\n * @param {Array<Object>} [props.receiveOperations] - Receive operations from AsyncAPI document\n * @returns {React.Element|null} Rendered initialization code or null.\n */\nexport function ReceiveOperationsDiscriminators({ receiveOperations }) {\n const
|
|
1
|
+
{"version":3,"file":"ReceiveOperationsDiscriminators.js","sources":["../../../../../../../../packages/templates/clients/websocket/python/components/ReceiveOperationsDiscriminators.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\nimport { getMessageDiscriminatorsFromOperations } from '@asyncapi/generator-helpers';\n\n/**\n * Component that generates initialization code for receive operation discriminators.\n * \n * @param {Object} props - Component properties\n * @param {Array<Object>} [props.receiveOperations] - Receive operations from AsyncAPI document\n * @returns {React.Element|null} Rendered initialization code or null.\n */\nexport function ReceiveOperationsDiscriminators({ receiveOperations }) {\n const operationDiscriminators = Array.isArray(receiveOperations) && receiveOperations.length > 0\n ? getMessageDiscriminatorsFromOperations(receiveOperations)\n : [];\n const serializedDiscriminators = JSON.stringify(operationDiscriminators);\n\n return (\n <Text indent={2} newLines={2}>\n {`\n self.receive_operation_handlers = {}\n self.receive_operation_discriminators = ${serializedDiscriminators}`\n }\n </Text>\n );\n}\n"],"names":["ReceiveOperationsDiscriminators","receiveOperations","operationDiscriminators","Array","isArray","length","getMessageDiscriminatorsFromOperations","serializedDiscriminators","JSON","stringify","_jsx","Text","indent","newLines","children"],"mappings":";;;;;;;;;AAUO,SAASA,+BAA+BA,CAAC;AAAEC,EAAAA,iBAAAA;AAAkB,CAAC,EAAE;EACrE,MAAMC,uBAAuB,GAAGC,KAAK,CAACC,OAAO,CAACH,iBAAiB,CAAC,IAAIA,iBAAiB,CAACI,MAAM,GAAG,CAAC,GAC5FC,uDAAsC,CAACL,iBAAiB,CAAC,GACzD,EAAE,CAAA;AACN,EAAA,MAAMM,wBAAwB,GAAGC,IAAI,CAACC,SAAS,CAACP,uBAAuB,CAAC,CAAA;EAExE,oBACEQ,cAAA,CAACC,sBAAI,EAAA;AAACC,IAAAA,MAAM,EAAE,CAAE;AAACC,IAAAA,QAAQ,EAAE,CAAE;AAAAC,IAAAA,QAAA,EAC1B,CAAA;AACP;AACA,8CAAA,EAAgDP,wBAAwB,CAAA,CAAA;AAAE,GAEhE,CAAC,CAAA;AAEX;;;;"}
|
|
@@ -17,7 +17,7 @@ function Send({
|
|
|
17
17
|
indent: 2,
|
|
18
18
|
children: `
|
|
19
19
|
@staticmethod
|
|
20
|
-
|
|
20
|
+
def _send(message, socket):
|
|
21
21
|
"""
|
|
22
22
|
Internal helper to handle the actual sending logic.
|
|
23
23
|
|
|
@@ -31,7 +31,7 @@ async def _send(message, socket):
|
|
|
31
31
|
try:
|
|
32
32
|
if isinstance(message, dict):
|
|
33
33
|
message = json.dumps(message)
|
|
34
|
-
|
|
34
|
+
socket.send(message)
|
|
35
35
|
except Exception as e:
|
|
36
36
|
print("Error sending:", e)`
|
|
37
37
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Send.js","sources":["../../../../../../../../packages/templates/clients/websocket/python/components/Send.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function Send({ sendOperations }) {\n if (!sendOperations || sendOperations.length === 0) {\n return null;\n }\n\n return (\n <Text newLines={2} indent={2}>\n {\n `\n@staticmethod\
|
|
1
|
+
{"version":3,"file":"Send.js","sources":["../../../../../../../../packages/templates/clients/websocket/python/components/Send.js"],"sourcesContent":["import { Text } from '@asyncapi/generator-react-sdk';\n\nexport function Send({ sendOperations }) {\n if (!sendOperations || sendOperations.length === 0) {\n return null;\n }\n\n return (\n <Text newLines={2} indent={2}>\n {\n `\n@staticmethod\ndef _send(message, socket):\n \"\"\"\n Internal helper to handle the actual sending logic.\n\n Args:\n message (dict or str): The message to send.\n socket (websockets.WebSocketCommonProtocol): The WebSocket to send through.\n\n Notes:\n If message is a dictionary, it will be automatically converted to JSON.\n \"\"\"\n try:\n if isinstance(message, dict):\n message = json.dumps(message)\n socket.send(message)\n except Exception as e:\n print(\"Error sending:\", e)`\n }\n </Text>\n );\n}\n"],"names":["Send","sendOperations","length","_jsx","Text","newLines","indent","children"],"mappings":";;;;;;;;AAEO,SAASA,IAAIA,CAAC;AAAEC,EAAAA,cAAAA;AAAe,CAAC,EAAE;EACvC,IAAI,CAACA,cAAc,IAAIA,cAAc,CAACC,MAAM,KAAK,CAAC,EAAE;AAClD,IAAA,OAAO,IAAI,CAAA;AACb,GAAA;EAEA,oBACEC,cAAA,CAACC,sBAAI,EAAA;AAACC,IAAAA,QAAQ,EAAE,CAAE;AAACC,IAAAA,MAAM,EAAE,CAAE;AAAAC,IAAAA,QAAA,EAEzB,CAAA;AACR;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kCAAA,CAAA;AAAmC,GAEzB,CAAC,CAAA;AAEX;;;;"}
|
|
@@ -31,7 +31,7 @@ function Send({
|
|
|
31
31
|
indent: 2,
|
|
32
32
|
children: `
|
|
33
33
|
@staticmethod
|
|
34
|
-
|
|
34
|
+
def _send(message, socket):
|
|
35
35
|
"""
|
|
36
36
|
Internal helper to handle the actual sending logic.
|
|
37
37
|
|
|
@@ -45,7 +45,7 @@ async def _send(message, socket):
|
|
|
45
45
|
try:
|
|
46
46
|
if isinstance(message, dict):
|
|
47
47
|
message = json.dumps(message)
|
|
48
|
-
|
|
48
|
+
socket.send(message)
|
|
49
49
|
except Exception as e:
|
|
50
50
|
print("Error sending:", e)`
|
|
51
51
|
});
|
|
@@ -95,11 +95,7 @@ function InitSignature({
|
|
|
95
95
|
function ReceiveOperationsDiscriminators({
|
|
96
96
|
receiveOperations
|
|
97
97
|
}) {
|
|
98
|
-
const
|
|
99
|
-
if (!hasOperations) {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
const operationDiscriminators = generatorHelpers.getMessageDiscriminatorsFromOperations(receiveOperations);
|
|
98
|
+
const operationDiscriminators = Array.isArray(receiveOperations) && receiveOperations.length > 0 ? generatorHelpers.getMessageDiscriminatorsFromOperations(receiveOperations) : [];
|
|
103
99
|
const serializedDiscriminators = JSON.stringify(operationDiscriminators);
|
|
104
100
|
return /*#__PURE__*/jsxRuntime.jsx(generatorReactSdk.Text, {
|
|
105
101
|
indent: 2,
|