[object Object]

← back to Cli Printing Press

fix(openapi): handle nullable types in OpenAPI 3.1 specs

33d0648398ed31a6c082976cd47b636d4a67b411 · 2026-03-23 18:51:50 -0700 · Matt Van Horn

Use schema.Type.Includes() instead of .Is() to correctly map nullable
types like ["boolean", "null"] and ["integer", "null"] from OpenAPI 3.1
specs. Previously these fell through to "string" because Is() requires
exactly one type element.

Fixes: --tts string -> --tts (bool), --flags string -> --flags int

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Files touched

Diff

commit 33d0648398ed31a6c082976cd47b636d4a67b411
Author: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Date:   Mon Mar 23 18:51:50 2026 -0700

    fix(openapi): handle nullable types in OpenAPI 3.1 specs
    
    Use schema.Type.Includes() instead of .Is() to correctly map nullable
    types like ["boolean", "null"] and ["integer", "null"] from OpenAPI 3.1
    specs. Previously these fell through to "string" because Is() requires
    exactly one type element.
    
    Fixes: --tts string -> --tts (bool), --flags string -> --flags int
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---
 internal/openapi/parser.go | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/internal/openapi/parser.go b/internal/openapi/parser.go
index 1feabffc..b126f1e0 100644
--- a/internal/openapi/parser.go
+++ b/internal/openapi/parser.go
@@ -812,15 +812,16 @@ func mapSchemaType(schema *openapi3.Schema) string {
 	if schema == nil || schema.Type == nil {
 		return "string"
 	}
+	// Use Includes instead of Is to handle nullable types like ["boolean", "null"]
 	switch {
-	case schema.Type.Is(openapi3.TypeString):
-		return "string"
-	case schema.Type.Is(openapi3.TypeInteger):
-		return "int"
-	case schema.Type.Is(openapi3.TypeBoolean):
+	case schema.Type.Includes(openapi3.TypeBoolean):
 		return "bool"
-	case schema.Type.Is(openapi3.TypeNumber):
+	case schema.Type.Includes(openapi3.TypeInteger):
+		return "int"
+	case schema.Type.Includes(openapi3.TypeNumber):
 		return "float"
+	case schema.Type.Includes(openapi3.TypeString):
+		return "string"
 	default:
 		return "string"
 	}
@@ -860,7 +861,7 @@ func isArraySchema(schema *openapi3.Schema) bool {
 	if schema == nil {
 		return false
 	}
-	if schema.Type != nil && schema.Type.Is(openapi3.TypeArray) {
+	if schema.Type != nil && schema.Type.Includes(openapi3.TypeArray) {
 		return true
 	}
 	return schema.Items != nil
@@ -870,7 +871,7 @@ func isObjectSchema(schema *openapi3.Schema) bool {
 	if schema == nil {
 		return false
 	}
-	if schema.Type != nil && schema.Type.Is(openapi3.TypeObject) {
+	if schema.Type != nil && schema.Type.Includes(openapi3.TypeObject) {
 		return true
 	}
 	return len(schema.Properties) > 0 || len(schema.AllOf) > 0

← 2915ae3e fix(generator): auth mapping for Discord BotToken scheme  ·  back to Cli Printing Press  ·  feat(generator): auto-generate usage examples in command hel e993ba6e →