Skip to content

Multi-type unions aren't handled for OpenAPI 3.1 #2521

Closed

Description

@bendrucker

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.

Activity

  1. mromaszewicz commented on Aug 16, 2026

    @mromaszewicz
    Member

    For the parameter-position gap found in the review of #2522 (a union param binds into an any destination, which the runtime rejects on every request), we've filed oapi-codegen/runtime#153 with the minimal runtime change: a Types []string field on the bind options, consulted only for interface destinations, walked in specificity order with JSON-grammar numeric detection. The codegen side (emitting Types, fixing SchemaType()'s first-entry behavior) will be tracked here once the runtime shape settles.

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