From d123d46ebcc2d242e3d5c6d157517bd8fd4d81bf Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Tue, 25 Jun 2024 04:24:56 +0200 Subject: [PATCH] fix: include `tenantId` and its root param in responses (#6092) * fix: include tenantId and its root param in responses * refactor: use shared object --------- Co-authored-by: Gao Sun --- .../src/routes/swagger/utils/parameters.ts | 19 ++++++++++--------- packages/core/src/utils/zod.ts | 4 +--- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/core/src/routes/swagger/utils/parameters.ts b/packages/core/src/routes/swagger/utils/parameters.ts index a3bccbc50..c7486c2ee 100644 --- a/packages/core/src/routes/swagger/utils/parameters.ts +++ b/packages/core/src/routes/swagger/utils/parameters.ts @@ -256,15 +256,16 @@ export const buildPathIdParameters = ( * Build a parameter object with additional parameters that are not inferred from the path. */ export const customParameters = (): Record => { + const entityId = 'tenantId'; + const shared = Object.freeze({ + in: 'path', + description: 'The unique identifier of the tenant.', + required: true, + schema: { type: 'string' }, + } as const); + return Object.freeze({ - tenantId: { - name: 'tenantId', - in: 'path', - description: 'The unique identifier of the tenant.', - required: true, - schema: { - type: 'string', - }, - }, + [`${entityId}-root`]: { name: 'id', ...shared }, + [entityId]: { name: 'tenantId', ...shared }, }); }; diff --git a/packages/core/src/utils/zod.ts b/packages/core/src/utils/zod.ts index d8331a037..18cbc93dc 100644 --- a/packages/core/src/utils/zod.ts +++ b/packages/core/src/utils/zod.ts @@ -207,9 +207,7 @@ export const zodTypeToSwagger = ( if (config instanceof ZodObject) { // Type from Zod is any // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - const entries = Object.entries(config.shape) - // `tenantId` is not editable for all routes - .filter(([key]) => key !== 'tenantId'); + const entries = Object.entries(config.shape); const required = entries .filter(([, value]) => !(value instanceof ZodOptional)) .map(([key]) => key);