From 2d9d622e504c55556a271d742da6225b382a739b Mon Sep 17 00:00:00 2001 From: Diego Torres Date: Mon, 24 Jun 2024 16:23:28 +0200 Subject: [PATCH 1/2] Add useChannelAddressAsIdentifier configuration --- docs/configuration/config-modification.md | 3 +++ library/src/config/config.ts | 1 + library/src/containers/Sidebar/Sidebar.tsx | 2 +- .../Sidebar/__tests__/SideBar.test.tsx | 24 +++++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/configuration/config-modification.md b/docs/configuration/config-modification.md index 633260303..8ec1ec26e 100644 --- a/docs/configuration/config-modification.md +++ b/docs/configuration/config-modification.md @@ -26,6 +26,7 @@ interface ConfigInterface { sidebar?: { showServers?: 'byDefault' | 'bySpecTags' | 'byServersTags'; showOperations?: 'byDefault' | 'bySpecTags' | 'byOperationsTags'; + useChannelAddressAsIdentifier?: boolean; }, parserOptions?: ParserOptions; publishLabel?: string; @@ -52,6 +53,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` uses the channel address or operation summary in the sidebar instead of the operationId, for both AsyncAPI v2 and v3 documents. + The default behaviour is to do this only for v2 documents. - **expand?: Partial** diff --git a/library/src/config/config.ts b/library/src/config/config.ts index 0218996eb..e0f42165a 100644 --- a/library/src/config/config.ts +++ b/library/src/config/config.ts @@ -30,4 +30,5 @@ export interface ExpandConfig { export interface SideBarConfig { showServers?: 'byDefault' | 'bySpecTags' | 'byServersTags'; showOperations?: 'byDefault' | 'bySpecTags' | 'byOperationsTags'; + useChannelAddressAsIdentifier?: boolean; } diff --git a/library/src/containers/Sidebar/Sidebar.tsx b/library/src/containers/Sidebar/Sidebar.tsx index a722eea3a..6e1eeaefc 100644 --- a/library/src/containers/Sidebar/Sidebar.tsx +++ b/library/src/containers/Sidebar/Sidebar.tsx @@ -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() ?? ''; diff --git a/library/src/containers/Sidebar/__tests__/SideBar.test.tsx b/library/src/containers/Sidebar/__tests__/SideBar.test.tsx index f98d53b22..4701a0006 100644 --- a/library/src/containers/Sidebar/__tests__/SideBar.test.tsx +++ b/library/src/containers/Sidebar/__tests__/SideBar.test.tsx @@ -103,4 +103,28 @@ describe('Sidebar component', () => { , ); }); + test('should render with useChannelAddressAsIdentifier: true', () => { + const { container } = render( + + + + + , + ); + 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], + ); + } + }); }); From 0fe2269e5eeb8e19a28e4ea1fef99b883fbc6bbf Mon Sep 17 00:00:00 2001 From: Diego Torres Date: Tue, 16 Jul 2024 10:27:33 +0200 Subject: [PATCH 2/2] Reword documentation --- docs/configuration/config-modification.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/configuration/config-modification.md b/docs/configuration/config-modification.md index e57a6db97..3eb36a4cc 100644 --- a/docs/configuration/config-modification.md +++ b/docs/configuration/config-modification.md @@ -57,8 +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` uses the channel address or operation summary in the sidebar instead of the operationId, for both AsyncAPI v2 and v3 documents. - The default behaviour is to do this only for v2 documents. + `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**