@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.
- package/CHANGELOG.md +14 -1
- package/docs/api_components.md +1233 -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/templates/bakedInTemplates/core-template-client-kafka-java-quarkus/README.md +1 -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 +0 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/.ageneratorrc +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/README.md +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-java-quarkus/package.json +2 -3
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/README.md +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/CompileOperationSchemas.js +7 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/components/CompileOperationSchemas.js.map +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/template/client.js.js +7 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/__transpiled/template/client.js.js.map +1 -1
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/components/CompileOperationSchemas.js +7 -0
- package/lib/templates/bakedInTemplates/core-template-client-websocket-javascript/package.json +4 -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 +0 -1
- package/package.json +4 -4
|
@@ -0,0 +1,1233 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Reusable Components API
|
|
3
|
+
weight: 77
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Components
|
|
7
|
+
|
|
8
|
+
* [CloseConnection](#CloseConnection) ⇒ `JSX.Element`<br/>
|
|
9
|
+
|
|
10
|
+
Renders a WebSocket close connection method with optional pre- and post-execution logic.
|
|
11
|
+
|
|
12
|
+
* [Connect](#Connect) ⇒ `JSX.Element`<br/>
|
|
13
|
+
|
|
14
|
+
Renders a WebSocket connection method for the specified programming language.
|
|
15
|
+
|
|
16
|
+
* [DependencyProvider](#DependencyProvider) ⇒ `JSX.Element`<br/>
|
|
17
|
+
|
|
18
|
+
Renders the top-of-file dependency statements for the selected programming language.
|
|
19
|
+
|
|
20
|
+
* [FileHeaderInfo](#FileHeaderInfo) ⇒ `JSX.Element`<br/>
|
|
21
|
+
|
|
22
|
+
Renders a file header with metadata information such as title, version, protocol, host, and path.
|
|
23
|
+
|
|
24
|
+
* [HandleMessage](#HandleMessage) ⇒ `JSX.Element`<br/>
|
|
25
|
+
|
|
26
|
+
Renders a WebSocket message handler method with optional pre- and post-execution logic.
|
|
27
|
+
|
|
28
|
+
* [MethodGenerator](#MethodGenerator) ⇒ `JSX.Element`<br/>
|
|
29
|
+
|
|
30
|
+
Renders a language-specific formatted method definition.
|
|
31
|
+
|
|
32
|
+
* [Models](#Models) ⇒ `Array.<File>`<br/>
|
|
33
|
+
|
|
34
|
+
Renders an array of model files based on the AsyncAPI document.
|
|
35
|
+
|
|
36
|
+
* [OnClose](#OnClose) ⇒ `JSX.Element`<br/>
|
|
37
|
+
|
|
38
|
+
Renders a WebSocket onClose event handler for the specified programming language.
|
|
39
|
+
|
|
40
|
+
* [OnError](#OnError) ⇒ `JSX.Element`<br/>
|
|
41
|
+
|
|
42
|
+
Renders a WebSocket onError event handler for the specified programming language.
|
|
43
|
+
|
|
44
|
+
* [OnMessage](#OnMessage) ⇒ `JSX.Element`<br/>
|
|
45
|
+
|
|
46
|
+
Renders a WebSocket onMessage event handler for the specified programming language.
|
|
47
|
+
|
|
48
|
+
* [OnOpen](#OnOpen) ⇒ `JSX.Element`<br/>
|
|
49
|
+
|
|
50
|
+
Renders a WebSocket onOpen event handler for the specified programming language.
|
|
51
|
+
|
|
52
|
+
* [QueryParamsVariables](#QueryParamsVariables) ⇒ `Array.<JSX.Element>`<br/>
|
|
53
|
+
|
|
54
|
+
Renders query parameter variables code blocks.
|
|
55
|
+
|
|
56
|
+
* [AvailableOperations](#AvailableOperations) ⇒ `JSX.Element`<br/>
|
|
57
|
+
|
|
58
|
+
Renders a list of AsyncAPI operations with their headers and message examples.
|
|
59
|
+
|
|
60
|
+
* [CoreMethods](#CoreMethods) ⇒ `JSX.Element`<br/>
|
|
61
|
+
|
|
62
|
+
Renders a list of core WebSocket client methods for a given target language.
|
|
63
|
+
|
|
64
|
+
* [Installation](#Installation) ⇒ `JSX.Element`<br/>
|
|
65
|
+
|
|
66
|
+
Renders the Installation Command for a given language.
|
|
67
|
+
|
|
68
|
+
* [MessageExamples](#MessageExamples) ⇒ `JSX.Element`<br/>
|
|
69
|
+
|
|
70
|
+
Renders Message Examples of a given AsyncAPI operation.
|
|
71
|
+
|
|
72
|
+
* [OperationHeader](#OperationHeader) ⇒ `JSX.Element`<br/>
|
|
73
|
+
|
|
74
|
+
Renders a header section for a single AsyncAPI operation.
|
|
75
|
+
|
|
76
|
+
* [Overview](#Overview) ⇒ `JSX.Element`<br/>
|
|
77
|
+
|
|
78
|
+
Renders an overview section for a WebSocket client. Displays the API description, version, and server URL.
|
|
79
|
+
|
|
80
|
+
* [Readme](#Readme) ⇒ `JSX.Element`<br/>
|
|
81
|
+
|
|
82
|
+
Renders a README.md file for a given AsyncAPI document. Composes multiple sections (overview, installation, usage, core methods, and available operations) into a single File component based on the provided AsyncAPI document, generator parameters, and target language.
|
|
83
|
+
|
|
84
|
+
* [Usage](#Usage) ⇒ `JSX.Element`<br/>
|
|
85
|
+
|
|
86
|
+
Renders a usage example snippet for a generated WebSocket client in a given language.
|
|
87
|
+
|
|
88
|
+
* [RegisterErrorHandler](#RegisterErrorHandler) ⇒ `JSX.Element`<br/>
|
|
89
|
+
|
|
90
|
+
Renders a WebSocket error handler registration method with optional pre- and post-execution logic.
|
|
91
|
+
|
|
92
|
+
* [RegisterMessageHandler](#RegisterMessageHandler) ⇒ `JSX.Element`<br/>
|
|
93
|
+
|
|
94
|
+
Renders a WebSocket message handler registration method with optional pre- and post-execution logic.
|
|
95
|
+
|
|
96
|
+
* [SendOperations](#SendOperations) ⇒ `Array.<JSX.Element>`<br/>
|
|
97
|
+
|
|
98
|
+
Renders WebSocket send operation methods. Generates both static and instance methods for sending messages through WebSocket connections.
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
<a name="CloseConnection"></a>
|
|
102
|
+
### CloseConnection()
|
|
103
|
+
Renders a WebSocket close connection method with optional pre- and post-execution logic.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
**Parameters**
|
|
107
|
+
|
|
108
|
+
| Name | Type | Description |
|
|
109
|
+
|------|------|-------------|
|
|
110
|
+
| props | `Object` | Component props. |
|
|
111
|
+
| props.language | `Language` | Programming language used for method formatting. |
|
|
112
|
+
| props.framework | `string` | Framework used, if any (e.g., 'quarkus' for Java). |
|
|
113
|
+
| props.methodName | `string` | Name of the method to generate. |
|
|
114
|
+
| props.methodParams | `Array.<string>` | List of parameters for the method. |
|
|
115
|
+
| props.preExecutionCode | `string` | Code to insert before the main function logic. |
|
|
116
|
+
| props.postExecutionCode | `string` | Code to insert after the main function logic. |
|
|
117
|
+
| props.indent | `number` | Indentation level for the method block. |
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
**Returns**
|
|
122
|
+
|
|
123
|
+
- `JSX.Element` - A Text component that contains method block with appropriate formatting.
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
**Example**
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
import { CloseConnection } from "@asyncapi/generator-components";
|
|
131
|
+
const language = "java";
|
|
132
|
+
const framework = "quarkus";
|
|
133
|
+
const methodName = "terminateConnection";
|
|
134
|
+
const methodParams = ["String reason"];
|
|
135
|
+
const preExecutionCode = "// About to terminate connection";
|
|
136
|
+
const postExecutionCode = "// Connection terminated";
|
|
137
|
+
const indent = 2;
|
|
138
|
+
|
|
139
|
+
function renderCloseConnection() {
|
|
140
|
+
return (
|
|
141
|
+
<CloseConnection
|
|
142
|
+
language={language}
|
|
143
|
+
framework={framework}
|
|
144
|
+
methodName={methodName}
|
|
145
|
+
methodParams={methodParams}
|
|
146
|
+
preExecutionCode={preExecutionCode}
|
|
147
|
+
postExecutionCode={postExecutionCode}
|
|
148
|
+
indent={indent}
|
|
149
|
+
/>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
renderCloseConnection();
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
<a name="Connect"></a>
|
|
159
|
+
### Connect()
|
|
160
|
+
Renders a WebSocket connection method for the specified programming language.
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
**Parameters**
|
|
164
|
+
|
|
165
|
+
| Name | Type | Description |
|
|
166
|
+
|------|------|-------------|
|
|
167
|
+
| props | `Object` | Component props. |
|
|
168
|
+
| props.language | `Language` | The programming language for which to generate connection code. |
|
|
169
|
+
| props.title | `string` | The title of the WebSocket server. |
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
**Returns**
|
|
174
|
+
|
|
175
|
+
- `JSX.Element` - A Text component containing the generated WebSocket connection code for the specified language.
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
**Example**
|
|
180
|
+
|
|
181
|
+
```js
|
|
182
|
+
import { Connect } from "@asyncapi/generator-components";
|
|
183
|
+
const language = "python";
|
|
184
|
+
const title = "HoppscotchEchoWebSocketClient";
|
|
185
|
+
|
|
186
|
+
function renderConnect() {
|
|
187
|
+
return(
|
|
188
|
+
<Connect
|
|
189
|
+
language={language}
|
|
190
|
+
title={title}
|
|
191
|
+
/>
|
|
192
|
+
)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
renderConnect();
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
<a name="DependencyProvider"></a>
|
|
201
|
+
### DependencyProvider()
|
|
202
|
+
Renders the top-of-file dependency statements for the selected programming language.
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
**Parameters**
|
|
206
|
+
|
|
207
|
+
| Name | Type | Description |
|
|
208
|
+
|------|------|-------------|
|
|
209
|
+
| props | `Object` | Component props. |
|
|
210
|
+
| props.language | `Language` | The programming language for which to render dependency statements. |
|
|
211
|
+
| props.framework | `string` | The framework (e.g., 'quarkus' for Java). |
|
|
212
|
+
| props.role | `string` | The role (e.g., 'client', 'connector' for Java). |
|
|
213
|
+
| props.additionalDependencies | `Array.<string>` | Optional additional dependencies to include. |
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
**Returns**
|
|
218
|
+
|
|
219
|
+
- `JSX.Element` - A Text component that contains list of import/require statements.
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
**Example**
|
|
224
|
+
|
|
225
|
+
```js
|
|
226
|
+
import { DependencyProvider } from "@asyncapi/generator-components";
|
|
227
|
+
const language = "java";
|
|
228
|
+
const framework = "quarkus";
|
|
229
|
+
const role = "client";
|
|
230
|
+
const additionalDependencies = ["import java.util.concurrent.CompletableFuture;", "import java.time.Duration;"];
|
|
231
|
+
|
|
232
|
+
function renderDependencyProvider() {
|
|
233
|
+
return (
|
|
234
|
+
<DependencyProvider
|
|
235
|
+
language={language}
|
|
236
|
+
framework={framework}
|
|
237
|
+
role={role}
|
|
238
|
+
additionalDependencies={additionalDependencies}
|
|
239
|
+
/>
|
|
240
|
+
)
|
|
241
|
+
}
|
|
242
|
+
renderDependencyProvider();
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
<a name="FileHeaderInfo"></a>
|
|
248
|
+
### FileHeaderInfo()
|
|
249
|
+
Renders a file header with metadata information such as title, version, protocol, host, and path.
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
**Parameters**
|
|
253
|
+
|
|
254
|
+
| Name | Type | Description |
|
|
255
|
+
|------|------|-------------|
|
|
256
|
+
| props | `Object` | Component props. |
|
|
257
|
+
| props.info | `Object` | Info object from the AsyncAPI document. |
|
|
258
|
+
| props.server | `Object` | Server object from the AsyncAPI document. |
|
|
259
|
+
| props.language | `Language` | Programming language used for comment formatting. |
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
**Returns**
|
|
264
|
+
|
|
265
|
+
- `JSX.Element` - A Text component that contains file header.
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
**Example**
|
|
270
|
+
|
|
271
|
+
```js
|
|
272
|
+
import path from "path";
|
|
273
|
+
import { Parser, fromFile } from "@asyncapi/parser";
|
|
274
|
+
import { FileHeaderInfo } from "@asyncapi/generator-components";
|
|
275
|
+
|
|
276
|
+
async function renderFileHeader() {
|
|
277
|
+
const parser = new Parser();
|
|
278
|
+
const asyncapi_websocket_query = path.resolve(__dirname, "../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml");
|
|
279
|
+
const language = "javascript";
|
|
280
|
+
|
|
281
|
+
// Parse the AsyncAPI document
|
|
282
|
+
const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
|
|
283
|
+
const parsedAsyncAPIDocument = parseResult.document;
|
|
284
|
+
|
|
285
|
+
return (
|
|
286
|
+
<FileHeaderInfo
|
|
287
|
+
info={parsedAsyncAPIDocument.info()}
|
|
288
|
+
server={parsedAsyncAPIDocument.servers().get("withPathname")}
|
|
289
|
+
language={language}
|
|
290
|
+
/>
|
|
291
|
+
)
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
renderFileHeader().catch(console.error);
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
<a name="HandleMessage"></a>
|
|
300
|
+
### HandleMessage()
|
|
301
|
+
Renders a WebSocket message handler method with optional pre- and post-execution logic.
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
**Parameters**
|
|
305
|
+
|
|
306
|
+
| Name | Type | Description |
|
|
307
|
+
|------|------|-------------|
|
|
308
|
+
| props | `Object` | Component props. |
|
|
309
|
+
| props.language | `Language` | Programming language used for method formatting. |
|
|
310
|
+
| props.methodName | `string` | Name of the method to generate. |
|
|
311
|
+
| props.methodParams | `Array.<string>` | List of parameters for the method. |
|
|
312
|
+
| props.preExecutionCode | `string` | Code to insert before the main function logic. |
|
|
313
|
+
| props.postExecutionCode | `string` | Code to insert after the main function logic. |
|
|
314
|
+
| props.customMethodConfig | `Object` | Optional overrides for default method configuration. |
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
**Returns**
|
|
319
|
+
|
|
320
|
+
- `JSX.Element` - A Text component that contains method block with appropriate formatting.
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
**Example**
|
|
325
|
+
|
|
326
|
+
```js
|
|
327
|
+
import { HandleMessage } from "@asyncapi/generator-components";
|
|
328
|
+
const language = "javascript";
|
|
329
|
+
const methodName = "handleMessage";
|
|
330
|
+
const methodParams = ["message","cb"];
|
|
331
|
+
const preExecutionCode = "// Pass the incoming message to all registered message handlers.";
|
|
332
|
+
const postExecutionCode = "// Passed the incoming message to all registered message handlers.";
|
|
333
|
+
const customMethodConfig = {
|
|
334
|
+
javascript: {
|
|
335
|
+
methodDocs: "// Method to handle message with callback",
|
|
336
|
+
methodLogic: "if (cb) cb(message);"
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
function renderHandleMessage() {
|
|
341
|
+
return (
|
|
342
|
+
<HandleMessage
|
|
343
|
+
language={language}
|
|
344
|
+
methodName={methodName}
|
|
345
|
+
methodParams={methodParams}
|
|
346
|
+
preExecutionCode={preExecutionCode}
|
|
347
|
+
postExecutionCode={postExecutionCode}
|
|
348
|
+
customMethodConfig={customMethodConfig}
|
|
349
|
+
/>
|
|
350
|
+
)
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
renderHandleMessage();
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
<a name="MethodGenerator"></a>
|
|
359
|
+
### MethodGenerator()
|
|
360
|
+
Renders a language-specific formatted method definition.
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
**Parameters**
|
|
364
|
+
|
|
365
|
+
| Name | Type | Description |
|
|
366
|
+
|------|------|-------------|
|
|
367
|
+
| props | `Object` | Component props. |
|
|
368
|
+
| props.language | `Language` | Programming language used for method formatting. |
|
|
369
|
+
| props.methodName | `string` | Name of the method. |
|
|
370
|
+
| props.methodParams | `Array.<string>` | Method parameters. |
|
|
371
|
+
| props.methodDocs | `string` | Optional documentation string. |
|
|
372
|
+
| props.methodLogic | `string` | Core method logic. |
|
|
373
|
+
| props.preExecutionCode | `string` | Code before main logic. |
|
|
374
|
+
| props.postExecutionCode | `string` | Code after main logic. |
|
|
375
|
+
| props.indent | `number` | Indentation for the method block. |
|
|
376
|
+
| props.newLines | `number` | Number of new lines after method. |
|
|
377
|
+
| props.customMethodConfig | `Object` | Optional custom syntax configuration for the current language. |
|
|
378
|
+
| props.methodConfig | `Object` | Language-level or framework-level configuration. |
|
|
379
|
+
| props.framework | `string` | Framework name for nested configurations (e.g., 'quarkus' for Java). |
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
**Returns**
|
|
384
|
+
|
|
385
|
+
- `JSX.Element` - A Text component that contains method block with appropriate formatting.
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
**Example**
|
|
390
|
+
|
|
391
|
+
```js
|
|
392
|
+
import { MethodGenerator } from "@asyncapi/generator-components";
|
|
393
|
+
const language = "java";
|
|
394
|
+
const methodName = "registerHandler";
|
|
395
|
+
const methodParams = ["Handler handler"];
|
|
396
|
+
const methodDocs = "// Process the input data.";
|
|
397
|
+
const methodLogic = "// TODO: implement";
|
|
398
|
+
const preExecutionCode = "// Before handler registration";
|
|
399
|
+
const postExecutionCode = "// After handler registration";
|
|
400
|
+
const customMethodConfig={ openingTag: "{", closingTag: "}", indentSize: 6 };
|
|
401
|
+
const methodConfig = {"java" : {"quarkus": {methodDocs : methodDocs, methodLogic: methodLogic }}};
|
|
402
|
+
const framework = "quarkus";
|
|
403
|
+
|
|
404
|
+
function renderMethodGenerator() {
|
|
405
|
+
return (
|
|
406
|
+
<MethodGenerator
|
|
407
|
+
language={language}
|
|
408
|
+
methodName={methodName}
|
|
409
|
+
methodParams={methodParams}
|
|
410
|
+
methodDocs={methodDocs}
|
|
411
|
+
methodLogic={methodLogic}
|
|
412
|
+
preExecutionCode={preExecutionCode}
|
|
413
|
+
postExecutionCode={postExecutionCode}
|
|
414
|
+
customMethodConfig={customMethodConfig}
|
|
415
|
+
methodConfig={methodConfig}
|
|
416
|
+
framework={framework}
|
|
417
|
+
/>
|
|
418
|
+
)
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
renderMethodGenerator();
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
<a name="Models"></a>
|
|
427
|
+
### Models()
|
|
428
|
+
Renders an array of model files based on the AsyncAPI document.
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
**Parameters**
|
|
432
|
+
|
|
433
|
+
| Name | Type | Description |
|
|
434
|
+
|------|------|-------------|
|
|
435
|
+
| props | `Object` | Component props. |
|
|
436
|
+
| props.asyncapi | `AsyncAPIDocumentInterface` | Parsed AsyncAPI document object. |
|
|
437
|
+
| props.language | `Language` | Target programming language for the generated models. |
|
|
438
|
+
| props.format | `Format` | Naming format for generated files. |
|
|
439
|
+
| props.presets | `Object` | Custom presets for the generator instance. |
|
|
440
|
+
| props.constraints | `Object` | Custom constraints for the generator instance. |
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
**Returns**
|
|
445
|
+
|
|
446
|
+
- `Array.<File>` - Array of File components with generated model content.
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
**Example**
|
|
451
|
+
|
|
452
|
+
```js
|
|
453
|
+
import path from "path";
|
|
454
|
+
import { Parser, fromFile } from "@asyncapi/parser";
|
|
455
|
+
import { Models } from "@asyncapi/generator-components";
|
|
456
|
+
|
|
457
|
+
async function renderModel() {
|
|
458
|
+
const parser = new Parser();
|
|
459
|
+
const asyncapi_v3_path = path.resolve(__dirname, "../__fixtures__/asyncapi-v3.yml");
|
|
460
|
+
|
|
461
|
+
// Parse the AsyncAPI document
|
|
462
|
+
const parseResult = await fromFile(parser, asyncapi_v3_path).parse();
|
|
463
|
+
const parsedAsyncAPIDocument = parseResult.document;
|
|
464
|
+
|
|
465
|
+
const language = "java";
|
|
466
|
+
|
|
467
|
+
return (
|
|
468
|
+
<Models
|
|
469
|
+
asyncapi={parsedAsyncAPIDocument}
|
|
470
|
+
language={language}
|
|
471
|
+
/>
|
|
472
|
+
)
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
renderModel().catch(console.error);
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
<a name="OnClose"></a>
|
|
481
|
+
### OnClose()
|
|
482
|
+
Renders a WebSocket onClose event handler for the specified programming language.
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
**Parameters**
|
|
486
|
+
|
|
487
|
+
| Name | Type | Description |
|
|
488
|
+
|------|------|-------------|
|
|
489
|
+
| props | `Object` | Component props. |
|
|
490
|
+
| props.language | `Language` | The programming language for which to generate onClose handler code. |
|
|
491
|
+
| props.framework | `string` | Framework variant; required for framework-specific languages (e.g., 'quarkus' for java). |
|
|
492
|
+
| props.title | `string` | The title of the WebSocket server. |
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
**Returns**
|
|
497
|
+
|
|
498
|
+
- `JSX.Element` - A Text component containing the onClose handler code for the specified language.
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
**Example**
|
|
503
|
+
|
|
504
|
+
```js
|
|
505
|
+
import { OnClose } from "@asyncapi/generator-components";
|
|
506
|
+
const language = "java";
|
|
507
|
+
const framework = "quarkus";
|
|
508
|
+
const title = "HoppscotchEchoWebSocketClient";
|
|
509
|
+
|
|
510
|
+
function renderOnClose() {
|
|
511
|
+
return (
|
|
512
|
+
<OnClose
|
|
513
|
+
language={language}
|
|
514
|
+
framework={framework}
|
|
515
|
+
title={title}
|
|
516
|
+
/>
|
|
517
|
+
)
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
renderOnClose();
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
<a name="OnError"></a>
|
|
526
|
+
### OnError()
|
|
527
|
+
Renders a WebSocket onError event handler for the specified programming language.
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
**Parameters**
|
|
531
|
+
|
|
532
|
+
| Name | Type | Description |
|
|
533
|
+
|------|------|-------------|
|
|
534
|
+
| props | `Object` | Component props. |
|
|
535
|
+
| props.language | `Language` | The programming language for which to generate onError handler code. |
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
**Returns**
|
|
540
|
+
|
|
541
|
+
- `JSX.Element` - A Text component containing the onError handler code for the specified language.
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
**Example**
|
|
546
|
+
|
|
547
|
+
```js
|
|
548
|
+
import { OnError } from "@asyncapi/generator-components";
|
|
549
|
+
const language = "javascript";
|
|
550
|
+
|
|
551
|
+
function renderOnError() {
|
|
552
|
+
return (
|
|
553
|
+
<OnError language={language} />
|
|
554
|
+
)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
renderOnError();
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
<a name="OnMessage"></a>
|
|
563
|
+
### OnMessage()
|
|
564
|
+
Renders a WebSocket onMessage event handler for the specified programming language.
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
**Parameters**
|
|
568
|
+
|
|
569
|
+
| Name | Type | Description |
|
|
570
|
+
|------|------|-------------|
|
|
571
|
+
| props | `Object` | Component props. |
|
|
572
|
+
| props.language | `Language` | The programming language for which to generate onMessage handler code. |
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
**Returns**
|
|
577
|
+
|
|
578
|
+
- `JSX.Element` - A Text component containing the onMessage handler code for the specified language.
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
**Example**
|
|
583
|
+
|
|
584
|
+
```js
|
|
585
|
+
import { OnMessage } from "@asyncapi/generator-components";
|
|
586
|
+
const language = "javascript";
|
|
587
|
+
|
|
588
|
+
function renderOnMessage() {
|
|
589
|
+
return (
|
|
590
|
+
<OnMessage language={language} />
|
|
591
|
+
)
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
renderOnMessage();
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
<a name="OnOpen"></a>
|
|
600
|
+
### OnOpen()
|
|
601
|
+
Renders a WebSocket onOpen event handler for the specified programming language.
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
**Parameters**
|
|
605
|
+
|
|
606
|
+
| Name | Type | Description |
|
|
607
|
+
|------|------|-------------|
|
|
608
|
+
| props | `Object` | Component props. |
|
|
609
|
+
| props.language | `Language` | The programming language for which to generate onOpen handler code. |
|
|
610
|
+
| props.framework | `string` | Optional framework variant (e.g., 'quarkus' for java). |
|
|
611
|
+
| props.title | `string` | The title of the WebSocket server. |
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
**Returns**
|
|
616
|
+
|
|
617
|
+
- `JSX.Element` - A Text component containing the onOpen handler code for the specified language.
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
**Example**
|
|
622
|
+
|
|
623
|
+
```js
|
|
624
|
+
import { OnOpen } from "@asyncapi/generator-components";
|
|
625
|
+
const language = "java";
|
|
626
|
+
const framework = "quarkus";
|
|
627
|
+
const title = "HoppscotchEchoWebSocketClient";
|
|
628
|
+
|
|
629
|
+
function renderOnOpen() {
|
|
630
|
+
return (
|
|
631
|
+
<OnOpen
|
|
632
|
+
language={language}
|
|
633
|
+
framework={framework}
|
|
634
|
+
title={title}
|
|
635
|
+
/>
|
|
636
|
+
)
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
renderOnOpen();
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
<a name="QueryParamsVariables"></a>
|
|
645
|
+
### QueryParamsVariables()
|
|
646
|
+
Renders query parameter variables code blocks.
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
**Parameters**
|
|
650
|
+
|
|
651
|
+
| Name | Type | Description |
|
|
652
|
+
|------|------|-------------|
|
|
653
|
+
| props | `Object` | Component props. |
|
|
654
|
+
| props.language | `Language` | The target programming language. |
|
|
655
|
+
| props.framework | `string` | Optional framework for the language. |
|
|
656
|
+
| props.queryParams | `Array.<Array.<string>>` | Array of query parameters, each represented as [paramName, paramType?]. |
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
**Returns**
|
|
661
|
+
|
|
662
|
+
- `Array.<JSX.Element>` - Array of Text components for each query parameter, or null if queryParams is invalid.
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
**Example**
|
|
667
|
+
|
|
668
|
+
```js
|
|
669
|
+
import path from "path";
|
|
670
|
+
import { Parser, fromFile } from "@asyncapi/parser";
|
|
671
|
+
import { getQueryParams } from "@asyncapi/generator-helpers";
|
|
672
|
+
import { QueryParamsVariables } from "@asyncapi/generator-components";
|
|
673
|
+
|
|
674
|
+
async function renderQueryParamsVariable(){
|
|
675
|
+
const parser = new Parser();
|
|
676
|
+
const asyncapi_v3_path = path.resolve(__dirname, "../__fixtures__/asyncapi-v3.yml");
|
|
677
|
+
|
|
678
|
+
// Parse the AsyncAPI document
|
|
679
|
+
const parseResult = await fromFile(parser, asyncapi_v3_path).parse();
|
|
680
|
+
const parsedAsyncAPIDocument = parseResult.document;
|
|
681
|
+
|
|
682
|
+
const channels = parsedAsyncAPIDocument.channels();
|
|
683
|
+
const queryParamsObject = getQueryParams(channels);
|
|
684
|
+
const queryParamsArray = queryParamsObject ? Array.from(queryParamsObject.entries()) : [];
|
|
685
|
+
|
|
686
|
+
const language = "java";
|
|
687
|
+
const framework = "quarkus";
|
|
688
|
+
|
|
689
|
+
return (
|
|
690
|
+
<QueryParamsVariables
|
|
691
|
+
language={language}
|
|
692
|
+
framework={framework}
|
|
693
|
+
queryParams={queryParamsArray}
|
|
694
|
+
/>
|
|
695
|
+
)
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
renderQueryParamsVariable().catch(console.error);
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
<a name="AvailableOperations"></a>
|
|
704
|
+
### AvailableOperations()
|
|
705
|
+
Renders a list of AsyncAPI operations with their headers and message examples.
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
**Parameters**
|
|
709
|
+
|
|
710
|
+
| Name | Type | Description |
|
|
711
|
+
|------|------|-------------|
|
|
712
|
+
| props | `Object` | Component Props |
|
|
713
|
+
| props.operations | `Array.<Object>` | Array of AsyncAPI Operation objects. |
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
**Returns**
|
|
718
|
+
|
|
719
|
+
- `JSX.Element` - A Component containing rendered operations, or null if no operations are provided
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
**Example**
|
|
724
|
+
|
|
725
|
+
```js
|
|
726
|
+
import path from "path";
|
|
727
|
+
import { Parser, fromFile } from "@asyncapi/parser";
|
|
728
|
+
import { AvailableOperations } from "@asyncapi/generator-components";
|
|
729
|
+
|
|
730
|
+
async function renderAvailableOperations(){
|
|
731
|
+
const parser = new Parser();
|
|
732
|
+
const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
|
|
733
|
+
|
|
734
|
+
//parse the AsyncAPI document
|
|
735
|
+
const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
|
|
736
|
+
const parsedAsyncAPIDocument = parseResult.document;
|
|
737
|
+
|
|
738
|
+
return (
|
|
739
|
+
<AvailableOperations operations={parsedAsyncAPIDocument.operations().all()} />
|
|
740
|
+
)
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
renderAvailableOperations().catch(console.error);
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
<a name="CoreMethods"></a>
|
|
749
|
+
### CoreMethods()
|
|
750
|
+
Renders a list of core WebSocket client methods for a given target language.
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
**Parameters**
|
|
754
|
+
|
|
755
|
+
| Name | Type | Description |
|
|
756
|
+
|------|------|-------------|
|
|
757
|
+
| props | `Object` | Component props |
|
|
758
|
+
| props.language | `Language` | Target language used to select method names. |
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
**Returns**
|
|
763
|
+
|
|
764
|
+
- `JSX.Element` - A Text component that contains a list of core client methods.
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
**Example**
|
|
769
|
+
|
|
770
|
+
```js
|
|
771
|
+
import { CoreMethods } from "@asyncapi/generator-components";
|
|
772
|
+
const language = "javascript";
|
|
773
|
+
|
|
774
|
+
function renderCoreMethods() {
|
|
775
|
+
return (
|
|
776
|
+
<CoreMethods language={language} />
|
|
777
|
+
)
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
renderCoreMethods();
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
<a name="Installation"></a>
|
|
786
|
+
### Installation()
|
|
787
|
+
Renders the Installation Command for a given language.
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
**Parameters**
|
|
791
|
+
|
|
792
|
+
| Name | Type | Description |
|
|
793
|
+
|------|------|-------------|
|
|
794
|
+
| props | `Object` | Component props |
|
|
795
|
+
| props.language | `Language` | The programming language for which to generate Installation Command. |
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
**Returns**
|
|
800
|
+
|
|
801
|
+
- `JSX.Element` - A Text component that contains Installation Command.
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
**Example**
|
|
806
|
+
|
|
807
|
+
```js
|
|
808
|
+
import { Installation } from "@asyncapi/generator-components";
|
|
809
|
+
const language = "javascript";
|
|
810
|
+
|
|
811
|
+
function renderInstallation() {
|
|
812
|
+
return (
|
|
813
|
+
<Installation language={language} />
|
|
814
|
+
)
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
renderInstallation()
|
|
818
|
+
```
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
<a name="MessageExamples"></a>
|
|
823
|
+
### MessageExamples()
|
|
824
|
+
Renders Message Examples of a given AsyncAPI operation.
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
**Parameters**
|
|
828
|
+
|
|
829
|
+
| Name | Type | Description |
|
|
830
|
+
|------|------|-------------|
|
|
831
|
+
| props | `Object` | Component Props |
|
|
832
|
+
| props.operation | `Object` | An AsyncAPI Operation object. |
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
**Returns**
|
|
837
|
+
|
|
838
|
+
- `JSX.Element` - A Text component that contains message examples, or null when no examples exist.
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
**Example**
|
|
843
|
+
|
|
844
|
+
```js
|
|
845
|
+
import path from "path";
|
|
846
|
+
import { Parser, fromFile } from "@asyncapi/parser";
|
|
847
|
+
import { MessageExamples } from "@asyncapi/generator-components";
|
|
848
|
+
|
|
849
|
+
async function renderMessageExamples(){
|
|
850
|
+
const parser = new Parser();
|
|
851
|
+
const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
|
|
852
|
+
|
|
853
|
+
//parse the AsyncAPI document
|
|
854
|
+
const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
|
|
855
|
+
const parsedAsyncAPIDocument = parseResult.document;
|
|
856
|
+
const operations = parsedAsyncAPIDocument.operations().all();
|
|
857
|
+
|
|
858
|
+
return operations.map((operation) => {
|
|
859
|
+
return (
|
|
860
|
+
<MessageExamples operation={operation} />
|
|
861
|
+
)
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
renderMessageExamples().catch(console.error);
|
|
866
|
+
```
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
<a name="OperationHeader"></a>
|
|
871
|
+
### OperationHeader()
|
|
872
|
+
Renders a header section for a single AsyncAPI operation.
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
**Parameters**
|
|
876
|
+
|
|
877
|
+
| Name | Type | Description |
|
|
878
|
+
|------|------|-------------|
|
|
879
|
+
| props | `Object` | Component properties. |
|
|
880
|
+
| props.operation | `Object` | An AsyncAPI Operation object. |
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
**Returns**
|
|
885
|
+
|
|
886
|
+
- `JSX.Element` - A Text component that contains formatted operation header.
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
**Example**
|
|
891
|
+
|
|
892
|
+
```js
|
|
893
|
+
import path from "path";
|
|
894
|
+
import { Parser, fromFile } from "@asyncapi/parser";
|
|
895
|
+
import { OperationHeader } from "@asyncapi/generator-components";
|
|
896
|
+
|
|
897
|
+
async function renderOperationHeader(){
|
|
898
|
+
const parser = new Parser();
|
|
899
|
+
const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
|
|
900
|
+
|
|
901
|
+
//parse the AsyncAPI document
|
|
902
|
+
const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
|
|
903
|
+
const parsedAsyncAPIDocument = parseResult.document;
|
|
904
|
+
const operations = parsedAsyncAPIDocument.operations().all();
|
|
905
|
+
|
|
906
|
+
return operations.map((operation) => {
|
|
907
|
+
return (
|
|
908
|
+
<OperationHeader operation={operation} />
|
|
909
|
+
)
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
renderOperationHeader().catch(console.error);
|
|
914
|
+
```
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
<a name="Overview"></a>
|
|
919
|
+
### Overview()
|
|
920
|
+
Renders an overview section for a WebSocket client. Displays the API description, version, and server URL.
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
**Parameters**
|
|
924
|
+
|
|
925
|
+
| Name | Type | Description |
|
|
926
|
+
|------|------|-------------|
|
|
927
|
+
| props | `Object` | Component props |
|
|
928
|
+
| props.info | `Object` | Info object from the AsyncAPI document. |
|
|
929
|
+
| props.title | `string` | Title from the AsyncAPI document. |
|
|
930
|
+
| props.serverUrl | `string` | ServerUrl from a specific server from the AsyncAPI document. |
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
**Returns**
|
|
935
|
+
|
|
936
|
+
- `JSX.Element` - A Text component that contains the Overview of a Websocket client.
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
**Example**
|
|
941
|
+
|
|
942
|
+
```js
|
|
943
|
+
import path from "path";
|
|
944
|
+
import { Parser, fromFile } from "@asyncapi/parser";
|
|
945
|
+
import { getServer, getServerUrl } from '@asyncapi/generator-helpers';
|
|
946
|
+
import { Overview } from "@asyncapi/generator-components";
|
|
947
|
+
|
|
948
|
+
async function renderOverview(){
|
|
949
|
+
const parser = new Parser();
|
|
950
|
+
const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
|
|
951
|
+
|
|
952
|
+
//parse the AsyncAPI document
|
|
953
|
+
const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
|
|
954
|
+
const parsedAsyncAPIDocument = parseResult.document;
|
|
955
|
+
|
|
956
|
+
const info = parsedAsyncAPIDocument.info();
|
|
957
|
+
const title = info.title();
|
|
958
|
+
const server = getServer(parsedAsyncAPIDocument.servers(), 'withoutPathName');
|
|
959
|
+
const serverUrl = getServerUrl(server);
|
|
960
|
+
|
|
961
|
+
return (
|
|
962
|
+
<Overview
|
|
963
|
+
info={info}
|
|
964
|
+
title={title}
|
|
965
|
+
serverUrl={serverUrl}
|
|
966
|
+
/>
|
|
967
|
+
)
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
renderOverview().catch(console.error);
|
|
971
|
+
```
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+
<a name="Readme"></a>
|
|
976
|
+
### Readme()
|
|
977
|
+
Renders a README.md file for a given AsyncAPI document. Composes multiple sections (overview, installation, usage, core methods, and available operations) into a single File component based on the provided AsyncAPI document, generator parameters, and target language.
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
**Parameters**
|
|
981
|
+
|
|
982
|
+
| Name | Type | Description |
|
|
983
|
+
|------|------|-------------|
|
|
984
|
+
| props | `Object` | Component props |
|
|
985
|
+
| props.asyncapi | `AsyncAPIDocumentInterface` | Parsed AsyncAPI document instance. |
|
|
986
|
+
| props.params | `Object` | Generator parameters used to customize output |
|
|
987
|
+
| props.language | `Language` | Target language used to render language-specific sections. |
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
**Returns**
|
|
992
|
+
|
|
993
|
+
- `JSX.Element` - A File component representing the generated README.md.
|
|
994
|
+
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
**Example**
|
|
998
|
+
|
|
999
|
+
```js
|
|
1000
|
+
import path from "path";
|
|
1001
|
+
import { Parser, fromFile } from "@asyncapi/parser";
|
|
1002
|
+
import { buildParams } from '@asyncapi/generator-helpers';
|
|
1003
|
+
import { Readme } from "@asyncapi/generator-components";
|
|
1004
|
+
|
|
1005
|
+
async function renderReadme(){
|
|
1006
|
+
const parser = new Parser();
|
|
1007
|
+
const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
|
|
1008
|
+
|
|
1009
|
+
// parse the AsyncAPI document
|
|
1010
|
+
const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
|
|
1011
|
+
const parsedAsyncAPIDocument = parseResult.document;
|
|
1012
|
+
const language = "javascript";
|
|
1013
|
+
const config = { clientFileName: 'myClient.js' };
|
|
1014
|
+
const params = buildParams('javascript', config, 'echoServer');
|
|
1015
|
+
|
|
1016
|
+
return (
|
|
1017
|
+
<Readme
|
|
1018
|
+
asyncapi={parsedAsyncAPIDocument}
|
|
1019
|
+
params={params}
|
|
1020
|
+
language={language}
|
|
1021
|
+
/>
|
|
1022
|
+
)
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
renderReadme().catch(console.error);
|
|
1026
|
+
```
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
<a name="Usage"></a>
|
|
1031
|
+
### Usage()
|
|
1032
|
+
Renders a usage example snippet for a generated WebSocket client in a given language.
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
**Parameters**
|
|
1036
|
+
|
|
1037
|
+
| Name | Type | Description |
|
|
1038
|
+
|------|------|-------------|
|
|
1039
|
+
| props | `Object` | Component props |
|
|
1040
|
+
| props.clientName | `string` | The exported name of the client. |
|
|
1041
|
+
| props.clientFileName | `string` | The file name where the client is defined. |
|
|
1042
|
+
| props.language | `Language` | The target language for which to render the usage snippet |
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
**Returns**
|
|
1047
|
+
|
|
1048
|
+
- `JSX.Element` - A Text component containing a formatted usage example snippet.
|
|
1049
|
+
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
**Example**
|
|
1053
|
+
|
|
1054
|
+
```js
|
|
1055
|
+
import { Usage } from "@asyncapi/generator-components";
|
|
1056
|
+
const clientName = "MyClient";
|
|
1057
|
+
const clientFileName = "myClient.js";
|
|
1058
|
+
const language = "javascript";
|
|
1059
|
+
|
|
1060
|
+
function renderUsage(){
|
|
1061
|
+
return (
|
|
1062
|
+
<Usage
|
|
1063
|
+
clientName={clientName}
|
|
1064
|
+
clientFileName={clientFileName}
|
|
1065
|
+
language={language}
|
|
1066
|
+
/>
|
|
1067
|
+
)
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
renderUsage();
|
|
1071
|
+
```
|
|
1072
|
+
|
|
1073
|
+
|
|
1074
|
+
|
|
1075
|
+
<a name="RegisterErrorHandler"></a>
|
|
1076
|
+
### RegisterErrorHandler()
|
|
1077
|
+
Renders a WebSocket error handler registration method with optional pre- and post-execution logic.
|
|
1078
|
+
|
|
1079
|
+
|
|
1080
|
+
**Parameters**
|
|
1081
|
+
|
|
1082
|
+
| Name | Type | Description |
|
|
1083
|
+
|------|------|-------------|
|
|
1084
|
+
| props | `Object` | Component props. |
|
|
1085
|
+
| props.language | `Language` | Programming language used for method formatting. |
|
|
1086
|
+
| props.methodName | `string` | Name of the method to generate. |
|
|
1087
|
+
| props.methodParams | `Array.<string>` | List of parameters for the method. |
|
|
1088
|
+
| props.preExecutionCode | `string` | Code to insert before the main function logic. |
|
|
1089
|
+
| props.postExecutionCode | `string` | Code to insert after the main function logic. |
|
|
1090
|
+
| props.customMethodConfig | `Object` | Optional overrides for default method configuration. |
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
|
|
1094
|
+
**Returns**
|
|
1095
|
+
|
|
1096
|
+
- `JSX.Element` - A Text component that contains method block with appropriate formatting.
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
|
|
1100
|
+
**Example**
|
|
1101
|
+
|
|
1102
|
+
```js
|
|
1103
|
+
import { RegisterErrorHandler } from "@asyncapi/generator-components";
|
|
1104
|
+
const language = "python";
|
|
1105
|
+
const methodName = "registerErrorHandler";
|
|
1106
|
+
const methodParams = ["self", "handler"];
|
|
1107
|
+
const preExecutionCode = "# Pre-register operations";
|
|
1108
|
+
const postExecutionCode = "# Post-register operations";
|
|
1109
|
+
const customMethodConfig = { returnType: "int", openingTag: "{", closingTag: "}", indentSize: 2};
|
|
1110
|
+
|
|
1111
|
+
function renderRegisterErrorHandler() {
|
|
1112
|
+
return (
|
|
1113
|
+
<RegisterErrorHandler
|
|
1114
|
+
language={language}
|
|
1115
|
+
methodName={methodName}
|
|
1116
|
+
methodParams={methodParams}
|
|
1117
|
+
preExecutionCode={preExecutionCode}
|
|
1118
|
+
postExecutionCode={postExecutionCode}
|
|
1119
|
+
customMethodConfig={customMethodConfig}
|
|
1120
|
+
/>
|
|
1121
|
+
)
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
renderRegisterErrorHandler();
|
|
1125
|
+
```
|
|
1126
|
+
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
<a name="RegisterMessageHandler"></a>
|
|
1130
|
+
### RegisterMessageHandler()
|
|
1131
|
+
Renders a WebSocket message handler registration method with optional pre- and post-execution logic.
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
**Parameters**
|
|
1135
|
+
|
|
1136
|
+
| Name | Type | Description |
|
|
1137
|
+
|------|------|-------------|
|
|
1138
|
+
| props | `Object` | Component props. |
|
|
1139
|
+
| props.language | `Language` | Programming language used for method formatting. |
|
|
1140
|
+
| props.methodName | `string` | Name of the method to generate. |
|
|
1141
|
+
| props.methodParams | `Array.<string>` | List of parameters for the method. |
|
|
1142
|
+
| props.preExecutionCode | `string` | Code to insert before the main function logic. |
|
|
1143
|
+
| props.postExecutionCode | `string` | Code to insert after the main function logic. |
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
**Returns**
|
|
1148
|
+
|
|
1149
|
+
- `JSX.Element` - A Text component that contains method block with appropriate formatting.
|
|
1150
|
+
|
|
1151
|
+
|
|
1152
|
+
|
|
1153
|
+
**Example**
|
|
1154
|
+
|
|
1155
|
+
```js
|
|
1156
|
+
import { RegisterMessageHandler } from "@asyncapi/generator-components";
|
|
1157
|
+
const language = "python";
|
|
1158
|
+
const methodName = "registerMessageHandler";
|
|
1159
|
+
const methodParams = ["self", "handler"];
|
|
1160
|
+
const preExecutionCode = "# Pre-register operations";
|
|
1161
|
+
const postExecutionCode = "# Post-register operations";
|
|
1162
|
+
|
|
1163
|
+
function renderRegisterMessageHandler(){
|
|
1164
|
+
return (
|
|
1165
|
+
<RegisterMessageHandler
|
|
1166
|
+
language={language}
|
|
1167
|
+
methodName={methodName}
|
|
1168
|
+
methodParams={methodParams}
|
|
1169
|
+
preExecutionCode={preExecutionCode}
|
|
1170
|
+
postExecutionCode={postExecutionCode}
|
|
1171
|
+
/>
|
|
1172
|
+
)
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
renderRegisterMessageHandler();
|
|
1176
|
+
```
|
|
1177
|
+
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
<a name="SendOperations"></a>
|
|
1181
|
+
### SendOperations()
|
|
1182
|
+
Renders WebSocket send operation methods. Generates both static and instance methods for sending messages through WebSocket connections.
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
**Parameters**
|
|
1186
|
+
|
|
1187
|
+
| Name | Type | Description |
|
|
1188
|
+
|------|------|-------------|
|
|
1189
|
+
| props | `Object` | Component props. |
|
|
1190
|
+
| props.language | `Language` | The target programming language. |
|
|
1191
|
+
| props.sendOperations | `Array.<Object>` | Array of send operations from AsyncAPI document. |
|
|
1192
|
+
| props.clientName | `string` | The name of the client class. |
|
|
1193
|
+
|
|
1194
|
+
|
|
1195
|
+
|
|
1196
|
+
**Returns**
|
|
1197
|
+
|
|
1198
|
+
- `Array.<JSX.Element>` - Array of Text components for static and non-static WebSocket send operation methods, or null if no send operations are provided.
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
**Example**
|
|
1203
|
+
|
|
1204
|
+
```js
|
|
1205
|
+
import path from "path";
|
|
1206
|
+
import { Parser, fromFile } from "@asyncapi/parser";
|
|
1207
|
+
import { SendOperations } from "@asyncapi/generator-components";
|
|
1208
|
+
|
|
1209
|
+
async function renderSendOperations(){
|
|
1210
|
+
const parser = new Parser();
|
|
1211
|
+
const asyncapi_v3_path = path.resolve(__dirname, '../__fixtures__/asyncapi-v3.yml');
|
|
1212
|
+
|
|
1213
|
+
// Parse the AsyncAPI document
|
|
1214
|
+
const parseResult = await fromFile(parser, asyncapi_v3_path).parse();
|
|
1215
|
+
const parsedAsyncAPIDocument = parseResult.document;
|
|
1216
|
+
|
|
1217
|
+
const language = "javascript";
|
|
1218
|
+
const clientName = "AccountServiceAPI";
|
|
1219
|
+
const sendOperations = parsedAsyncAPIDocument.operations().filterBySend();
|
|
1220
|
+
|
|
1221
|
+
return (
|
|
1222
|
+
<SendOperations
|
|
1223
|
+
language={language}
|
|
1224
|
+
clientName={clientName}
|
|
1225
|
+
sendOperations={sendOperations}
|
|
1226
|
+
/>
|
|
1227
|
+
)
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
renderSendOperations().catch(console.error);
|
|
1231
|
+
```
|
|
1232
|
+
|
|
1233
|
+
|