Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional null field results in Zod schema syntax error #1584

Closed
quintal-william opened this issue Feb 28, 2025 · 0 comments · Fixed by #1610
Closed

Optional null field results in Zod schema syntax error #1584

quintal-william opened this issue Feb 28, 2025 · 0 comments · Fixed by #1610
Labels
bug Something isn't working

Comments

@quintal-william
Copy link

quintal-william commented Feb 28, 2025

What version of kubb is running?

3.6.1

What kind of platform do you use?

Linux

How does your kubb.config.ts config look like

import { defineConfig } from '@kubb/core'
import { pluginOas } from '@kubb/plugin-oas'
import { pluginZod } from '@kubb/plugin-zod'

export default defineConfig({
  name: 'Test',
  root: './src',
  input: {
    data: JSON.stringify({
      openapi: '3.1.0',
      components: {
        schemas: {
          TestSchema: {
            properties: {
              stringField: {
                type: 'string',
              },
              nullField: {
                type: 'null',
              },
            },
            type: 'object',
            required: [],
          },
        },
      },
    }),
  },
  output: {
    path: './__generated__',
    clean: true,
  },
  plugins: [pluginOas(), pluginZod()],
})

What version of external packages are you using(@tanstack-query, MSW, React, Vue, ...)

{
  "zod": "3.24.2",
  "react": "19.0.0",
  "typescript": "5.7.3"
}

What steps can reproduce the bug?

Given the example kubb.config.ts file, run the generator and observe the syntax error in the generated zod schema:

import { z } from "zod";

export const testSchemaSchema = z.object({
      "stringField": z.string().optional(),
  "nullField": .optional()z.null()
      })

How often does this bug happen?

Every time

What is the expected behavior?

The null field should match the behaviour of the string field

import { z } from "zod";

export const testSchemaSchema = z.object({
    "stringField": z.string().optional(),
    "nullField": z.null().optional()
})

Additional information

No response

@quintal-william quintal-william added the bug Something isn't working label Feb 28, 2025
lambdank added a commit to lambdank/kubb that referenced this issue Mar 21, 2025
@stijnvanhulle stijnvanhulle linked a pull request Mar 24, 2025 that will close this issue
stijnvanhulle added a commit that referenced this issue Mar 24, 2025
Correct order for null field - Fixes #1584
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant