From 0a194c675266449c388b0e70a0ee56fc1e545fa7 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Sat, 22 Jun 2024 19:19:00 +0200 Subject: [PATCH] fix: change special character to fix root paramter naming issue feat: add customParameters function for fixing tenantId error on `/api/.well-known/endpoints/{tenantId}` --- packages/core/src/routes/swagger/index.ts | 7 +++++- .../src/routes/swagger/utils/parameters.ts | 22 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/core/src/routes/swagger/index.ts b/packages/core/src/routes/swagger/index.ts index 19d8f743e..a15c38e4e 100644 --- a/packages/core/src/routes/swagger/index.ts +++ b/packages/core/src/routes/swagger/index.ts @@ -34,6 +34,7 @@ import { paginationParameters, buildPathIdParameters, mergeParameters, + customParameters, } from './utils/parameters.js'; type RouteObject = { @@ -232,7 +233,11 @@ export default function swaggerRoutes ({ ...previous, ...buildPathIdParameters(entityName) }), + (previous, entityName) => ({ + ...previous, + ...buildPathIdParameters(entityName), + ...customParameters(), + }), {} ), }, diff --git a/packages/core/src/routes/swagger/utils/parameters.ts b/packages/core/src/routes/swagger/utils/parameters.ts index 49bbd20a6..f62378069 100644 --- a/packages/core/src/routes/swagger/utils/parameters.ts +++ b/packages/core/src/routes/swagger/utils/parameters.ts @@ -91,7 +91,7 @@ export const buildParameters: BuildParameters = ( if (key === 'id') { if (rootComponent) { return { - $ref: `#/components/parameters/${pluralize(rootComponent, 1)}Id:root`, + $ref: `#/components/parameters/${pluralize(rootComponent, 1)}Id-root`, }; } @@ -241,7 +241,7 @@ export const buildPathIdParameters = ( // Need to duplicate the object because OpenAPI does not support partial reference. // See https://github.com/OAI/OpenAPI-Specification/issues/2026 return { - [`${entityId}:root`]: { + [`${entityId}-root`]: { ...shared, name: 'id', }, @@ -251,3 +251,21 @@ export const buildPathIdParameters = ( }, }; }; + +/** + * Build a parameter object for the `tenantId` parameter. + * @returns The parameter object for the `tenantId` parameter. + */ +export const customParameters = (): Record => { + return { + tenantId: { + name: 'tenantId', + in: 'path', + description: 'The unique identifier of the tenant.', + required: true, + schema: { + type: 'string', + }, + }, + }; +};