From 864ca245973c0aa6f792cb8430dc68258f8dc0ef Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 19 Nov 2025 10:45:21 -0500 Subject: [PATCH] Handle nullable array items. Openapi represents an array of nullable items using an allOf with exactly one reference entry (items.allOf[0].$ref), rather than the usual items.$ref. We currently treat these types as any, which means users have to cast or marshal and unmarshal data to the correct type. This patch adds a check for this edge case and replaces the any with the appropriate concrete type. Part of #340. --- internal/generate/utils.go | 16 ++++++++++++++++ oxide/types.go | 8 ++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/internal/generate/utils.go b/internal/generate/utils.go index 6befa5e..8285fa8 100644 --- a/internal/generate/utils.go +++ b/internal/generate/utils.go @@ -144,6 +144,22 @@ func convertToValidGoType(property, typeName string, r *openapi3.SchemaRef) stri } func schemaValueToGoType(schemaValue *openapi3.Schema, property string) string { + // In the special case of an array of nullable items, we represent the + // item type with an allOf of length 1. In this case, return the schema + // of the 0th entry in anyOf. + if len(schemaValue.AllOf) == 1 { + value := schemaValue.AllOf[0] + reference := getReferenceSchema(value) + if reference == "" { + fmt.Printf("[WARN] TODO: handle allOf %+v for %q, marking as any for now\n", value, property) + return "any" + } + if schemaValue.Nullable { + reference = fmt.Sprintf("*%s", reference) + } + return reference + } + if schemaValue.Type == nil { fmt.Printf("[WARN] TODO: handle nil type for %q, marking as any for now\n", property) return "any" diff --git a/oxide/types.go b/oxide/types.go index 6acce68..4bc1a62 100644 --- a/oxide/types.go +++ b/oxide/types.go @@ -7175,8 +7175,8 @@ type ValueArrayString struct { // - Type // - Values type ValueArrayIntegerDistribution struct { - Type ValueArrayType `json:"type" yaml:"type"` - Values []any `json:"values" yaml:"values"` + Type ValueArrayType `json:"type" yaml:"type"` + Values []Distributionint64 `json:"values" yaml:"values"` } // ValueArrayDoubleDistribution is the type definition for a ValueArrayDoubleDistribution. @@ -7185,8 +7185,8 @@ type ValueArrayIntegerDistribution struct { // - Type // - Values type ValueArrayDoubleDistribution struct { - Type ValueArrayType `json:"type" yaml:"type"` - Values []any `json:"values" yaml:"values"` + Type ValueArrayType `json:"type" yaml:"type"` + Values []Distributiondouble `json:"values" yaml:"values"` } // ValueArray is list of data values for one timeseries.