Skip to content

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

@up209d

Description

@up209d

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.

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