Skip to content

Commit d123d46

Browse files
mostafagao-sun
andauthored
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 <gao@silverhand.io>
1 parent dfa0135 commit d123d46

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

packages/core/src/routes/swagger/utils/parameters.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,16 @@ export const buildPathIdParameters = (
256256
* Build a parameter object with additional parameters that are not inferred from the path.
257257
*/
258258
export const customParameters = (): Record<string, OpenAPIV3.ParameterObject> => {
259+
const entityId = 'tenantId';
260+
const shared = Object.freeze({
261+
in: 'path',
262+
description: 'The unique identifier of the tenant.',
263+
required: true,
264+
schema: { type: 'string' },
265+
} as const);
266+
259267
return Object.freeze({
260-
tenantId: {
261-
name: 'tenantId',
262-
in: 'path',
263-
description: 'The unique identifier of the tenant.',
264-
required: true,
265-
schema: {
266-
type: 'string',
267-
},
268-
},
268+
[`${entityId}-root`]: { name: 'id', ...shared },
269+
[entityId]: { name: 'tenantId', ...shared },
269270
});
270271
};

packages/core/src/utils/zod.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ export const zodTypeToSwagger = (
207207
if (config instanceof ZodObject) {
208208
// Type from Zod is any
209209
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
210-
const entries = Object.entries(config.shape)
211-
// `tenantId` is not editable for all routes
212-
.filter(([key]) => key !== 'tenantId');
210+
const entries = Object.entries(config.shape);
213211
const required = entries
214212
.filter(([, value]) => !(value instanceof ZodOptional))
215213
.map(([key]) => key);

0 commit comments

Comments
 (0)