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
Title
typearrays (OpenAPI 3.1 / JSON Schema nullable syntax) generateunknowninstead of the correct TS typeSummary
When an OpenAPI 3.1 schema expresses nullability using the JSON Schema 2020-12 array form —
type: [string, "null"]— instead of the OpenAPI 3.0nullable: truekeyword, the generated TypeScript client types the field asunknowninstead ofstring | null.Reproduction
openapi.yaml(OpenAPI 3.1.0):Generate a frontend TS client:
Actual generated type:
Expected:
As a workaround, rewriting the schema with the OpenAPI 3.0-style keyword produces the correct type:
Root cause (pointer, not a fix)
getType()inlib/get-type.js(massimo-cli) branches ontypeDef.typevia strict string checks —typeDef.type === 'array',typeDef.type === 'object', and aswitch (type)insideJSONSchemaToTsType().All of these assume
typeis a single string. Whentypeis an array (valid per OpenAPI 3.1 / JSON Schema 2020-12), none of the checks match, so generation falls through theswitchdefault and returns'unknown'.This likely affects not just plain string/null fields but any property whose
typeis expressed as an array — including["object", "null"]and["array", "null"]— since those are checked earlier ingetType, beforeJSONSchemaToTsTypeis 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