feat: add support for AsyncAPI 2 and 3 in the split command#2552
feat: add support for AsyncAPI 2 and 3 in the split command#2552tibisabau wants to merge 8 commits intoRedocly:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 3205cd1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
e9121a4 to
8875719
Compare
|
@tibisabau |
Co-authored-by: Dmytro Anansky <dmytro@redocly.com>
| } | ||
| } | ||
|
|
||
| function removeAsyncApiEmptyComponents( |
There was a problem hiding this comment.
Maybe this one can be simplified:
function removeAsyncApiEmptyComponents(
asyncapi: AnyAsyncApiDefinition,
componentType: AsyncApi2Component | AsyncApi3Component
) {
const components = (asyncapi as any).components;
if (!components) return;
if (isEmptyObject(components[componentType])) {
delete components[componentType];
}
if (isEmptyObject(components)) {
delete (asyncapi as any).components;
}
}
| function findAsyncApiComponentTypes(components: any, specVersion: 'async2' | 'async3') { | ||
| const componentNames = | ||
| specVersion === 'async2' ? ASYNCAPI2_COMPONENT_NAMES : ASYNCAPI3_COMPONENT_NAMES; | ||
| const excluded = new Set([ |
There was a problem hiding this comment.
Why do you need this exclude?
Will it make sense to remove items you want to exclude from this place
https://github.com/Redocly/redocly-cli/pull/2552/changes#diff-8200bdf7c09b5fccef9dca77890af1ed6ec7bd1332d08aeef1c1d846e296f18dR79
and check if they are in components?
| return parseYaml(fs.readFileSync(fileName, 'utf8')) as Definition; | ||
| } catch (e) { | ||
| return exitWithError(e.message); | ||
| function detectSpecType(definition: Definition): 'openapi' | 'asyncapi' | null { |
There was a problem hiding this comment.
Do we need this detectSpecType function.
Maybe we can just use already detected spec version and build switch case logic, similar to this example
const specVersion = detectSpec(definition)
switch (specVersion) {
case 'async2':
....
break;
case 'async3':
....
break;
case 'oas2':
case 'oas3_0':
case 'oas3_1':
case 'oas3_2':
....
break;
default:
....
}
|
@tibisabau |
What/Why/How?
What: Added support for AsyncAPI 2.x and 3.x specifications to the
splitcommand, which previously only supported OpenAPI 3.x.Why: To enable users to split AsyncAPI definition files into modular directory structures, similar to the existing OpenAPI functionality. This addresses issue #2352.
How:
splitAsyncApiDefinition()orchestrator function to handle both AsyncAPI versionsiterateAsyncApiChannels()to split channels into separate files with proper $ref replacementsiterateAsyncApiOperations()for AsyncAPI 3 operations splittingiterateAsyncApiComponents()to handle component extraction with version-specific logicvalidateDefinitionFileName()to recognize AsyncAPI documentsReference
Resolves #2352
Testing
tests/e2e/split/asyncapi2-basic/asyncapi.yamlandtests/e2e/split/asyncapi3-basic/asyncapi.yamlScreenshots (optional)
N/A - CLI functionality
Check yourself
Security