Skip to content

Commit

Permalink
fix route path
Browse files Browse the repository at this point in the history
  • Loading branch information
kainpets committed Jul 5, 2024
1 parent 51942f1 commit 8358674
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/lib/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@ const createRoute = (
path: string,
pathItem: Record<string, unknown>,
): Route => {
const pathParts = path.split('/')
const routePath = `/${pathParts.slice(1, -1).join('/')}`

return {
path,
namespace: { path: path.split('/').slice(0, 2).join('/') },
path: routePath,
namespace: { path: `/${pathParts[1]}` },
endpoints: createEndpoints(path, pathItem),
subroutes: [],
}
Expand All @@ -174,12 +177,15 @@ const createEndpoint = (
operation: Record<string, unknown>,
path: string,
): Endpoint => {
const pathParts = path.split('/')
const endpointPath = `/${pathParts.slice(1, -1).join('/')}`

return {
name:
'operationId' in operation && typeof operation['operationId'] === 'string'
? operation['operationId']
: `${path.replace(/\//g, '')}${method.charAt(0).toUpperCase() + method.slice(1).toLowerCase()}`,
path: `/${path.split('/').slice(1, -1).join('/')}`,
path: endpointPath,
description:
'description' in operation && typeof operation['description'] === 'string'
? operation['description']
Expand Down
2 changes: 1 addition & 1 deletion test/snapshots/blueprint.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Generated by [AVA](https://avajs.dev).
namespace: {
path: '/foos',
},
path: '/foos/get',
path: '/foos',
subroutes: [],
},
],
Expand Down
Binary file modified test/snapshots/blueprint.test.ts.snap
Binary file not shown.
2 changes: 1 addition & 1 deletion test/snapshots/seam-blueprint.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Generated by [AVA](https://avajs.dev).
namespace: {
path: '/acs',
},
path: '/acs/systems/list',
path: '/acs/systems',
subroutes: [],
},
],
Expand Down
Binary file modified test/snapshots/seam-blueprint.test.ts.snap
Binary file not shown.

0 comments on commit 8358674

Please sign in to comment.