From 30cd7727de4524acdbf42ef9b91d92ea725c4bde Mon Sep 17 00:00:00 2001 From: simeng-li Date: Mon, 15 May 2023 17:10:40 +0800 Subject: [PATCH] fix(schemas): remove the notnull string min-length guard from response type (#3844) remove the notnull string min-length guard from response type --- .../integration-tests/src/tests/api/application.test.ts | 5 +++++ packages/schemas/src/gen/schema.ts | 6 ------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/integration-tests/src/tests/api/application.test.ts b/packages/integration-tests/src/tests/api/application.test.ts index adb248353..ec0881da8 100644 --- a/packages/integration-tests/src/tests/api/application.test.ts +++ b/packages/integration-tests/src/tests/api/application.test.ts @@ -64,6 +64,11 @@ describe('admin console application', () => { expect(updatedAgainApplication.isAdmin).toBeFalsy(); }); + it('should get demo app application successfully', async () => { + const application = await getApplication('demo-app'); + expect(application.id).toBe('demo-app'); + }); + it('should fetch all applications created above', async () => { const applications = await getApplications(); const applicationNames = applications.map(({ name }) => name); diff --git a/packages/schemas/src/gen/schema.ts b/packages/schemas/src/gen/schema.ts index d879e2727..4c9eebd88 100644 --- a/packages/schemas/src/gen/schema.ts +++ b/packages/schemas/src/gen/schema.ts @@ -65,7 +65,6 @@ export const generateSchema = ({ name, fields }: TableWithType) => { `const guard: Guard<${modelName}> = z.object({`, ...fields.map( - // eslint-disable-next-line complexity ({ name, type, isArray, isEnum, nullable, tsType, isString, maxLength, hasDefaultValue }) => { if (tsType) { return ` ${camelcase(name)}: ${camelcase(tsType)}Guard${conditionalString( @@ -74,11 +73,6 @@ export const generateSchema = ({ name, fields }: TableWithType) => { } return ` ${camelcase(name)}: z.${isEnum ? `nativeEnum(${type})` : `${type}()`}${ - // Non-nullable strings should have a min length of 1 - conditionalString( - isString && !(nullable || hasDefaultValue || name === tenantId) && `.min(1)` - ) - }${ // String types value in DB should have a max length conditionalString(isString && maxLength && `.max(${maxLength})`) }${conditionalString(isArray && '.array()')}${conditionalString(