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

zod-openapi - default value rendered as optional field #239

Open
up209d opened this issue Feb 20, 2025 · 0 comments
Open

zod-openapi - default value rendered as optional field #239

up209d opened this issue Feb 20, 2025 · 0 comments

Comments

@up209d
Copy link

up209d commented Feb 20, 2025

Version: @anatine/zod-openapi: 2.2.7

z.object({
  messages: z.string().array().default([]),
})

The infered type is

messages: string[] // Mandatory field

However, OpenAPI contract rendered as optional field

{
	"type": [
		"object"
	],
	"properties": {
		"messages": {
			"default": [],
			"type": [
				"array"
			],
			"items": {
				"type": [
					"string"
				]
			}
		}
	},
	"required": []
}

This doesn't make sense, the field should be required in openapi contract.

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

No branches or pull requests

1 participant