Skip to content

Commit 0142c2e

Browse files
committed
add jsdocs for readme components
1 parent 23f1e29 commit 0142c2e

File tree

10 files changed

+606
-4
lines changed

10 files changed

+606
-4
lines changed

packages/components/docs/API.md

Lines changed: 401 additions & 1 deletion
Large diffs are not rendered by default.

packages/components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"lint": "eslint --max-warnings 0 --config ../../.eslintrc --ignore-path ../../.eslintignore .",
1111
"lint:fix": "eslint --max-warnings 0 --config ../../.eslintrc --ignore-path ../../.eslintignore . --fix",
1212
"generate:assets": "npm run prepublishOnly && npm run docs",
13-
"docs": "jsdoc2md --helper \"jsdoc2md-helpers/jsdoc-helper.js\" --template \"jsdoc2md-handlebars/api.hbs\" \"./lib/**/*.js\" > docs/API.md"
13+
"docs": "jsdoc2md --helper \"jsdoc2md-helpers/jsdoc-helper.js\" --template \"jsdoc2md-handlebars/api.hbs\" \"./lib/**/*.js\" \"./lib/**/readme/*.js\" > docs/API.md"
1414
},
1515
"files": [
1616
"lib/**",

packages/components/src/components/readme/AvailableOperations.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@ import { Text } from '@asyncapi/generator-react-sdk';
22
import OperationHeader from './OperationHeader';
33
import MessageExamples from './MessageExamples';
44

5+
/**
6+
* Renders a list of AsyncAPI operations with their headers and message examples.
7+
* @param {Object} props - Component Props
8+
* @param {object} props.operations - Array of AsyncAPI Operation objects.
9+
* @returns {JSX.Element} A Component containing rendered operations, or null if no operations are provided
10+
*
11+
* @example
12+
* import path from "path";
13+
* import { Parser, fromFile } from "@asyncapi/parser";
14+
*
15+
* async function renderAvailableOperations(){
16+
* const parser = new Parser();
17+
* const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
18+
*
19+
* //parse the AsyncAPI document
20+
* const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
21+
* const parsedAsyncAPIDocument = parseResult.document;
22+
*
23+
* return (
24+
* <AvailableOperations operations={parsedAsyncAPIDocument.operations().all()} />
25+
* )
26+
* }
27+
*/
28+
529
export function AvailableOperations({ operations }) {
630
if (!operations || operations.length === 0) {
731
return null;

packages/components/src/components/readme/CoreMethods.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ const methodConfig = {
1111
},
1212
};
1313

14+
/**
15+
* Renders a list of core WebSocket client methods for a given target language.
16+
* @param {Object} props - Component props
17+
* @param {string} props.language - Target language used to select method names.
18+
* @returns {JSX.Element} A Text Component that contains a list of core client methods.
19+
*
20+
* @example
21+
* const language = "javascript";
22+
* return (
23+
* <CoreMethods language={language} />
24+
* )
25+
*/
26+
1427
export function CoreMethods({ language }) {
1528
const config = methodConfig[language];
1629
const { msgHandler, errHandler } = config;

packages/components/src/components/readme/Installation.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ const installCommands = {
55
javascript: 'npm install',
66
};
77

8+
/**
9+
* Renders the Installation Command for a given language.
10+
* @param {Object} props - Component Props
11+
* @param {string} props.language - The programming language for which to generate Installation Command.
12+
* @returns {JSX.Element} A Text Component that contains Installation Command.
13+
*
14+
* @example
15+
* const language = "javascript";
16+
* return (
17+
* <Installation language={language} />
18+
* )
19+
*/
20+
821
export function Installation({ language }) {
922
const command = installCommands[language];
1023
return (

packages/components/src/components/readme/MessageExamples.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,35 @@ client.${opId}(${JSON.stringify(payload, null, 2)})
3535
\`\`\`
3636
`;
3737
}
38+
/**
39+
* Renders Message Examples of a given AsyncAPI operation.
40+
*
41+
* @param {Object} props - Component Props
42+
* @param {object} props.operation - An AsyncAPI Operation object.
43+
* @returns {JSX.Element} A Text Component that contains message examples.
44+
*
45+
* @example
46+
* import path from "path";
47+
* import { Parser, fromFile } from "@asyncapi/parser";
48+
*
49+
* async function renderMessageExamples(){
50+
* const parser = new Parser();
51+
* const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
52+
*
53+
* //parse the AsyncAPI document
54+
* const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
55+
* const parsedAsyncAPIDocument = parseResult.document;
56+
* const operations = parsedAsyncAPIDocument.operations().all();
57+
*
58+
* operations.map((operation) => {
59+
* return (
60+
* <MessageExamples operation={operation} />
61+
* )
62+
* })
63+
* }
64+
*/
3865

39-
export default function MessageExamples({ operation }) {
66+
export function MessageExamples({ operation }) {
4067
const operationId = operation.id();
4168
const messages = getOperationMessages(operation) || [];
4269

packages/components/src/components/readme/OperationHeader.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
import { Text } from '@asyncapi/generator-react-sdk';
22

3-
export default function OperationHeader({ operation }) {
3+
/**
4+
* Renders a header section for a single AsyncAPI operation.
5+
* @param {Object} props - Component properties.
6+
* @param {object} props.operation - An AsyncAPI Operation object.
7+
* @returns {JSX.Element} A Text Component that contains formatted operation header.
8+
*
9+
* @example
10+
* import path from "path";
11+
* import { Parser, fromFile } from "@asyncapi/parser";
12+
*
13+
* async function renderOperationHeader(){
14+
* const parser = new Parser();
15+
* const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
16+
*
17+
* //parse the AsyncAPI document
18+
* const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
19+
* const parsedAsyncAPIDocument = parseResult.document;
20+
* const operations = parsedAsyncAPIDocument.operations().all();
21+
*
22+
* operations.map((operation) => {
23+
* return (
24+
* <OperationHeader operation={operation} />
25+
* )
26+
* }
27+
* }
28+
*
29+
*/
30+
31+
export function OperationHeader({ operation }) {
432
const operationId = operation.id();
533
const summary = operation.hasSummary() ? operation.summary() : '';
634
const description = operation.hasDescription() ? `\n${operation.description()}` : '';

packages/components/src/components/readme/Overview.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
11
import { Text } from '@asyncapi/generator-react-sdk';
22

3+
/**
4+
* Renders an overview section for a WebSocket client.
5+
* Displays the API description, version, and server URL.
6+
*
7+
* @param {Object} props - Component props
8+
* @param {object} props.info - Info object from the AsyncAPI document.
9+
* @param {string} props.title - Title from the AsyncAPI document.
10+
* @param {string} props.serverUrl - ServerUrl from a specific server from the AsyncAPI document.
11+
* @returns {JSX.Element} A Text Component that contains the Overview of a Websocket client.
12+
*
13+
* @example
14+
*
15+
* import path from "path";
16+
* import { Parser, fromFile } from "@asyncapi/parser";
17+
* import { getServer, getServerUrl } from '@asyncapi/generator-helpers';
18+
*
19+
* async function renderOverview(){
20+
* const parser = new Parser();
21+
* const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
22+
*
23+
* //parse the AsyncAPI document
24+
* const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
25+
* const parsedAsyncAPIDocument = parseResult.document;
26+
*
27+
* const info = parsedAsyncAPIDocument.info();
28+
* const title = info.title();
29+
* const server = getServer(parsedAsyncAPIDocument.servers(), 'withoutPathName');
30+
* const serverUrl = getServerUrl(server);
31+
*
32+
* return (
33+
* <Overview info={info} title={title} serverUrl={serverUrl} />
34+
* )
35+
* }
36+
*
37+
*/
38+
339
export function Overview({ info, title, serverUrl }) {
440
return (
541
<Text newLines={2}>

packages/components/src/components/readme/Readme.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,44 @@ import { Usage } from './Usage';
66
import { CoreMethods } from './CoreMethods';
77
import { AvailableOperations } from './AvailableOperations';
88

9+
/**
10+
* Renders a README.md file for a given AsyncAPI document.
11+
*
12+
* Composes multiple sections (overview, installation, usage, core methods,
13+
* and available operations) into a single File component based on the
14+
* provided AsyncAPI document, generator parameters, and target language.
15+
* @param {Object} props - Component props
16+
* @param {string} props.asyncapi - Parsed AsyncAPI document instance.
17+
* @param {object} props.params - Generator parameters used to customize output
18+
* @param {string} props.language - Target language used to render language-specific sections.
19+
* @returns {JSX.Element} A File component representing the generated README.md.
20+
*
21+
* @example
22+
* import path from "path";
23+
* import { Parser, fromFile } from "@asyncapi/parser";
24+
* import { buildParams } from '@asyncapi/generator-helpers';
25+
* async function renderReadme(){
26+
* const parser = new Parser();
27+
* const asyncapi_websocket_query = path.resolve(__dirname, '../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml');
28+
*
29+
* // parse the AsyncAPI document
30+
* const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
31+
* const parsedAsyncAPIDocument = parseResult.document;
32+
* const language = "javascript";
33+
* const config = { clientFileName: 'myClient.js' };
34+
* const params = buildParams('javascript', config, 'echoServer');
35+
*
36+
* return (
37+
* <Readme
38+
* asyncapi={parsedAsyncAPIDocument}
39+
* params={params}
40+
* language={language}
41+
* />
42+
* )
43+
* }
44+
*
45+
*/
46+
947
export function Readme({ asyncapi, params, language }) {
1048
const server = getServer(asyncapi.servers(), params.server);
1149
const info = getInfo(asyncapi);

packages/components/src/components/readme/Usage.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@ main();
3030
`,
3131
};
3232

33+
/**
34+
* Renders a usage example snippet for a generated client in a given language.
35+
* @param {Object} props - Component props
36+
* @param {string} props.clientName - The Exported name of the client.
37+
* @param {string} props.clientFileName - The file name where the client is defined.
38+
* @param {string} props.language - The target language for which to render the usage snippet
39+
* @returns {JSX.Element} A Text component containing a formatted usage example snippet.
40+
*
41+
* @example
42+
* const clientName = "MyClient";
43+
* const clientFileName = "myClient.js";
44+
* const language = "javascript";
45+
*
46+
* return (
47+
* <Usage
48+
* clientName={clientName}
49+
* clientFileName={clientFileName}
50+
* language={language}
51+
* />
52+
* )
53+
*
54+
*
55+
*/
3356
export function Usage({ clientName, clientFileName, language }) {
3457
const snippetFn = usageConfig[language];
3558
const snippet = snippetFn(clientName, clientFileName);

0 commit comments

Comments
 (0)