Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add configuration to use channel addresses in the sidebar for AsyncAPI v3 #1022

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/configuration/config-modification.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface ConfigInterface {
sidebar?: {
showServers?: 'byDefault' | 'bySpecTags' | 'byServersTags';
showOperations?: 'byDefault' | 'bySpecTags' | 'byOperationsTags';
useChannelAddressAsIdentifier?: boolean;
},
parserOptions?: ParserOptions;
publishLabel?: string;
Expand Down Expand Up @@ -56,6 +57,8 @@ interface ConfigInterface {
This field contains configuration responsible for the way of working of the sidebar.
`showServers` field is set to `byDefault` by default.
`showOperations` field is set to `byDefault` by default.
`useChannelAddressAsIdentifier`: for AsyncAPI v3 documents, use the operation summary or channel address in the sidebar instead of the operationId.
By default, this behavior is applied only to AsyncAPI v2 documents.

- **expand?: Partial<ExpandConfig>**

Expand Down
1 change: 1 addition & 0 deletions library/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export interface ExpandConfig {
export interface SideBarConfig {
showServers?: 'byDefault' | 'bySpecTags' | 'byServersTags';
showOperations?: 'byDefault' | 'bySpecTags' | 'byOperationsTags';
useChannelAddressAsIdentifier?: boolean;
}
2 changes: 1 addition & 1 deletion library/src/containers/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ const OperationsList: React.FunctionComponent = () => {
numeric: true,
});
let label = '';
if (version === 0) {
if (version === 0 || sidebarConfig?.useChannelAddressAsIdentifier) {
// old version uses different labels for the operations
const operationChannels = operationChannel.all();
const channelAddress = operationChannels[0]?.address() ?? '';
Expand Down
24 changes: 24 additions & 0 deletions library/src/containers/Sidebar/__tests__/SideBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,28 @@ describe('Sidebar component', () => {
</ConfigContext.Provider>,
);
});
test('should render with useChannelAddressAsIdentifier: true', () => {
const { container } = render(
<ConfigContext.Provider
value={{ sidebar: { useChannelAddressAsIdentifier: true } }}
>
<SpecificationContext.Provider value={parsed}>
<Sidebar />
</SpecificationContext.Provider>
</ConfigContext.Provider>,
);
const operations = container.querySelectorAll('a[href^="#operation-"]');
const expectedOperationDescriptions = [
'Inform about environmental lighting conditions of a particular streetlight.', // because the channel has a summary
'smartylighting.streetlights.1.0.action.{streetlightId}.turn.on',
'smartylighting.streetlights.1.0.action.{streetlightId}.turn.off',
'smartylighting.streetlights.1.0.action.{streetlightId}.dim',
];
for (let i = 0; i < operations.length; i++) {
// eslint-disable-next-line jest/no-standalone-expect
expect(operations[i].querySelectorAll('span')[1].textContent).toBe(
expectedOperationDescriptions[i],
);
}
});
});
Loading