Skip to content

Fields with Multiple Types #861

@joshuamcginnis

Description

@joshuamcginnis

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.2.1

Plugin version

9.4.0

Node.js version

22.9.0

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

Unknown

Description

This was previously reported in #190 but was marked as stale and closed. I'd like to reopen it.

Basically, the issue is if you make a field that has multiple types, e.g.:

 "collectionName": {
  "type": ["null", "string"]
}

You get "Unknown Type: null,string"

Image

I think this has something to do with the underlying swagger implementation using OpenAPI 3.0+ which introduced nullable: true for defining nullable types.

In my case, I'm actually using zod-to-json-schema which outputs the schema (by default) in jsonSchema7 format.

Link to code that reproduces the bug

#190

Expected Behavior

json schema types with multiple values, including nulls, should generate the correct swagger docs.

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