Reusable Components API

Found an error? Have a suggestion?Edit this page on GitHub

Components

  • CloseConnectionJSX.Element

    Renders a WebSocket close connection method with optional pre- and post-execution logic.

  • ConnectJSX.Element

    Renders a WebSocket connection method for the specified programming language.

  • DependencyProviderJSX.Element

    Renders the top-of-file dependency statements for the selected programming language.

  • FileHeaderInfoJSX.Element

    Renders a file header with metadata information such as title, version, protocol, host, and path.

  • HandleMessageJSX.Element

    Renders a WebSocket message handler method with optional pre- and post-execution logic.

  • MethodGeneratorJSX.Element

    Renders a language-specific formatted method definition.

  • ModelsArray.<File>

    Renders an array of model files based on the AsyncAPI document.

  • OnCloseJSX.Element

    Renders a WebSocket onClose event handler for the specified programming language.

  • OnErrorJSX.Element

    Renders a WebSocket onError event handler for the specified programming language.

  • OnMessageJSX.Element

    Renders a WebSocket onMessage event handler for the specified programming language.

  • OnOpenJSX.Element

    Renders a WebSocket onOpen event handler for the specified programming language.

  • QueryParamsVariablesArray.<JSX.Element>

    Renders query parameter variables code blocks.

  • AvailableOperationsJSX.Element

    Renders a list of AsyncAPI operations with their headers and message examples.

  • CoreMethodsJSX.Element

    Renders a list of core WebSocket client methods for a given target language.

  • InstallationJSX.Element

    Renders the Installation Command for a given language.

  • MessageExamplesJSX.Element

    Renders Message Examples of a given AsyncAPI operation.

  • OperationHeaderJSX.Element

    Renders a header section for a single AsyncAPI operation.

  • OverviewJSX.Element

    Renders an overview section for a WebSocket client. Displays the API description, version, and server URL.

  • ReadmeJSX.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.

  • UsageJSX.Element

    Renders a usage example snippet for a generated WebSocket client in a given language.

  • RegisterErrorHandlerJSX.Element

    Renders a WebSocket error handler registration method with optional pre- and post-execution logic.

  • RegisterMessageHandlerJSX.Element

    Renders a WebSocket message handler registration method with optional pre- and post-execution logic.

  • SendOperationsArray.<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

NameTypeDescription
propsObjectComponent props.
props.languageLanguageProgramming language used for method formatting.
props.frameworkstringFramework used, if any (e.g., 'quarkus' for Java).
props.methodNamestringName of the method to generate.
props.methodParamsArray.<string>List of parameters for the method.
props.preExecutionCodestringCode to insert before the main function logic.
props.postExecutionCodestringCode to insert after the main function logic.
props.indentnumberIndentation 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

NameTypeDescription
propsObjectComponent props.
props.languageLanguageThe programming language for which to generate connection code.
props.titlestringThe 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

NameTypeDescription
propsObjectComponent props.
props.languageLanguageThe programming language for which to render dependency statements.
props.frameworkstringThe framework (e.g., 'quarkus' for Java).
props.rolestringThe role (e.g., 'client', 'connector' for Java).
props.additionalDependenciesArray.<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

NameTypeDescription
propsObjectComponent props.
props.infoObjectInfo object from the AsyncAPI document.
props.serverObjectServer object from the AsyncAPI document.
props.languageLanguageProgramming 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

NameTypeDescription
propsObjectComponent props.
props.languageLanguageProgramming language used for method formatting.
props.methodNamestringName of the method to generate.
props.methodParamsArray.<string>List of parameters for the method.
props.preExecutionCodestringCode to insert before the main function logic.
props.postExecutionCodestringCode to insert after the main function logic.
props.customMethodConfigObjectOptional 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

NameTypeDescription
propsObjectComponent props.
props.languageLanguageProgramming language used for method formatting.
props.methodNamestringName of the method.
props.methodParamsArray.<string>Method parameters.
props.methodDocsstringOptional documentation string.
props.methodLogicstringCore method logic.
props.preExecutionCodestringCode before main logic.
props.postExecutionCodestringCode after main logic.
props.indentnumberIndentation for the method block.
props.newLinesnumberNumber of new lines after method.
props.customMethodConfigObjectOptional custom syntax configuration for the current language.
props.methodConfigObjectLanguage-level or framework-level configuration.
props.frameworkstringFramework 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

NameTypeDescription
propsObjectComponent props.
props.asyncapiAsyncAPIDocumentInterfaceParsed AsyncAPI document object.
props.languageLanguageTarget programming language for the generated models.
props.formatFormatNaming format for generated files.
props.presetsObjectCustom presets for the generator instance.
props.constraintsObjectCustom 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

NameTypeDescription
propsObjectComponent props.
props.languageLanguageThe programming language for which to generate onClose handler code.
props.frameworkstringFramework variant; required for framework-specific languages (e.g., 'quarkus' for java).
props.titlestringThe 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

NameTypeDescription
propsObjectComponent props.
props.languageLanguageThe 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

NameTypeDescription
propsObjectComponent props.
props.languageLanguageThe 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

NameTypeDescription
propsObjectComponent props.
props.languageLanguageThe programming language for which to generate onOpen handler code.
props.frameworkstringOptional framework variant (e.g., 'quarkus' for java).
props.titlestringThe 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

NameTypeDescription
propsObjectComponent props.
props.languageLanguageThe target programming language.
props.frameworkstringOptional framework for the language.
props.queryParamsArray.<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

NameTypeDescription
propsObjectComponent Props
props.operationsArray.<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

NameTypeDescription
propsObjectComponent props
props.languageLanguageTarget 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

NameTypeDescription
propsObjectComponent props
props.languageLanguageThe 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

NameTypeDescription
propsObjectComponent Props
props.operationObjectAn 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

NameTypeDescription
propsObjectComponent properties.
props.operationObjectAn 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

NameTypeDescription
propsObjectComponent props
props.infoObjectInfo object from the AsyncAPI document.
props.titlestringTitle from the AsyncAPI document.
props.serverUrlstringServerUrl 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

NameTypeDescription
propsObjectComponent props
props.asyncapiAsyncAPIDocumentInterfaceParsed AsyncAPI document instance.
props.paramsObjectGenerator parameters used to customize output
props.languageLanguageTarget 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

NameTypeDescription
propsObjectComponent props
props.clientNamestringThe exported name of the client.
props.clientFileNamestringThe file name where the client is defined.
props.languageLanguageThe 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

NameTypeDescription
propsObjectComponent props.
props.languageLanguageProgramming language used for method formatting.
props.methodNamestringName of the method to generate.
props.methodParamsArray.<string>List of parameters for the method.
props.preExecutionCodestringCode to insert before the main function logic.
props.postExecutionCodestringCode to insert after the main function logic.
props.customMethodConfigObjectOptional 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

NameTypeDescription
propsObjectComponent props.
props.languageLanguageProgramming language used for method formatting.
props.methodNamestringName of the method to generate.
props.methodParamsArray.<string>List of parameters for the method.
props.preExecutionCodestringCode to insert before the main function logic.
props.postExecutionCodestringCode 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

NameTypeDescription
propsObjectComponent props.
props.languageLanguageThe target programming language.
props.sendOperationsArray.<Object>Array of send operations from AsyncAPI document.
props.clientNamestringThe 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);
Was this helpful?
Help us improve the docs by adding your contribution.
OR
Github:AsyncAPICreate Issue on GitHub