feat: change simple enum to zod native enums

Signed-off-by: Elaine Mattos <elaine.mattos@gmail.com>
This commit is contained in:
Elaine Mattos
2023-12-25 18:32:27 +01:00
parent e61ed0901c
commit 2a3360a77f
2 changed files with 8 additions and 29 deletions
@@ -48,8 +48,7 @@ export const examples: TemplateExample[] = [
...commonGitlabConfigExample,
projectId: 12,
title: 'Test Issue',
assignees: `
- 18 `,
assignees: [18],
description: 'This is the description of the issue',
createdAt: '2022-09-27 18:00:00.000',
dueDate: '2022-09-28 12:00:00.000',
@@ -70,9 +69,7 @@ export const examples: TemplateExample[] = [
...commonGitlabConfigExample,
projectId: 12,
title: 'Test Issue',
assignees: `
- 18
- 15 `,
assignees: [18, 15],
description: 'This is the description of the issue',
confidential: false,
createdAt: '2022-09-27 18:00:00.000',
@@ -23,11 +23,11 @@ import { z } from 'zod';
import { checkEpicScope, convertDate, getClient, parseRepoUrl } from '../util';
import { Gitlab, CreateIssueOptions, IssueSchema } from '@gitbeaker/rest';
const enumIssueType = {
ISSUE: 'issue',
INCIDENT: 'incident',
TEST: 'test_case',
};
enum IssueType {
ISSUE = 'issue',
INCIDENT = 'incident',
TEST = 'test_case',
}
const issueInputProperties = z.object({
projectId: z.number().describe('Project Id'),
@@ -67,27 +67,9 @@ const issueInputProperties = z.object({
.optional(),
labels: z.string({ description: 'Labels to apply' }).optional(),
issueType: z
.string({
.nativeEnum(IssueType, {
description: 'Type of the issue',
})
.refine(issueType => {
const isValid = Object.values(enumIssueType).includes(issueType);
if (!isValid) {
throw new z.ZodError([
{
code: 'invalid_enum_value',
options: Object.values(enumIssueType),
path: ['issueType'],
message: `Invalid value for 'issueType'. Must be one of: ${Object.values(
enumIssueType,
).join(', ')}`,
received: issueType,
},
]);
}
return isValid;
})
.default(enumIssueType.ISSUE)
.optional(),
mergeRequestToResolveDiscussionsOf: z
.number({