Skip to content

Strong typed JSON fields don't support @default and generate invalid Zod schemas when they are a List #2039

@diesal11

Description

@diesal11

Description and expected behavior

type Foo {
    a String
}

model Bar {
    id            String    @id   @default(cuid())
    foo          Foo       @json @default("{ \"a\": \"a\" }")
    fooList    Foo[]    @json @default("[{ \"a\": \"b\" }]")
}

@default args on Typed JSON fields currently fail with the error: Value is not assignable to parameter
However as per the Prisma docs, strings are the intended method to provide default JSON values.

Unrelated to that, the generated Zod schemas for Typed JSON lists like fooList are missing z.array(...), the typescript types are correct

Environment (please complete the following information):

  • ZenStack version: 2.12.2
  • Prisma version: 6.4.x
  • Database type: Postgresql

Additional context

Raising a PR to address this shortly, just needed an issue number for the regression test :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions