Skip to content

Commit 38bf474

Browse files
authored
Fix resource validation (#129)
1 parent ac1069a commit 38bf474

2 files changed

Lines changed: 26 additions & 24 deletions

File tree

package-lock.json

Lines changed: 14 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/infrastructure/application/validation/actions/createResourceOptionsValidator.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
ContentDefinition,
77
RootDefinition,
88
} from '@croct/content-model/definition/definition';
9-
import type {Content, PrimitiveValue} from '@croct/content-model/content/content';
9+
import type {Content, ListItem, PrimitiveValue} from '@croct/content-model/content/content';
1010
import type {JsonValue} from '@croct/json';
1111
import type {CreateResourceOptions} from '@/application/template/action/createResourceAction';
1212
import type {
@@ -215,13 +215,19 @@ const structureContentSchema = z.strictObject({
215215
attributes: z.record(z.string(), z.lazy((): ZodType<Content> => contentSchema)),
216216
}) satisfies ZodType<Content<'structure'>>;
217217

218+
const labeledItemSchema: ZodType<ListItem<Content>> = z.lazy(
219+
() => z.discriminatedUnion('type', [
220+
textContentSchema.extend({label: z.string().optional()}),
221+
numberContentSchema.extend({label: z.string().optional()}),
222+
booleanContentSchema.extend({label: z.string().optional()}),
223+
structureContentSchema.extend({label: z.string().optional()}),
224+
listContentSchema.extend({label: z.string().optional()}),
225+
]),
226+
);
227+
218228
const listContentSchema = z.strictObject({
219229
type: z.literal('list'),
220-
items: z.array(z.lazy(
221-
(): ZodType<Content> => z.intersection(contentSchema, z.object({
222-
label: z.string().optional(),
223-
})),
224-
)),
230+
items: z.array(labeledItemSchema),
225231
}) satisfies ZodType<Content<'list'>>;
226232

227233
const contentSchema = z.discriminatedUnion('type', [

0 commit comments

Comments
 (0)