Components
- CloseConnection ⇒
JSX.Element Renders a WebSocket close connection method with optional pre- and post-execution logic.
- Connect ⇒
JSX.Element Renders a WebSocket connection method for the specified programming language.
- DependencyProvider ⇒
JSX.Element Renders the top-of-file dependency statements for the selected programming language.
- FileHeaderInfo ⇒
JSX.Element Renders a file header with metadata information such as title, version, protocol, host, and path.
- HandleMessage ⇒
JSX.Element Renders a WebSocket message handler method with optional pre- and post-execution logic.
- MethodGenerator ⇒
JSX.Element Renders a language-specific formatted method definition.
- Models ⇒
Array.<File> Renders an array of model files based on the AsyncAPI document.
- OnClose ⇒
JSX.Element Renders a WebSocket onClose event handler for the specified programming language.
- OnError ⇒
JSX.Element Renders a WebSocket onError event handler for the specified programming language.
- OnMessage ⇒
JSX.Element Renders a WebSocket onMessage event handler for the specified programming language.
- OnOpen ⇒
JSX.Element Renders a WebSocket onOpen event handler for the specified programming language.
- QueryParamsVariables ⇒
Array.<JSX.Element> Renders query parameter variables code blocks.
- AvailableOperations ⇒
JSX.Element Renders a list of AsyncAPI operations with their headers and message examples.
- CoreMethods ⇒
JSX.Element Renders a list of core WebSocket client methods for a given target language.
- Installation ⇒
JSX.Element Renders the Installation Command for a given language.
- MessageExamples ⇒
JSX.Element Renders Message Examples of a given AsyncAPI operation.
- OperationHeader ⇒
JSX.Element Renders a header section for a single AsyncAPI operation.
- Overview ⇒
JSX.Element Renders an overview section for a WebSocket client. Displays the API description, version, and server URL.
- Readme ⇒
JSX.Element 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.
- Usage ⇒
JSX.Element Renders a usage example snippet for a generated WebSocket client in a given language.
- RegisterErrorHandler ⇒
JSX.Element Renders a WebSocket error handler registration method with optional pre- and post-execution logic.
- RegisterMessageHandler ⇒
JSX.Element Renders a WebSocket message handler registration method with optional pre- and post-execution logic.
- SendOperations ⇒
Array.<JSX.Element> Renders WebSocket send operation methods. Generates both static and instance methods for sending messages through WebSocket connections.
CloseConnection()
Renders a WebSocket close connection method with optional pre- and post-execution logic.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props. |
| props.language | Language | Programming language used for method formatting. |
| props.framework | string | Framework used, if any (e.g., 'quarkus' for Java). |
| props.methodName | string | Name of the method to generate. |
| props.methodParams | Array.<string> | List of parameters for the method. |
| props.preExecutionCode | string | Code to insert before the main function logic. |
| props.postExecutionCode | string | Code to insert after the main function logic. |
| props.indent | number | Indentation level for the method block. |
Returns
JSX.Element- A Text component that contains method block with appropriate formatting.
Example
1const language = "java";
2const framework = "quarkus";
3const methodName = "terminateConnection";
4const methodParams = ["String reason"];
5const preExecutionCode = "// About to terminate connection";
6const postExecutionCode = "// Connection terminated";
7const indent = 2;
8
9function renderCloseConnection() {
10 return (
11 <CloseConnection
12 language={language}
13 framework={framework}
14 methodName={methodName}
15 methodParams={methodParams}
16 preExecutionCode={preExecutionCode}
17 postExecutionCode={postExecutionCode}
18 indent={indent}
19 />
20 );
21}
22
23renderCloseConnection();Connect()
Renders a WebSocket connection method for the specified programming language.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props. |
| props.language | Language | The programming language for which to generate connection code. |
| props.title | string | The title of the WebSocket server. |
Returns
JSX.Element- A Text component containing the generated WebSocket connection code for the specified language.
Example
1const language = "python";
2const title = "HoppscotchEchoWebSocketClient";
3
4function renderConnect() {
5 return(
6 <Connect
7 language={language}
8 title={title}
9 />
10 )
11}
12
13renderConnect();DependencyProvider()
Renders the top-of-file dependency statements for the selected programming language.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props. |
| props.language | Language | The programming language for which to render dependency statements. |
| props.framework | string | The framework (e.g., 'quarkus' for Java). |
| props.role | string | The role (e.g., 'client', 'connector' for Java). |
| props.additionalDependencies | Array.<string> | Optional additional dependencies to include. |
Returns
JSX.Element- A Text component that contains list of import/require statements.
Example
1const language = "java";
2const framework = "quarkus";
3const role = "client";
4const additionalDependencies = ["import java.util.concurrent.CompletableFuture;", "import java.time.Duration;"];
5
6function renderDependencyProvider() {
7 return (
8 <DependencyProvider
9 language={language}
10 framework={framework}
11 role={role}
12 additionalDependencies={additionalDependencies}
13 />
14 )
15}
16renderDependencyProvider();FileHeaderInfo()
Renders a file header with metadata information such as title, version, protocol, host, and path.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props. |
| props.info | Object | Info object from the AsyncAPI document. |
| props.server | Object | Server object from the AsyncAPI document. |
| props.language | Language | Programming language used for comment formatting. |
Returns
JSX.Element- A Text component that contains file header.
Example
1import path from "path";
2import { Parser, fromFile } from "@asyncapi/parser";
3import { FileHeaderInfo } from "@asyncapi/generator-components";
4
5async function renderFileHeader() {
6 const parser = new Parser();
7 const asyncapi_websocket_query = path.resolve(__dirname, "../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml");
8 const language = "javascript";
9
10 // Parse the AsyncAPI document
11 const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
12 const parsedAsyncAPIDocument = parseResult.document;
13
14 return (
15 <FileHeaderInfo
16 info={parsedAsyncAPIDocument.info()}
17 server={parsedAsyncAPIDocument.servers().get("withPathname")}
18 language={language}
19 />
20 )
21}
22
23renderFileHeader().catch(console.error);HandleMessage()
Renders a WebSocket message handler method with optional pre- and post-execution logic.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props. |
| props.language | Language | Programming language used for method formatting. |
| props.methodName | string | Name of the method to generate. |
| props.methodParams | Array.<string> | List of parameters for the method. |
| props.preExecutionCode | string | Code to insert before the main function logic. |
| props.postExecutionCode | string | Code to insert after the main function logic. |
| props.customMethodConfig | Object | Optional overrides for default method configuration. |
Returns
JSX.Element- A Text component that contains method block with appropriate formatting.
Example
1const language = "javascript";
2const methodName = "handleMessage";
3const methodParams = ["message","cb"];
4const preExecutionCode = "// Pass the incoming message to all registered message handlers.";
5const postExecutionCode = "// Passed the incoming message to all registered message handlers.";
6const customMethodConfig = {
7 javascript: {
8 methodDocs: "// Method to handle message with callback",
9 methodLogic: "if (cb) cb(message);"
10 }
11};
12
13function renderHandleMessage() {
14 return (
15 <HandleMessage
16 language={language}
17 methodName={methodName}
18 methodParams={methodParams}
19 preExecutionCode={preExecutionCode}
20 postExecutionCode={postExecutionCode}
21 customMethodConfig={customMethodConfig}
22 />
23 )
24}
25
26renderHandleMessage();MethodGenerator()
Renders a language-specific formatted method definition.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props. |
| props.language | Language | Programming language used for method formatting. |
| props.methodName | string | Name of the method. |
| props.methodParams | Array.<string> | Method parameters. |
| props.methodDocs | string | Optional documentation string. |
| props.methodLogic | string | Core method logic. |
| props.preExecutionCode | string | Code before main logic. |
| props.postExecutionCode | string | Code after main logic. |
| props.indent | number | Indentation for the method block. |
| props.newLines | number | Number of new lines after method. |
| props.customMethodConfig | Object | Optional custom syntax configuration for the current language. |
| props.methodConfig | Record.<Language, ({methodDocs: (string|undefined), methodLogic: (string|undefined)}|Record.<string, {methodDocs: (string|undefined), methodLogic: (string|undefined)}>)> | Language-level or framework-level configuration. |
| props.framework | string | Framework name for nested configurations (e.g., 'quarkus' for Java). |
Returns
JSX.Element- A Text component that contains method block with appropriate formatting.
Example
1const language = "java";
2const methodName = "registerHandler";
3const methodParams = ["Handler handler"];
4const methodDocs = "// Process the input data.";
5const methodLogic = "// TODO: implement";
6const preExecutionCode = "// Before handler registration";
7const postExecutionCode = "// After handler registration";
8const customMethodConfig={ openingTag: "{", closingTag: "}", indentSize: 6 };
9const methodConfig = {"java" : {"quarkus": {methodDocs : methodDocs, methodLogic: methodLogic }}};
10const framework = "quarkus";
11
12function renderMethodGenerator() {
13 return (
14 <MethodGenerator
15 language={language}
16 methodName={methodName}
17 methodParams={methodParams}
18 methodDocs={methodDocs}
19 methodLogic={methodLogic}
20 preExecutionCode={preExecutionCode}
21 postExecutionCode={postExecutionCode}
22 customMethodConfig={customMethodConfig}
23 methodConfig={methodConfig}
24 framework={framework}
25 />
26 )
27}
28
29renderMethodGenerator();Models()
Renders an array of model files based on the AsyncAPI document.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props. |
| props.asyncapi | AsyncAPIDocumentInterface | Parsed AsyncAPI document object. |
| props.language | Language | Target programming language for the generated models. |
| props.format | Format | Naming format for generated files. |
| props.presets | Object | Custom presets for the generator instance. |
| props.constraints | Object | Custom constraints for the generator instance. |
Returns
Array.<File>- Array of File components with generated model content.
Example
1import path from "path";
2import { Parser, fromFile } from "@asyncapi/parser";
3import { Models } from "@asyncapi/generator-components";
4
5async function renderModel() {
6 const parser = new Parser();
7 const asyncapi_v3_path = path.resolve(__dirname, "../__fixtures__/asyncapi-v3.yml");
8
9 // Parse the AsyncAPI document
10 const parseResult = await fromFile(parser, asyncapi_v3_path).parse();
11 const parsedAsyncAPIDocument = parseResult.document;
12
13 const language = "java";
14
15 return (
16 <Models
17 asyncapi={parsedAsyncAPIDocument}
18 language={language}
19 />
20 )
21}
22
23renderModel().catch(console.error);OnClose()
Renders a WebSocket onClose event handler for the specified programming language.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props. |
| props.language | Language | The programming language for which to generate onClose handler code. |
| props.framework | string | Framework variant; required for framework-specific languages (e.g., 'quarkus' for java). |
| props.title | string | The title of the WebSocket server. |
Returns
JSX.Element- A Text component containing the onClose handler code for the specified language.
Example
1const language = "java";
2const framework = "quarkus";
3const title = "HoppscotchEchoWebSocketClient";
4
5function renderOnClose() {
6 return (
7 <OnClose
8 language={language}
9 framework={framework}
10 title={title}
11 />
12 )
13}
14
15renderOnClose();OnError()
Renders a WebSocket onError event handler for the specified programming language.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props. |
| props.language | Language | The programming language for which to generate onError handler code. |
Returns
JSX.Element- A Text component containing the onError handler code for the specified language.
Example
1const language = "javascript";
2
3function renderOnError() {
4 return (
5 <OnError language={language} />
6 )
7}
8
9renderOnError();OnMessage()
Renders a WebSocket onMessage event handler for the specified programming language.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props. |
| props.language | Language | The programming language for which to generate onMessage handler code. |
Returns
JSX.Element- A Text component containing the onMessage handler code for the specified language.
Example
1const language = "javascript";
2
3function renderOnMessage() {
4 return (
5 <OnMessage language={language} />
6 )
7}
8
9renderOnMessage();OnOpen()
Renders a WebSocket onOpen event handler for the specified programming language.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props. |
| props.language | Language | The programming language for which to generate onOpen handler code. |
| props.framework | string | Optional framework variant (e.g., 'quarkus' for java). |
| props.title | string | The title of the WebSocket server. |
Returns
JSX.Element- A Text component containing the onOpen handler code for the specified language.
Example
1const language = "java";
2const framework = "quarkus";
3const title = "HoppscotchEchoWebSocketClient";
4
5function renderOnOpen() {
6 return (
7 <OnOpen
8 language={language}
9 framework={framework}
10 title={title}
11 />
12 )
13}
14
15renderOnOpen();QueryParamsVariables()
Renders query parameter variables code blocks.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props. |
| props.language | Language | The target programming language. |
| props.framework | string | Optional framework for the language. |
| props.queryParams | Array.<Array.<string>> | Array of query parameters, each represented as [paramName, paramType?]. |
Returns
Array.<JSX.Element>- Array of Text components for each query parameter, or null if queryParams is invalid.
Example
1import path from "path";
2import { Parser, fromFile } from "@asyncapi/parser";
3import { getQueryParams } from "@asyncapi/generator-helpers";
4import { QueryParamsVariables } from "@asyncapi/generator-components";
5
6async function renderQueryParamsVariable(){
7 const parser = new Parser();
8 const asyncapi_v3_path = path.resolve(__dirname, "../__fixtures__/asyncapi-v3.yml");
9
10 // Parse the AsyncAPI document
11 const parseResult = await fromFile(parser, asyncapi_v3_path).parse();
12 const parsedAsyncAPIDocument = parseResult.document;
13
14 const channels = parsedAsyncAPIDocument.channels();
15 const queryParamsObject = getQueryParams(channels);
16 const queryParamsArray = queryParamsObject ? Array.from(queryParamsObject.entries()) : [];
17
18 const language = "java";
19 const framework = "quarkus";
20
21 return (
22 <QueryParamsVariables
23 language={language}
24 framework={framework}
25 queryParams={queryParamsArray}
26 />
27 )
28}
29
30renderQueryParamsVariable().catch(console.error);AvailableOperations()
Renders a list of AsyncAPI operations with their headers and message examples.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component Props |
| props.operations | Array.<Object> | Array of AsyncAPI Operation objects. |
Returns
JSX.Element- A Component containing rendered operations, or null if no operations are provided
Example
1import path from "path";
2import { Parser, fromFile } from "@asyncapi/parser";
3import { AvailableOperations } from "@asyncapi/generator-components";
4
5async function renderAvailableOperations(){
6 const parser = new Parser();
7 const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
8
9 //parse the AsyncAPI document
10 const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
11 const parsedAsyncAPIDocument = parseResult.document;
12
13 return (
14 <AvailableOperations operations={parsedAsyncAPIDocument.operations().all()} />
15 )
16}
17
18renderAvailableOperations().catch(console.error);CoreMethods()
Renders a list of core WebSocket client methods for a given target language.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props |
| props.language | Language | Target language used to select method names. |
Returns
JSX.Element- A Text component that contains a list of core client methods.
Example
1const language = "javascript";
2
3function renderCoreMethods() {
4 return (
5 <CoreMethods language={language} />
6 )
7}
8
9renderCoreMethods();Installation()
Renders the Installation Command for a given language.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props |
| props.language | Language | The programming language for which to generate Installation Command. |
Returns
JSX.Element- A Text component that contains Installation Command.
Example
1const language = "javascript";
2
3function renderInstallation() {
4 return (
5 <Installation language={language} />
6 )
7}
8
9renderInstallation()MessageExamples()
Renders Message Examples of a given AsyncAPI operation.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component Props |
| props.operation | Object | An AsyncAPI Operation object. |
Returns
JSX.Element- A Text component that contains message examples, or null when no examples exist.
Example
1import path from "path";
2import { Parser, fromFile } from "@asyncapi/parser";
3import { MessageExamples } from "@asyncapi/generator-components";
4
5async function renderMessageExamples(){
6 const parser = new Parser();
7 const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
8
9 //parse the AsyncAPI document
10 const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
11 const parsedAsyncAPIDocument = parseResult.document;
12 const operations = parsedAsyncAPIDocument.operations().all();
13
14 return operations.map((operation) => {
15 return (
16 <MessageExamples operation={operation} />
17 )
18 });
19}
20
21renderMessageExamples().catch(console.error);OperationHeader()
Renders a header section for a single AsyncAPI operation.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component properties. |
| props.operation | Object | An AsyncAPI Operation object. |
Returns
JSX.Element- A Text component that contains formatted operation header.
Example
1import path from "path";
2import { Parser, fromFile } from "@asyncapi/parser";
3import { OperationHeader } from "@asyncapi/generator-components";
4
5async function renderOperationHeader(){
6 const parser = new Parser();
7 const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
8
9 //parse the AsyncAPI document
10 const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
11 const parsedAsyncAPIDocument = parseResult.document;
12 const operations = parsedAsyncAPIDocument.operations().all();
13
14 return operations.map((operation) => {
15 return (
16 <OperationHeader operation={operation} />
17 )
18 });
19}
20
21renderOperationHeader().catch(console.error);Overview()
Renders an overview section for a WebSocket client. Displays the API description, version, and server URL.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props |
| props.info | Object | Info object from the AsyncAPI document. |
| props.title | string | Title from the AsyncAPI document. |
| props.serverUrl | string | ServerUrl from a specific server from the AsyncAPI document. |
Returns
JSX.Element- A Text component that contains the Overview of a Websocket client.
Example
1import path from "path";
2import { Parser, fromFile } from "@asyncapi/parser";
3import { getServer, getServerUrl } from '@asyncapi/generator-helpers';
4import { Overview } from "@asyncapi/generator-components";
5
6async function renderOverview(){
7 const parser = new Parser();
8 const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
9
10 //parse the AsyncAPI document
11 const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
12 const parsedAsyncAPIDocument = parseResult.document;
13
14 const info = parsedAsyncAPIDocument.info();
15 const title = info.title();
16 const server = getServer(parsedAsyncAPIDocument.servers(), 'withoutPathName');
17 const serverUrl = getServerUrl(server);
18
19 return (
20 <Overview
21 info={info}
22 title={title}
23 serverUrl={serverUrl}
24 />
25 )
26}
27
28renderOverview().catch(console.error);Readme()
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.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props |
| props.asyncapi | AsyncAPIDocumentInterface | Parsed AsyncAPI document instance. |
| props.params | Object | Generator parameters used to customize output |
| props.language | Language | Target language used to render language-specific sections. |
Returns
JSX.Element- A File component representing the generated README.md.
Example
1import path from "path";
2import { Parser, fromFile } from "@asyncapi/parser";
3import { buildParams } from '@asyncapi/generator-helpers';
4import { Readme } from "@asyncapi/generator-components";
5
6async function renderReadme(){
7 const parser = new Parser();
8 const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
9
10 // parse the AsyncAPI document
11 const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
12 const parsedAsyncAPIDocument = parseResult.document;
13 const language = "javascript";
14 const config = { clientFileName: 'myClient.js' };
15 const params = buildParams('javascript', config, 'echoServer');
16
17 return (
18 <Readme
19 asyncapi={parsedAsyncAPIDocument}
20 params={params}
21 language={language}
22 />
23 )
24}
25
26renderReadme().catch(console.error);Usage()
Renders a usage example snippet for a generated WebSocket client in a given language.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props |
| props.clientName | string | The exported name of the client. |
| props.clientFileName | string | The file name where the client is defined. |
| props.language | Language | The target language for which to render the usage snippet |
Returns
JSX.Element- A Text component containing a formatted usage example snippet.
Example
1const clientName = "MyClient";
2const clientFileName = "myClient.js";
3const language = "javascript";
4
5function renderUsage(){
6 return (
7 <Usage
8 clientName={clientName}
9 clientFileName={clientFileName}
10 language={language}
11 />
12 )
13}
14
15renderUsage();RegisterErrorHandler()
Renders a WebSocket error handler registration method with optional pre- and post-execution logic.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props. |
| props.language | Language | Programming language used for method formatting. |
| props.methodName | string | Name of the method to generate. |
| props.methodParams | Array.<string> | List of parameters for the method. |
| props.preExecutionCode | string | Code to insert before the main function logic. |
| props.postExecutionCode | string | Code to insert after the main function logic. |
| props.customMethodConfig | Object | Optional overrides for default method configuration. |
Returns
JSX.Element- A Text component that contains method block with appropriate formatting.
Example
1const language = "python";
2const methodName = "registerErrorHandler";
3const methodParams = ["self", "handler"];
4const preExecutionCode = "# Pre-register operations";
5const postExecutionCode = "# Post-register operations";
6const customMethodConfig = { returnType: "int", openingTag: "{", closingTag: "}", indentSize: 2};
7
8function renderRegisterErrorHandler() {
9 return (
10 <RegisterErrorHandler
11 language={language}
12 methodName={methodName}
13 methodParams={methodParams}
14 preExecutionCode={preExecutionCode}
15 postExecutionCode={postExecutionCode}
16 customMethodConfig={customMethodConfig}
17 />
18 )
19}
20
21renderRegisterErrorHandler();RegisterMessageHandler()
Renders a WebSocket message handler registration method with optional pre- and post-execution logic.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props. |
| props.language | Language | Programming language used for method formatting. |
| props.methodName | string | Name of the method to generate. |
| props.methodParams | Array.<string> | List of parameters for the method. |
| props.preExecutionCode | string | Code to insert before the main function logic. |
| props.postExecutionCode | string | Code to insert after the main function logic. |
Returns
JSX.Element- A Text component that contains method block with appropriate formatting.
Example
1const language = "python";
2const methodName = "registerMessageHandler";
3const methodParams = ["self", "handler"];
4const preExecutionCode = "# Pre-register operations";
5const postExecutionCode = "# Post-register operations";
6
7function renderRegisterMessageHandler(){
8 return (
9 <RegisterMessageHandler
10 language={language}
11 methodName={methodName}
12 methodParams={methodParams}
13 preExecutionCode={preExecutionCode}
14 postExecutionCode={postExecutionCode}
15 />
16 )
17}
18
19renderRegisterMessageHandler();SendOperations()
Renders WebSocket send operation methods. Generates both static and instance methods for sending messages through WebSocket connections.
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | Component props. |
| props.language | Language | The target programming language. |
| props.sendOperations | Array.<Object> | Array of send operations from AsyncAPI document. |
| props.clientName | string | The name of the client class. |
Returns
Array.<JSX.Element>- Array of Text components for static and non-static WebSocket send operation methods, or null if no send operations are provided.
Example
1import path from "path";
2import { Parser, fromFile } from "@asyncapi/parser";
3import { SendOperations } from "@asyncapi/generator-components";
4
5async function renderSendOperations(){
6 const parser = new Parser();
7 const asyncapi_v3_path = path.resolve(__dirname, '../__fixtures__/asyncapi-v3.yml');
8
9 // Parse the AsyncAPI document
10 const parseResult = await fromFile(parser, asyncapi_v3_path).parse();
11 const parsedAsyncAPIDocument = parseResult.document;
12
13 const language = "javascript";
14 const clientName = "AccountServiceAPI";
15 const sendOperations = parsedAsyncAPIDocument.operations().filterBySend();
16
17 return (
18 <SendOperations
19 language={language}
20 clientName={clientName}
21 sendOperations={sendOperations}
22 />
23 )
24}
25
26renderSendOperations().catch(console.error);