OpenAPI 3.1 allows type to be a list, so a value may be any one of several types. Generation fails on any schema that uses one.
Spec:
openapi: 3.1.0
info:
title: multi-type union
version: "1.0.0"
paths: {}
components:
schemas:
Event:
type: object
additionalProperties:
type: [string, number, boolean]
Config:
package: example
output: example.gen.go
generate:
models: true
output-options:
skip-prune: true
Error:
error generating code: error collecting component types: error generating Go types for component schemas: error converting Schema Event to Go type: error generating type for additional properties: error resolving primitive type: unhandled Schema type: &[string number boolean]
The position doesn't matter. additionalProperties is just where it happens to land here. A union in a property, parameter, body, or array items fails the same way, because the primitive-type dispatch in pkg/codegen/schema.go uses Types.Is(...), which only matches a single-element type list.
Expected: type Event map[string]any. Go has no type meaning "one of these", so any is the same permissive mapping a bare type: "null" got in #2430.
This comes up in real specs. Honeycomb's published 3.1 spec has two of these for genuinely polymorphic event and query-result values, and the only workaround today is an overlay that deletes the type keyword before generation.
oapi-codegen version: current main (6768b63)
Go version: 1.26.5
I have a fix ready and will open a PR shortly.
OpenAPI 3.1 allows
typeto be a list, so a value may be any one of several types. Generation fails on any schema that uses one.Spec:
Config:
Error:
The position doesn't matter.
additionalPropertiesis just where it happens to land here. A union in a property, parameter, body, or array items fails the same way, because the primitive-type dispatch inpkg/codegen/schema.gousesTypes.Is(...), which only matches a single-elementtypelist.Expected:
type Event map[string]any. Go has no type meaning "one of these", soanyis the same permissive mapping a baretype: "null"got in #2430.This comes up in real specs. Honeycomb's published 3.1 spec has two of these for genuinely polymorphic event and query-result values, and the only workaround today is an overlay that deletes the
typekeyword before generation.oapi-codegenversion: currentmain(6768b63)Go version: 1.26.5
I have a fix ready and will open a PR shortly.