diff --git a/packages/schema/src/api-key/index.ts b/packages/schema/src/api-key/index.ts index 02dcfd73..88fdb179 100644 --- a/packages/schema/src/api-key/index.ts +++ b/packages/schema/src/api-key/index.ts @@ -14,10 +14,9 @@ export const ApiKeySchema = z.object({ userId: z.string() }) -export const CreateApiKeyRequestSchema = z.object({ +export const CreateApiKeyRequestSchema = ApiKeySchema.partial().extend({ name: ApiKeySchema.shape.name, - expiresAfter: expiresAfterEnum.optional(), - authorities: ApiKeySchema.shape.authorities.optional() + expiresAfter: expiresAfterEnum.optional() }) export const CreateApiKeyResponseSchema = ApiKeySchema diff --git a/packages/schema/tests/api-key.spec.ts b/packages/schema/tests/api-key.spec.ts index b5baa8f9..f77b31f7 100644 --- a/packages/schema/tests/api-key.spec.ts +++ b/packages/schema/tests/api-key.spec.ts @@ -58,6 +58,17 @@ describe('API Key Schema Tests', () => { expect(result.success).toBe(true) }) + it('should validate if optional fields are specified for CreateApiKeyRequestSchema', () => { + const result = CreateApiKeyRequestSchema.safeParse({ + name: 'test', + expiresAfter: '720', + authorities: ['UPDATE_PROJECT'], + slug: 'test-slug' + }) + + expect(result.success).toBe(true) + }) + it('should not validate if invalid values are specified for CreateApiKeyRequestSchema', () => { const result = CreateApiKeyRequestSchema.safeParse({ name: 123,