Skip to content

Commit b7b3a7d

Browse files
authored
feat: add support for AsyncAPI 2 and 3 in the split command (#2552)
1 parent ab560ef commit b7b3a7d

File tree

14 files changed

+939
-30
lines changed

14 files changed

+939
-30
lines changed

.changeset/breezy-cougars-tie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@redocly/cli": minor
3+
---
4+
5+
Added support for AsyncAPI v2 and v3 in the split command.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"asyncapi": "2.6.0",
3+
"info": {
4+
"title": "Test AsyncAPI 2",
5+
"version": "1.0.0"
6+
},
7+
"channels": {
8+
"user/signedup": {
9+
"subscribe": {
10+
"message": {
11+
"payload": {
12+
"type": "object",
13+
"properties": {
14+
"userId": { "type": "string" }
15+
}
16+
}
17+
}
18+
}
19+
}
20+
},
21+
"components": {
22+
"schemas": {
23+
"UserSignedUp": {
24+
"type": "object",
25+
"properties": {
26+
"userId": { "type": "string" }
27+
}
28+
}
29+
},
30+
"messages": {
31+
"UserSignedUpMessage": {
32+
"payload": {
33+
"$ref": "#/components/schemas/UserSignedUp"
34+
}
35+
}
36+
}
37+
}
38+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"asyncapi": "3.0.0",
3+
"info": {
4+
"title": "Test AsyncAPI 3",
5+
"version": "1.0.0"
6+
},
7+
"channels": {
8+
"userSignedUp": {
9+
"address": "user/signedup",
10+
"messages": {
11+
"UserSignedUpMessage": {
12+
"$ref": "#/components/messages/UserSignedUpMessage"
13+
}
14+
}
15+
}
16+
},
17+
"operations": {
18+
"UserSignedUp": {
19+
"action": "send",
20+
"channel": {
21+
"$ref": "#/channels/userSignedUp"
22+
}
23+
}
24+
},
25+
"components": {
26+
"schemas": {
27+
"UserSignedUp": {
28+
"type": "object",
29+
"properties": {
30+
"userId": { "type": "string" }
31+
}
32+
}
33+
},
34+
"messages": {
35+
"UserSignedUpMessage": {
36+
"payload": {
37+
"$ref": "#/components/schemas/UserSignedUp"
38+
}
39+
}
40+
}
41+
}
42+
}

packages/cli/src/commands/split/__tests__/index.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,54 @@ describe('split', () => {
176176

177177
expect(utils.escapeLanguageName).toBeCalledTimes(3);
178178
});
179+
180+
it('should split an AsyncAPI 2 file and show the success message', async () => {
181+
const filePath = 'packages/cli/src/commands/split/__tests__/fixtures/asyncapi2.json';
182+
183+
vi.spyOn(process.stderr, 'write').mockImplementation(() => true);
184+
185+
await handleSplit({
186+
argv: {
187+
api: filePath,
188+
outDir: openapiDir,
189+
separator: '_',
190+
},
191+
config: configFixture,
192+
version: 'cli-version',
193+
});
194+
195+
expect(vi.mocked(process.stderr.write)).toBeCalledTimes(2);
196+
expect(vi.mocked(process.stderr.write).mock.calls[0][0]).toBe(
197+
`🪓 Document: ${blue(filePath!)} ${green('is successfully split')}
198+
and all related files are saved to the directory: ${blue(openapiDir)} \n`
199+
);
200+
expect(vi.mocked(process.stderr.write).mock.calls[1][0]).toContain(
201+
`${filePath}: split processed in <test>ms`
202+
);
203+
});
204+
205+
it('should split an AsyncAPI 3 file and show the success message', async () => {
206+
const filePath = 'packages/cli/src/commands/split/__tests__/fixtures/asyncapi3.json';
207+
208+
vi.spyOn(process.stderr, 'write').mockImplementation(() => true);
209+
210+
await handleSplit({
211+
argv: {
212+
api: filePath,
213+
outDir: openapiDir,
214+
separator: '_',
215+
},
216+
config: configFixture,
217+
version: 'cli-version',
218+
});
219+
220+
expect(vi.mocked(process.stderr.write)).toBeCalledTimes(2);
221+
expect(vi.mocked(process.stderr.write).mock.calls[0][0]).toBe(
222+
`🪓 Document: ${blue(filePath!)} ${green('is successfully split')}
223+
and all related files are saved to the directory: ${blue(openapiDir)} \n`
224+
);
225+
expect(vi.mocked(process.stderr.write).mock.calls[1][0]).toContain(
226+
`${filePath}: split processed in <test>ms`
227+
);
228+
});
179229
});

0 commit comments

Comments
 (0)