Skip to content

Commit

Permalink
fix: include tenantId and its root param in responses (#6092)
Browse files Browse the repository at this point in the history
* fix: include tenantId and its root param in responses

* refactor: use shared object

---------

Co-authored-by: Gao Sun <gao@silverhand.io>
  • Loading branch information
mostafa and gao-sun authored Jun 25, 2024
1 parent dfa0135 commit d123d46
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
19 changes: 10 additions & 9 deletions packages/core/src/routes/swagger/utils/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, OpenAPIV3.ParameterObject> => {
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 },
});
};
4 changes: 1 addition & 3 deletions packages/core/src/utils/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d123d46

Please sign in to comment.