Skip to content

Commit 118937a

Browse files
committed
Merge branch 'master' into api-generation-for-components
2 parents 6d16479 + 92de9ee commit 118937a

File tree

8 files changed

+80
-14
lines changed

8 files changed

+80
-14
lines changed

Development.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ For the PR titles you can refer to [this guide](CONTRIBUTING.md?plain=1#L60)
195195
196196
If you encounter any issues during development or testing, please check the following:
197197
198-
1. Ensure you're using the correct Node.js version (18.20.8 or higher) and npm version (10.8.2 or higher).
198+
1. Ensure you're using the correct Node.js version (24.11 or higher) and npm version (11.5.1 or higher).
199199
2. Clear the `node_modules` directory and reinstall dependencies if you encounter unexpected behavior.
200200
3. For Docker-related issues, make sure Docker is running and you have sufficient permissions.
201201

apps/generator/docs/model-generation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ weight: 200
55

66
This guide will walk you through the process of enabling models/types generation in a template by using [Modelina](https://www.asyncapi.com/tools/modelina).
77

8-
Modelina is an AsyncAPI library designed for generating data models using inputs such as [AsyncAPI](generator/asyncapi-document), OpenAPI, or JSON schema inputs. Its functionality revolves around creating data models from the provided AsyncAPI document and the model template, which defines message payloads. It is better to use Modelina in your template to handle model generation rather than providing custom templates.
8+
Modelina is an AsyncAPI library designed for generating data models using inputs such as [AsyncAPI](asyncapi-document), OpenAPI, or JSON schema inputs. Its functionality revolves around creating data models from the provided AsyncAPI document and the model template, which defines message payloads. It is better to use Modelina in your template to handle model generation rather than providing custom templates.
99

1010
You can integrate the work shown in this guide into a template by following the [tutorial about creating a template](https://www.asyncapi.com/docs/tools/generator/generator-template).
1111

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { render } from '@asyncapi/generator-react-sdk';
2+
import { Usage } from '../../src/components/readme/Usage';
3+
4+
describe('Testing of Usage component', () => {
5+
const supportedCases = [
6+
{
7+
language: 'python',
8+
clientFileName: 'my_client.py',
9+
},
10+
{
11+
language: 'javascript',
12+
clientFileName: 'myClient.js',
13+
},
14+
];
15+
16+
test.each(supportedCases)(
17+
'renders usage snippet for %s',
18+
({ language, clientFileName }) => {
19+
const result = render(
20+
<Usage
21+
clientName="MyClient"
22+
clientFileName={clientFileName}
23+
language={language}
24+
/>
25+
);
26+
27+
expect(result.trim()).toMatchSnapshot();
28+
}
29+
);
30+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Testing of Usage component renders usage snippet for { language: 'javascript', clientFileName: 'myClient.js' } 1`] = `
4+
"## Usage
5+
6+
\`\`\`javascript
7+
const MyClient = require('./myClient');
8+
const wsClient = new MyClient();
9+
10+
async function main() {
11+
try {
12+
await wsClient.connect();
13+
// use wsClient to send/receive messages
14+
await wsClient.close();
15+
} catch (error) {
16+
console.error('Failed to connect:', error);
17+
}
18+
}
19+
20+
main();
21+
\`\`\`"
22+
`;
23+
24+
exports[`Testing of Usage component renders usage snippet for { language: 'python', clientFileName: 'my_client.py' } 1`] = `
25+
"## Usage
26+
27+
\`\`\`python
28+
from my_client import MyClient
29+
30+
ws_client = MyClient()
31+
32+
async def main():
33+
await ws_client.connect()
34+
# use ws_client to send/receive messages
35+
await ws_client.close()
36+
\`\`\`"
37+
`;

packages/templates/clients/websocket/java/quarkus/.ageneratorrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v3
22
parameters:
33
server:
44
description: The name of the server described in AsyncAPI document
5-
required: false
5+
required: true
66
appendClientSuffix:
77
description: Add 'Client' suffix at the end of the class name. This option has no effect if 'customClientName' is specified.
88
required: false

packages/templates/clients/websocket/javascript/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ You can test this template:
77
4. Install with `npm install` and run test with `npm run test`
88
5. Start example script that uses a client library generated by the test: `node example.js`
99

10-
> By default this is testing against Hoppscotch echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change first line to `const WSClient = require('./tests/temp/snapshotTestResult/client_postman/client.js');` and run `node example.js` again. You will see example still works but now it is using a different API. This is possible since both AsyncAPI documents define the same name of operation for sending messages: `sendEchoMessage` so each client generated has the same API.
10+
> By default this is testing against Hoppscotch echo service. You can modify `packages/templates/clients/websocket/javascript/example.js` and change first line to `const WSClient = require('./test/temp/snapshotTestResult/client_postman/client.js');` and run `node example.js` again. You will see example still works but now it is using a different API. This is possible since both AsyncAPI documents define the same name of operation for sending messages: `sendEchoMessage` so each client generated has the same API.

packages/templates/clients/websocket/test/integration-test/common-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ function runCommonTests(language, config) {
5959
await generateAndVerifyClient(config.template, outputPath, asyncapiPath, params);
6060
});
6161
});
62+
63+
describe('When required server param is missing', () => {
64+
it('should throw an error when server param is missing during client generation', async () => {
65+
const generator = new Generator(config.template, config.testResultPath, {
66+
forceWrite: true,
67+
});
68+
await expect(generator.generateFromFile(asyncapi_v3_path_hoppscotch)).rejects.toThrow('This template requires the following missing params: server');
69+
});
70+
});
6271
}
6372

6473
function runCommonSlackTests(language, config) {

packages/templates/clients/websocket/test/integration-test/integration.test.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,6 @@ describe('WebSocket Clients Integration Tests', () => {
8181
const checkClientOutputFileExists = await stat(clientOutputFile);
8282
expect(checkClientOutputFileExists.isFile()).toBeTruthy();
8383
});
84-
85-
it('should throw an error when server param is missing during simple client generation for hoppscotch echo', async () => {
86-
const generator = new Generator(config.template, config.testResultPath, {
87-
forceWrite: true,
88-
templateParams: {
89-
clientFileName: config.clientFileName
90-
}
91-
});
92-
await expect(generator.generateFromFile(asyncapi_v3_path_hoppscotch)).rejects.toThrow('This template requires the following missing params: server');
93-
});
9484
});
9585
});
9686
});

0 commit comments

Comments
 (0)