Skip to content

Commit bd31cc1

Browse files
committed
wrap Asyncapi parse in async function
1 parent 80b3cfd commit bd31cc1

File tree

14 files changed

+282
-122
lines changed

14 files changed

+282
-122
lines changed

packages/components/docs/API.md

Lines changed: 141 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,15 @@ const postExecutionCode = "// Connection terminated"
143143
const indent = 2
144144

145145
return (
146-
<CloseConnection language={language} framework={framework} methodName={methodName} methodParams={methodParams} preExecutionCode={preExecutionCode} postExecutionCode={postExecutionCode} indent={indent} />
146+
<CloseConnection
147+
language={language}
148+
framework={framework}
149+
methodName={methodName}
150+
methodParams={methodParams}
151+
preExecutionCode={preExecutionCode}
152+
postExecutionCode={postExecutionCode}
153+
indent={indent}
154+
/>
147155
);
148156
```
149157

@@ -172,7 +180,10 @@ const language = "python"
172180
const title = "HoppscotchEchoWebSocketClient"
173181

174182
return(
175-
<Connect language={language} title={title} />
183+
<Connect
184+
language={language}
185+
title={title}
186+
/>
176187
)
177188
```
178189

@@ -210,7 +221,12 @@ const role = "client"
210221
const additionalDependencies = ["import java.util.concurrent.CompletableFuture;", "import java.time.Duration;"]
211222

212223
return (
213-
<DependencyProvider language={language} framework={framework} role={role} additionalDependencies={additionalDependencies} />
224+
<DependencyProvider
225+
language={language}
226+
framework={framework}
227+
role={role}
228+
additionalDependencies={additionalDependencies}
229+
/>
214230
)
215231
```
216232

@@ -244,17 +260,23 @@ Renders a file header with metadata information such as title, version, protocol
244260
import path from "path";
245261
import { Parser, fromFile } from "@asyncapi/parser";
246262

247-
const parser = new Parser();
248-
const asyncapi_websocket_query = path.resolve(__dirname, "../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml");
249-
const language = "javascript"
250-
251-
// Parse the AsyncAPI document (async operation)
252-
const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
253-
const parsedAsyncAPIDocument = parseResult.document;
254-
255-
return (
256-
<FileHeaderInfo info={parsedAsyncAPIDocument.info()} server={parsedAsyncAPIDocument.servers().get("withPathname")} language={language} />
257-
)
263+
async function renderFileHeader() {
264+
const parser = new Parser();
265+
const asyncapi_websocket_query = path.resolve(__dirname, "../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml");
266+
const language = "javascript"
267+
268+
// Parse the AsyncAPI document
269+
const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
270+
const parsedAsyncAPIDocument = parseResult.document;
271+
272+
return (
273+
<FileHeaderInfo
274+
info={parsedAsyncAPIDocument.info()}
275+
server={parsedAsyncAPIDocument.servers().get("withPathname")}
276+
language={language}
277+
/>
278+
)
279+
}
258280
```
259281

260282

@@ -299,7 +321,14 @@ const customMethodConfig = {
299321
}
300322
};
301323
return (
302-
<HandleMessage language={language} methodName={methodName} methodParams={methodParams} preExecutionCode={preExecutionCode} postExecutionCode={postExecutionCode} customMethodConfig={customMethodConfig} />
324+
<HandleMessage
325+
language={language}
326+
methodName={methodName}
327+
methodParams={methodParams}
328+
preExecutionCode={preExecutionCode}
329+
postExecutionCode={postExecutionCode}
330+
customMethodConfig={customMethodConfig}
331+
/>
303332
)
304333
```
305334

@@ -346,7 +375,18 @@ const methodConfig = {"java" : {methodDocs : methodDocs, methodLogic: methodLogi
346375
const framework = "quarkus"
347376

348377
return (
349-
<MethodGenerator language={language} methodName={methodName} methodParams={methodParams} methodDocs={methodDocs} methodLogic={methodLogic} preExecutionCode={preExecutionCode} postExecutionCode={postExecutionCode} customMethodConfig={customMethodConfig} methodConfig={methodConfig} framework={framework} />
378+
<MethodGenerator
379+
language={language}
380+
methodName={methodName}
381+
methodParams={methodParams}
382+
methodDocs={methodDocs}
383+
methodLogic={methodLogic}
384+
preExecutionCode={preExecutionCode}
385+
postExecutionCode={postExecutionCode}
386+
customMethodConfig={customMethodConfig}
387+
methodConfig={methodConfig}
388+
framework={framework}
389+
/>
350390
)
351391
```
352392

@@ -382,18 +422,24 @@ Generates and returns an array of model files based on the AsyncAPI document.
382422
import path from "path";
383423
import { Parser, fromFile } from "@asyncapi/parser";
384424

385-
const parser = new Parser();
386-
const asyncapi_v3_path = path.resolve(__dirname, "../__fixtures__/asyncapi-v3.yml");
387-
388-
// Parse the AsyncAPI document (async operation)
389-
const parseResult = await fromFile(parser, asyncapi_v3_path).parse();
390-
const parsedAsyncAPIDocument = parseResult.document;
391425

392-
const language = "java"
393-
394-
return (
395-
<Models asyncapi={parsedAsyncAPIDocument} language={language} />
396-
)
426+
async function renderModel() {
427+
const parser = new Parser();
428+
const asyncapi_v3_path = path.resolve(__dirname, "../__fixtures__/asyncapi-v3.yml");
429+
430+
// Parse the AsyncAPI document
431+
const parseResult = await fromFile(parser, asyncapi_v3_path).parse();
432+
const parsedAsyncAPIDocument = parseResult.document;
433+
434+
const language = "java"
435+
436+
return (
437+
<Models
438+
asyncapi={parsedAsyncAPIDocument}
439+
language={language}
440+
/>
441+
)
442+
}
397443
```
398444

399445

@@ -428,7 +474,11 @@ const framework = "quarkus"
428474
const title = "HoppscotchEchoWebSocketClient"
429475

430476
return (
431-
<OnClose language={language} framework={framework} title={title} />
477+
<OnClose
478+
language={language}
479+
framework={framework}
480+
title={title}
481+
/>
432482
)
433483
```
434484

@@ -511,7 +561,11 @@ const framework = "quarkus"
511561
const title = "HoppscotchEchoWebSocketClient"
512562

513563
return (
514-
<OnOpen language={language} framework={framework} title={title} />
564+
<OnOpen
565+
language={language}
566+
framework={framework}
567+
title={title}
568+
/>
515569
)
516570
```
517571

@@ -546,23 +600,30 @@ import path from "path"
546600
import { Parser, fromFile } from "@asyncapi/parser";
547601
import { getQueryParams } from "@asyncapi/generator-helpers";
548602

549-
const parser = new Parser();
550-
const asyncapi_v3_path = path.resolve(__dirname, "../__fixtures__/asyncapi-v3.yml");
551-
552-
// Parse the AsyncAPI document (async operation)
553-
const parseResult = await fromFile(parser, asyncapi_v3_path).parse();
554-
const parsedAsyncAPIDocument = parseResult.document;
555-
556-
const channels = parsedAsyncAPIDocument.channels();
557-
const queryParamsObject = getQueryParams(channels);
558-
const queryParamsArray = queryParamsObject ? Array.from(queryParamsObject.entries()) : [];
559603

560-
const language = "java"
561-
const framework = "quarkus"
562-
563-
return (
564-
<QueryParamsVariables language={language} framework={framework} queryParams={queryParamsArray} />
565-
)
604+
async function renderQueryParamsVariable(){
605+
const parser = new Parser();
606+
const asyncapi_v3_path = path.resolve(__dirname, "../__fixtures__/asyncapi-v3.yml");
607+
608+
// Parse the AsyncAPI document
609+
const parseResult = await fromFile(parser, asyncapi_v3_path).parse();
610+
const parsedAsyncAPIDocument = parseResult.document;
611+
612+
const channels = parsedAsyncAPIDocument.channels();
613+
const queryParamsObject = getQueryParams(channels);
614+
const queryParamsArray = queryParamsObject ? Array.from(queryParamsObject.entries()) : [];
615+
616+
const language = "java"
617+
const framework = "quarkus"
618+
619+
return (
620+
<QueryParamsVariables
621+
language={language}
622+
framework={framework}
623+
queryParams={queryParamsArray}
624+
/>
625+
)
626+
}
566627
```
567628

568629

@@ -603,7 +664,14 @@ const postExecutionCode = "# Post-register operations"
603664
const customMethodConfig = { returnType: "int", openingTag: "{", closingTag: "}", indentSize: 2};
604665

605666
return (
606-
<RegisterErrorHandler language={language} methodName={methodName} methodParams={methodParams} preExecutionCode={preExecutionCode} postExecutionCode={postExecutionCode} customMethodConfig={customMethodConfig} />
667+
<RegisterErrorHandler
668+
language={language}
669+
methodName={methodName}
670+
methodParams={methodParams}
671+
preExecutionCode={preExecutionCode}
672+
postExecutionCode={postExecutionCode}
673+
customMethodConfig={customMethodConfig}
674+
/>
607675
)
608676
```
609677

@@ -643,7 +711,13 @@ const preExecutionCode = "# Pre-register operations"
643711
const postExecutionCode = "# Post-register operations"
644712

645713
return (
646-
<RegisterMessageHandler language={language} methodName={methodName} methodParams={methodParams} preExecutionCode={preExecutionCode} postExecutionCode={postExecutionCode} />
714+
<RegisterMessageHandler
715+
language={language}
716+
methodName={methodName}
717+
methodParams={methodParams}
718+
preExecutionCode={preExecutionCode}
719+
postExecutionCode={postExecutionCode}
720+
/>
647721
)
648722
```
649723

@@ -673,20 +747,26 @@ Generates both static and instance methods for sending messages through WebSocke
673747
import path from "path";
674748
import { Parser, fromFile } from "@asyncapi/parser";
675749

676-
const parser = new Parser();
677-
const asyncapi_v3_path = path.resolve(__dirname, '../__fixtures__/asyncapi-v3.yml');
678-
679-
// Parse the AsyncAPI document (async operation)
680-
const parseResult = await fromFile(parser, asyncapi_v3_path).parse();
681-
const parsedAsyncAPIDocument = parseResult.document;
682-
683-
const language = "javascript"
684-
const clientName = "AccountServiceAPI"
685-
const sendOperations = parsedAsyncAPIDocument.operations().filterBySend()
686-
687-
return (
688-
<SendOperations language={language} clientName={clientName} sendOperations={sendOperations} />
689-
)
750+
async function renderSendOperations(){
751+
const parser = new Parser();
752+
const asyncapi_v3_path = path.resolve(__dirname, '../__fixtures__/asyncapi-v3.yml');
753+
754+
// Parse the AsyncAPI document
755+
const parseResult = await fromFile(parser, asyncapi_v3_path).parse();
756+
const parsedAsyncAPIDocument = parseResult.document;
757+
758+
const language = "javascript"
759+
const clientName = "AccountServiceAPI"
760+
const sendOperations = parsedAsyncAPIDocument.operations().filterBySend()
761+
762+
return (
763+
<SendOperations
764+
language={language}
765+
clientName={clientName}
766+
sendOperations={sendOperations}
767+
/>
768+
)
769+
}
690770
```
691771

692772

packages/components/src/components/CloseConnection.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@ print('WebSocket connection closed.');`
8080
* const indent = 2
8181
*
8282
* return (
83-
* <CloseConnection language={language} framework={framework} methodName={methodName} methodParams={methodParams} preExecutionCode={preExecutionCode} postExecutionCode={postExecutionCode} indent={indent} />
83+
* <CloseConnection
84+
* language={language}
85+
* framework={framework}
86+
* methodName={methodName}
87+
* methodParams={methodParams}
88+
* preExecutionCode={preExecutionCode}
89+
* postExecutionCode={postExecutionCode}
90+
* indent={indent}
91+
* />
8492
* );
8593
*
8694
*/

packages/components/src/components/Connect.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ Future<void> connect() async {
103103
* const title = "HoppscotchEchoWebSocketClient"
104104
*
105105
* return(
106-
* <Connect language={language} title={title} />
106+
* <Connect
107+
* language={language}
108+
* title={title}
109+
* />
107110
* )
108111
*/
109112
export function Connect({ language, title }) {

packages/components/src/components/DependencyProvider.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ function resolveDependencies(language, framework = '', role = '') {
111111
* const additionalDependencies = ["import java.util.concurrent.CompletableFuture;", "import java.time.Duration;"]
112112
*
113113
* return (
114-
* <DependencyProvider language={language} framework={framework} role={role} additionalDependencies={additionalDependencies} />
114+
* <DependencyProvider
115+
* language={language}
116+
* framework={framework}
117+
* role={role}
118+
* additionalDependencies={additionalDependencies}
119+
* />
115120
* )
116121
*/
117122
export function DependencyProvider({ language, framework = '', role = '', additionalDependencies = [] }) {

packages/components/src/components/FileHeaderInfo.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,23 @@ const commentConfig = {
3232
* import path from "path";
3333
* import { Parser, fromFile } from "@asyncapi/parser";
3434
*
35-
* const parser = new Parser();
36-
* const asyncapi_websocket_query = path.resolve(__dirname, "../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml");
37-
* const language = "javascript"
38-
*
39-
* // Parse the AsyncAPI document (async operation)
40-
* const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
41-
* const parsedAsyncAPIDocument = parseResult.document;
42-
*
43-
* return (
44-
* <FileHeaderInfo info={parsedAsyncAPIDocument.info()} server={parsedAsyncAPIDocument.servers().get("withPathname")} language={language} />
45-
* )
35+
* async function renderFileHeader() {
36+
* const parser = new Parser();
37+
* const asyncapi_websocket_query = path.resolve(__dirname, "../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml");
38+
* const language = "javascript"
39+
*
40+
* // Parse the AsyncAPI document
41+
* const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
42+
* const parsedAsyncAPIDocument = parseResult.document;
43+
*
44+
* return (
45+
* <FileHeaderInfo
46+
* info={parsedAsyncAPIDocument.info()}
47+
* server={parsedAsyncAPIDocument.servers().get("withPathname")}
48+
* language={language}
49+
* />
50+
* )
51+
* }
4652
*/
4753
export function FileHeaderInfo({ info, server, language }) {
4854
const { commentChar, lineStyle } = commentConfig[language] || {

packages/components/src/components/HandleMessage.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ else:
5252
* }
5353
* };
5454
* return (
55-
* <HandleMessage language={language} methodName={methodName} methodParams={methodParams} preExecutionCode={preExecutionCode} postExecutionCode={postExecutionCode} customMethodConfig={customMethodConfig} />
55+
* <HandleMessage
56+
* language={language}
57+
* methodName={methodName}
58+
* methodParams={methodParams}
59+
* preExecutionCode={preExecutionCode}
60+
* postExecutionCode={postExecutionCode}
61+
* customMethodConfig={customMethodConfig}
62+
* />
5663
* )
5764
*
5865
*/

0 commit comments

Comments
 (0)