Skip to content

Commit

Permalink
fix(core): do not titlize tags of .well-known APIs (#1412)
Browse files Browse the repository at this point in the history
  • Loading branch information
IceHe committed Jul 5, 2022
1 parent 6a83732 commit 5559fb1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
11 changes: 8 additions & 3 deletions packages/core/src/routes/swagger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,20 @@ describe('GET /swagger.json', () => {
});

it('should generate the tags', async () => {
const response = await mockSwaggerRequest.get('/swagger.json');
const testTagRouter = new Router();
testTagRouter.get('/mock', () => ({}));
testTagRouter.put('/.well-known', () => ({}));
const swaggerRequest = createSwaggerRequest([testTagRouter]);

const response = await swaggerRequest.get('/swagger.json');
expect(response.body.paths).toMatchObject(
expect.objectContaining({
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
'/api/mock': expect.objectContaining({
get: expect.objectContaining({ tags: ['Mock'] }),
}),
'/api/test': expect.objectContaining({
put: expect.objectContaining({ tags: ['Test'] }),
'/api/.well-known': expect.objectContaining({
put: expect.objectContaining({ tags: ['.well-known'] }),
}),
/* eslint-enable @typescript-eslint/no-unsafe-assignment */
})
Expand Down
12 changes: 11 additions & 1 deletion packages/core/src/routes/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ const buildParameters = (
}));
};

function buildTag(path: string) {
const root = path.split('/')[1];

if (root?.startsWith('.')) {
return root;
}

return toTitle(root ?? 'General');
}

const buildOperation = (stack: IMiddleware[], path: string): OpenAPIV3.OperationObject => {
const guard = stack.find((function_): function_ is WithGuardConfig<IMiddleware> =>
isGuardMiddleware(function_)
Expand All @@ -85,7 +95,7 @@ const buildOperation = (stack: IMiddleware[], path: string): OpenAPIV3.Operation
];

return {
tags: [toTitle(path.split('/')[1] ?? 'General')],
tags: [buildTag(path)],
parameters: [...pathParameters, ...queryParameters],
requestBody,
responses: {
Expand Down

0 comments on commit 5559fb1

Please sign in to comment.