diff --git a/pkg/dashboard/frontend/cypress/e2e/architecture.cy.ts b/pkg/dashboard/frontend/cypress/e2e/architecture.cy.ts index f8bac20f..4ab7c63b 100644 --- a/pkg/dashboard/frontend/cypress/e2e/architecture.cy.ts +++ b/pkg/dashboard/frontend/cypress/e2e/architecture.cy.ts @@ -39,18 +39,18 @@ describe('Architecture Spec', () => { it('should have correct routes drawer content', () => { const expected = [ [ - 'edge-label-e-first-api-allmethodsget-services/my-test-service.ts', + 'edge-label-e-first-api-services/my-test-service.ts', 'DELETE/all-methodsGET/all-methodsOPTIONS/all-methodsPATCH/all-methodsPOST/all-methodsPUT/all-methodsGET/header-testPOST/json-testGET/path-test/{name}GET/query-testGET/schedule-countGET/topic-count', ], [ - 'edge-label-e-second-api-imagefrombucketget-services/my-test-service.ts', + 'edge-label-e-second-api-services/my-test-service.ts', 'GET/content-type-binaryGET/content-type-cssGET/content-type-htmlGET/content-type-imageGET/content-type-xmlDELETE/image-from-bucketGET/image-from-bucketPUT/image-from-bucketPUT/very-nested-files', ], [ - 'edge-label-e-my-secret-api-setbinarypost-services/my-test-secret.ts', + 'edge-label-e-my-secret-api-services/my-test-secret.ts', 'GET/getPOST/setPOST/set-binary', ], - ['edge-label-e-my-db-api-getget-services/my-test-db.ts', 'GET/get'], + ['edge-label-e-my-db-api-services/my-test-db.ts', 'GET/get'], ] expected.forEach(([edge, routes]) => { diff --git a/pkg/dashboard/frontend/src/lib/utils/generate-architecture-data.ts b/pkg/dashboard/frontend/src/lib/utils/generate-architecture-data.ts index 85eaeac4..e91a50b5 100644 --- a/pkg/dashboard/frontend/src/lib/utils/generate-architecture-data.ts +++ b/pkg/dashboard/frontend/src/lib/utils/generate-architecture-data.ts @@ -224,14 +224,16 @@ export function generateArchitectureData(data: WebSocketResponse): { resource: api, icon: GlobeAltIcon, address: apiAddress, - description: `${routes.length} ${ - routes.length === 1 ? 'Route' : 'Routes' + description: `${allEndpoints.length} ${ + allEndpoints.length === 1 ? 'Route' : 'Routes' }`, endpoints: allEndpoints, }) const specEntries = (api.spec && api.spec.paths) || [] + const uniqueMap = new Map() + Object.entries(specEntries).forEach(([path, operations]) => { AllHttpMethods.forEach((m) => { const method = operations && (operations[m] as any) @@ -242,12 +244,20 @@ export function generateArchitectureData(data: WebSocketResponse): { const target = method['x-nitric-target']['name'] + // we only need one api edge per service target + if (uniqueMap.has(target)) { + return + } + + // mark the target as unique + uniqueMap.set(target, target) + const endpoints = allEndpoints.filter( (endpoint) => endpoint.requestingService === target, ) edges.push({ - id: `e-${api.name}-${method.operationId}-${target}`, + id: `e-${api.name}-${target}`, source: node.id, target, animated: true,