Skip to content

type arrays (OpenAPI 3.1 / JSON Schema nullable syntax) generate unknown instead of the correct TS type #170

Description

@Akallabet

Title

type arrays (OpenAPI 3.1 / JSON Schema nullable syntax) generate unknown instead of the correct TS type

Summary

When an OpenAPI 3.1 schema expresses nullability using the JSON Schema 2020-12 array form — type: [string, "null"] — instead of the OpenAPI 3.0 nullable: true keyword, the generated TypeScript client types the field as unknown instead of string | null.

Reproduction

openapi.yaml (OpenAPI 3.1.0):

openapi: 3.1.0
...
components:
  schemas:
    Transaction:
      type: object
      properties:
        description:
          type: [string, "null"]
          maxLength: 255
      required: [id]

Generate a frontend TS client:

massimo openapi.yaml --frontend --language ts --name generated-client --folder src/generated-client

Actual generated type:

export type Transaction = { ...; 'description'?: unknown; ... }

Expected:

export type Transaction = { ...; 'description'?: string | null; ... }

As a workaround, rewriting the schema with the OpenAPI 3.0-style keyword produces the correct type:

description:
  type: string
  nullable: true
'description'?: string | null   // correct

Root cause (pointer, not a fix)

getType() in lib/get-type.js (massimo-cli) branches on typeDef.type via strict string checks — typeDef.type === 'array', typeDef.type === 'object', and a switch (type) inside JSONSchemaToTsType().
All of these assume type is a single string. When type is an array (valid per OpenAPI 3.1 / JSON Schema 2020-12), none of the checks match, so generation falls through the switch default and returns 'unknown'.

This likely affects not just plain string/null fields but any property whose type is expressed as an array — including ["object", "null"] and ["array", "null"] — since those are checked earlier in getType, before JSONSchemaToTsType is ever reached.

Happy to send a PR for this if a fix direction is agreed on — just wanted to raise the bug first.

Environment

  • massimo / massimo-cli: 1.3.0
  • OpenAPI version in spec: 3.1.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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