Components
-
CloseConnection ⇒
JSX.ElementRenders a WebSocket close connection method with optional pre- and post-execution logic.
-
Connect ⇒
JSX.ElementRenders a WebSocket connection method for the specified programming language.
-
DependencyProvider ⇒
JSX.ElementRenders the top-of-file dependency statements for the selected programming language.
-
FileHeaderInfo ⇒
JSX.ElementRenders a file header with metadata information such as title, version, protocol, host, and path.
-
HandleMessage ⇒
JSX.ElementRenders a WebSocket message handler method with optional pre- and post-execution logic.
-
MethodGenerator ⇒
JSX.ElementRenders a language-specific formatted method definition.
-
Models ⇒
Array.<File>Renders an array of model files based on the AsyncAPI document.
-
OnClose ⇒
JSX.ElementRenders a WebSocket onClose event handler for the specified programming language.
-
OnError ⇒
JSX.ElementRenders a WebSocket onError event handler for the specified programming language.
-
OnMessage ⇒
JSX.ElementRenders a WebSocket onMessage event handler for the specified programming language.
-
OnOpen ⇒
JSX.ElementRenders a WebSocket onOpen event handler for the specified programming language.
-
QueryParamsVariables ⇒
Array.<JSX.Element>Renders query parameter variables code blocks.
-
AvailableOperations ⇒
JSX.ElementRenders a list of AsyncAPI operations with their headers and message examples.
-
CoreMethods ⇒
JSX.ElementRenders a list of core WebSocket client methods for a given target language.
-
Installation ⇒
JSX.ElementRenders the Installation Command for a given language.
-
MessageExamples ⇒
JSX.ElementRenders Message Examples of a given AsyncAPI operation.
-
OperationHeader ⇒
JSX.ElementRenders a header section for a single AsyncAPI operation.
-
Overview ⇒
JSX.ElementRenders an overview section for a WebSocket client. Displays the API description, version, and server URL.
-
Readme ⇒
JSX.ElementRenders 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.ElementRenders a usage example snippet for a generated WebSocket client in a given language.
-
RegisterErrorHandler ⇒
JSX.ElementRenders a WebSocket error handler registration method with optional pre- and post-execution logic.
-
RegisterMessageHandler ⇒
JSX.ElementRenders 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
1import { CloseConnection } from "@asyncapi/generator-components";
2const language = "java";
3const framework = "quarkus";
4const methodName = "terminateConnection";
5const methodParams = ["String reason"];
6const preExecutionCode = "// About to terminate connection";
7const postExecutionCode = "// Connection terminated";
8const indent = 2;
9
10function renderCloseConnection() {
11 return (
12 <CloseConnection
13 language={language}
14 framework={framework}
15 methodName={methodName}
16 methodParams={methodParams}
17 preExecutionCode={preExecutionCode}
18 postExecutionCode={postExecutionCode}
19 indent={indent}
20 />
21 );
22}
23
24renderCloseConnection();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
1import { Connect } from "@asyncapi/generator-components";
2const language = "python";
3const title = "HoppscotchEchoWebSocketClient";
4
5function renderConnect() {
6 return(
7 <Connect
8 language={language}
9 title={title}
10 />
11 )
12}
13
14renderConnect();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
1import { DependencyProvider } from "@asyncapi/generator-components";
2const language = "java";
3const framework = "quarkus";
4const role = "client";
5const additionalDependencies = ["import java.util.concurrent.CompletableFuture;", "import java.time.Duration;"];
6
7function renderDependencyProvider() {
8 return (
9 <DependencyProvider
10 language={language}
11 framework={framework}
12 role={role}
13 additionalDependencies={additionalDependencies}
14 />
15 )
16}
17renderDependencyProvider();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
1import { HandleMessage } from "@asyncapi/generator-components";
2const language = "javascript";
3const methodName = "handleMessage";
4const methodParams = ["message","cb"];
5const preExecutionCode = "// Pass the incoming message to all registered message handlers.";
6const postExecutionCode = "// Passed the incoming message to all registered message handlers.";
7const customMethodConfig = {
8 javascript: {
9 methodDocs: "// Method to handle message with callback",
10 methodLogic: "if (cb) cb(message);"
11 }
12};
13
14function renderHandleMessage() {
15 return (
16 <HandleMessage
17 language={language}
18 methodName={methodName}
19 methodParams={methodParams}
20 preExecutionCode={preExecutionCode}
21 postExecutionCode={postExecutionCode}
22 customMethodConfig={customMethodConfig}
23 />
24 )
25}
26
27renderHandleMessage();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 | Object | 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
1import { MethodGenerator } from "@asyncapi/generator-components";
2const language = "java";
3const methodName = "registerHandler";
4const methodParams = ["Handler handler"];
5const methodDocs = "// Process the input data.";
6const methodLogic = "// TODO: implement";
7const preExecutionCode = "// Before handler registration";
8const postExecutionCode = "// After handler registration";
9const customMethodConfig={ openingTag: "{", closingTag: "}", indentSize: 6 };
10const methodConfig = {"java" : {"quarkus": {methodDocs : methodDocs, methodLogic: methodLogic }}};
11const framework = "quarkus";
12
13function renderMethodGenerator() {
14 return (
15 <MethodGenerator
16 language={language}
17 methodName={methodName}
18 methodParams={methodParams}
19 methodDocs={methodDocs}
20 methodLogic={methodLogic}
21 preExecutionCode={preExecutionCode}
22 postExecutionCode={postExecutionCode}
23 customMethodConfig={customMethodConfig}
24 methodConfig={methodConfig}
25 framework={framework}
26 />
27 )
28}
29
30renderMethodGenerator();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
1import { OnClose } from "@asyncapi/generator-components";
2const language = "java";
3const framework = "quarkus";
4const title = "HoppscotchEchoWebSocketClient";
5
6function renderOnClose() {
7 return (
8 <OnClose
9 language={language}
10 framework={framework}
11 title={title}
12 />
13 )
14}
15
16renderOnClose();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
1import { OnError } from "@asyncapi/generator-components";
2const language = "javascript";
3
4function renderOnError() {
5 return (
6 <OnError language={language} />
7 )
8}
9
10renderOnError();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
1import { OnMessage } from "@asyncapi/generator-components";
2const language = "javascript";
3
4function renderOnMessage() {
5 return (
6 <OnMessage language={language} />
7 )
8}
9
10renderOnMessage();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
1import { OnOpen } from "@asyncapi/generator-components";
2const language = "java";
3const framework = "quarkus";
4const title = "HoppscotchEchoWebSocketClient";
5
6function renderOnOpen() {
7 return (
8 <OnOpen
9 language={language}
10 framework={framework}
11 title={title}
12 />
13 )
14}
15
16renderOnOpen();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
1import { CoreMethods } from "@asyncapi/generator-components";
2const language = "javascript";
3
4function renderCoreMethods() {
5 return (
6 <CoreMethods language={language} />
7 )
8}
9
10renderCoreMethods();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
1import { Installation } from "@asyncapi/generator-components";
2const language = "javascript";
3
4function renderInstallation() {
5 return (
6 <Installation language={language} />
7 )
8}
9
10renderInstallation()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
1import { Usage } from "@asyncapi/generator-components";
2const clientName = "MyClient";
3const clientFileName = "myClient.js";
4const language = "javascript";
5
6function renderUsage(){
7 return (
8 <Usage
9 clientName={clientName}
10 clientFileName={clientFileName}
11 language={language}
12 />
13 )
14}
15
16renderUsage();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
1import { RegisterErrorHandler } from "@asyncapi/generator-components";
2const language = "python";
3const methodName = "registerErrorHandler";
4const methodParams = ["self", "handler"];
5const preExecutionCode = "# Pre-register operations";
6const postExecutionCode = "# Post-register operations";
7const customMethodConfig = { returnType: "int", openingTag: "{", closingTag: "}", indentSize: 2};
8
9function renderRegisterErrorHandler() {
10 return (
11 <RegisterErrorHandler
12 language={language}
13 methodName={methodName}
14 methodParams={methodParams}
15 preExecutionCode={preExecutionCode}
16 postExecutionCode={postExecutionCode}
17 customMethodConfig={customMethodConfig}
18 />
19 )
20}
21
22renderRegisterErrorHandler();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
1import { RegisterMessageHandler } from "@asyncapi/generator-components";
2const language = "python";
3const methodName = "registerMessageHandler";
4const methodParams = ["self", "handler"];
5const preExecutionCode = "# Pre-register operations";
6const postExecutionCode = "# Post-register operations";
7
8function renderRegisterMessageHandler(){
9 return (
10 <RegisterMessageHandler
11 language={language}
12 methodName={methodName}
13 methodParams={methodParams}
14 preExecutionCode={preExecutionCode}
15 postExecutionCode={postExecutionCode}
16 />
17 )
18}
19
20renderRegisterMessageHandler();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);