Skip to content

Conversation

@farnabaz
Copy link
Member

@farnabaz farnabaz commented Sep 5, 2025

πŸ”— Linked issue

#3482: Credits for Zod v4 to JSON Schema implantation to @MuntasirSZN
resolves #3462

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Nuxt Content does not depend purely on Zod v3, and users will be able to use Zod v4 or their favorite validators. For now, the module supports Zod 3, Zod 4, and Valibot as a starting point, with support for additional validators planned in the future.

These changes are seamless for current users, and you should not face any breaking changes with this update.

Zod v4

import { defineContentConfig, defineCollection, property } from '@nuxt/content'
import { z } from 'zod/v4'

const pages = defineCollection({
  type: 'page',
  source: 'blog/*.md',
  schema: z.object({
    image: z.object({
      src: property(z.string()).editor({ input: 'media' }),
      alt: z.string(),
    })
  }),
})

Valibot

import { defineContentConfig, defineCollection, property } from '@nuxt/content'
import * as v from 'valibot'

const pages = defineCollection({
  type: 'page',
  source: 'blog/*.md',
  schema: v.object({
    image: v.object({
      src: property(v.string()).editor({ input: 'media' }),
      alt: v.string(),
    })
  }),
})

Syntax

To support multiple validators and remove unused dependencies, it is recommended to use the new syntax for importing Zod and setting editor({}) options. These are only suggestions for now, but in future patch releases they will be marked as deprecated and later removed in the next major version.

  • import { z } from '@nuxt/content' will be deprecated in favor of direct imports such as:

    import { z } from 'zod/v3'
- import { defineContentConfig, defineCollection, z } from '@nuxt/content'
+ import { defineContentConfig, defineCollection } from '@nuxt/content'
+ import { z } from 'zod/v3'

export default defineContentConfig({
  collections: {
    posts: defineCollection({
      type: 'page',
      source: 'blog/*.md',
      schema: z.object({
        category: z.enum(['studio', 'content']).optional(),
        date: z.date()
      }),
    }),
  },
})
  • z.string().editor({ input: 'media' }) will be deprecated in favor of the new syntax:

    property(z.string()).editor({ input: 'media' })
- import { defineContentConfig, defineCollection, z } from '@nuxt/content'
+ import { defineContentConfig, defineCollection, property } from '@nuxt/content'
+ import { z } from 'zod/v3'

export default defineContentConfig({
  collections: {
    posts: defineCollection({
      type: 'page',
      source: 'blog/*.md',
      schema: z.object({
        image: z.object({
-           src: z.string().editor({ input: 'media' }),
+           src: property(z.string()).editor({ input: 'media' }),
          alt: z.string(),
        })
      }),
    }),
  },
})

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel
Copy link

vercel bot commented Sep 5, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
content-docs Ready Ready Preview Sep 10, 2025 7:53am

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Sep 5, 2025

Deploying content with Β Cloudflare Pages Β Cloudflare Pages

Latest commit: 3b45047
Status:Β βœ…Β  Deploy successful!
Preview URL: https://1d51acee.content-f0q.pages.dev
Branch Preview URL: https://feat-standard-schema.content-f0q.pages.dev

View logs

@pkg-pr-new
Copy link

pkg-pr-new bot commented Sep 5, 2025

npm i https://pkg.pr.new/@nuxt/content@3524

commit: 3b45047

@miguelrk
Copy link

miguelrk commented Sep 8, 2025

This is awesome. I just tested this via pkg.pr.new and can confirm it resolves #3462. Can we get this reviews/merged? πŸ™πŸΌ

@MuntasirSZN
Copy link

@farnabaz what would the validators @nuxt/content would support? Arktype, typebox, typia?

@farnabaz
Copy link
Member Author

farnabaz commented Sep 9, 2025

@farnabaz what would the validators @nuxt/content would support? Arktype, typebox, typia?

Module can support any validator which satisfy Standard Schema and can convert to JSON Schema.

My concern is mostly about the removing the bound between Nuxt Content and one specific validator. With help of community we can integrate other validators if needed.

@farnabaz farnabaz merged commit 46a1004 into main Sep 10, 2025
6 checks passed
@farnabaz farnabaz deleted the feat/standard-schema branch September 10, 2025 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot start nuxt: Cannot read properties of undefined (reading 'id')

4 participants