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.
-
HandleError ⇒
JSX.ElementRenders the
handleError(or framework-equivalent) method body that dispatches an error to registered handlers (or logs it when none are registered). -
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.
-
createError ⇒
ErrorCreates an error with a specific error code for programmatic handling
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;910function renderCloseConnection() {11 return (12 <CloseConnection13 language={language}14 framework={framework}15 methodName={methodName}16 methodParams={methodParams}17 preExecutionCode={preExecutionCode}18 postExecutionCode={postExecutionCode}19 indent={indent}20 />21 );22}2324renderCloseConnection();
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";45function renderConnect() {6 return(7 <Connect8 language={language}9 title={title}10 />11 )12}1314renderConnect();
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;"];67function renderDependencyProvider() {8 return (9 <DependencyProvider10 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";45async 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";910 // Parse the AsyncAPI document11 const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();12 const parsedAsyncAPIDocument = parseResult.document;1314 return (15 <FileHeaderInfo16 info={parsedAsyncAPIDocument.info()}17 server={parsedAsyncAPIDocument.servers().get("withPathname")}18 language={language}19 />20 )21}2223renderFileHeader().catch(console.error);
HandleError()
Renders the `handleError` (or framework-equivalent) method body that dispatches an error to registered handlers (or logs it when none are registered).
Parameters
| Name | Type | Description |
|---|---|---|
| props | Object | |
| props.language | Language | Target programming language. |
| props.framework | string | Framework discriminator (required for languages with multiple frameworks, e.g. `java` → `quarkus`). |
Returns
JSX.Element- A `<Text>` block containing the rendered method.
Example
1import { HandleError } from '@asyncapi/generator-components';23function renderHandleError() {4 return <HandleError language='python' />;5}
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};1314function renderHandleMessage() {15 return (16 <HandleMessage17 language={language}18 methodName={methodName}19 methodParams={methodParams}20 preExecutionCode={preExecutionCode}21 postExecutionCode={postExecutionCode}22 customMethodConfig={customMethodConfig}23 />24 )25}2627renderHandleMessage();
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 (non-empty string required). |
| 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 (must be >= 0). |
| 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";1213function renderMethodGenerator() {14 return (15 <MethodGenerator16 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}2930renderMethodGenerator();
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";45async function renderModel() {6 const parser = new Parser();7 const asyncapi_v3_path = path.resolve(__dirname, "../__fixtures__/asyncapi-v3.yml");89 // Parse the AsyncAPI document10 const parseResult = await fromFile(parser, asyncapi_v3_path).parse();11 const parsedAsyncAPIDocument = parseResult.document;1213 const language = "java";1415 return (16 <Models17 asyncapi={parsedAsyncAPIDocument}18 language={language}19 />20 )21}2223renderModel().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";56function renderOnClose() {7 return (8 <OnClose9 language={language}10 framework={framework}11 title={title}12 />13 )14}1516renderOnClose();
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";34function renderOnError() {5 return (6 <OnError language={language} />7 )8}910renderOnError();
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";34function renderOnMessage() {5 return (6 <OnMessage language={language} />7 )8}910renderOnMessage();
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";56function renderOnOpen() {7 return (8 <OnOpen9 language={language}10 framework={framework}11 title={title}12 />13 )14}1516renderOnOpen();
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";56async function renderQueryParamsVariable(){7 const parser = new Parser();8 const asyncapi_v3_path = path.resolve(__dirname, "../__fixtures__/asyncapi-v3.yml");910 // Parse the AsyncAPI document11 const parseResult = await fromFile(parser, asyncapi_v3_path).parse();12 const parsedAsyncAPIDocument = parseResult.document;1314 const channels = parsedAsyncAPIDocument.channels();15 const queryParamsObject = getQueryParams(channels);16 const queryParamsArray = queryParamsObject ? Array.from(queryParamsObject.entries()) : [];1718 const language = "java";19 const framework = "quarkus";2021 return (22 <QueryParamsVariables23 language={language}24 framework={framework}25 queryParams={queryParamsArray}26 />27 )28}2930renderQueryParamsVariable().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";45async function renderAvailableOperations(){6 const parser = new Parser();7 const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');89 //parse the AsyncAPI document10 const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();11 const parsedAsyncAPIDocument = parseResult.document;1213 return (14 <AvailableOperations operations={parsedAsyncAPIDocument.operations().all()} />15 )16}1718renderAvailableOperations().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";34function renderCoreMethods() {5 return (6 <CoreMethods language={language} />7 )8}910renderCoreMethods();
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";34function renderInstallation() {5 return (6 <Installation language={language} />7 )8}910renderInstallation()
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";45async function renderMessageExamples(){6 const parser = new Parser();7 const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');89 //parse the AsyncAPI document10 const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();11 const parsedAsyncAPIDocument = parseResult.document;12 const operations = parsedAsyncAPIDocument.operations().all();1314 return operations.map((operation) => {15 return (16 <MessageExamples operation={operation} />17 )18 });19}2021renderMessageExamples().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";45async function renderOperationHeader(){6 const parser = new Parser();7 const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');89 //parse the AsyncAPI document10 const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();11 const parsedAsyncAPIDocument = parseResult.document;12 const operations = parsedAsyncAPIDocument.operations().all();1314 return operations.map((operation) => {15 return (16 <OperationHeader operation={operation} />17 )18 });19}2021renderOperationHeader().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";56async function renderOverview(){7 const parser = new Parser();8 const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');910 //parse the AsyncAPI document11 const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();12 const parsedAsyncAPIDocument = parseResult.document;1314 const info = parsedAsyncAPIDocument.info();15 const title = info.title();16 const server = getServer(parsedAsyncAPIDocument.servers(), 'withoutPathName');17 const serverUrl = getServerUrl(server);1819 return (20 <Overview21 info={info}22 title={title}23 serverUrl={serverUrl}24 />25 )26}2728renderOverview().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";56async function renderReadme(){7 const parser = new Parser();8 const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');910 // parse the AsyncAPI document11 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');1617 return (18 <Readme19 asyncapi={parsedAsyncAPIDocument}20 params={params}21 language={language}22 />23 )24}2526renderReadme().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";56function renderUsage(){7 return (8 <Usage9 clientName={clientName}10 clientFileName={clientFileName}11 language={language}12 />13 )14}1516renderUsage();
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};89function renderRegisterErrorHandler() {10 return (11 <RegisterErrorHandler12 language={language}13 methodName={methodName}14 methodParams={methodParams}15 preExecutionCode={preExecutionCode}16 postExecutionCode={postExecutionCode}17 customMethodConfig={customMethodConfig}18 />19 )20}2122renderRegisterErrorHandler();
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";78function renderRegisterMessageHandler(){9 return (10 <RegisterMessageHandler11 language={language}12 methodName={methodName}13 methodParams={methodParams}14 preExecutionCode={preExecutionCode}15 postExecutionCode={postExecutionCode}16 />17 )18}1920renderRegisterMessageHandler();
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";45async function renderSendOperations(){6 const parser = new Parser();7 const asyncapi_v3_path = path.resolve(__dirname, '../__fixtures__/asyncapi-v3.yml');89 // Parse the AsyncAPI document10 const parseResult = await fromFile(parser, asyncapi_v3_path).parse();11 const parsedAsyncAPIDocument = parseResult.document;1213 const language = "javascript";14 const clientName = "AccountServiceAPI";15 const sendOperations = parsedAsyncAPIDocument.operations().filterBySend();1617 return (18 <SendOperations19 language={language}20 clientName={clientName}21 sendOperations={sendOperations}22 />23 )24}2526renderSendOperations().catch(console.error);
createError()
Creates an error with a specific error code for programmatic handling
Parameters
| Name | Type | Description |
|---|---|---|
| code | string | The error code (from ERROR_CODES) |
| message | string | The error message |
Returns
Error- An error object with an attached code property