GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — A oneOf/anyOf branch that is an array of an inline enum gets the same type name as its items · Issue #2640 · oapi-codegen/oapi-codegen

A oneOf/anyOf branch that is an array of an inline enum gets the same type name as its items #2640

New issue
Copy link
New issue
Copy link
Open
#2653
Open
A oneOf/anyOf branch that is an array of an inline enum gets the same type name as its items#2640
#2653
Copy link

Description

@BogdanYarotsky
BogdanYarotsky
opened on Oct 29, 2026
Issue body actions

When a union branch is an array whose items are an inline enum, the branch's type and the items' enum type get the same name (...Roles1). In a request body or a parameter, generation succeeds and the output doesn't compile. In a component schema, generation fails with "duplicate typename", and the suggested x-go-name doesn't apply, since both names are generated.

"A string or a list of strings" (oneOf: [string, array of string]) is a common shape; adding an enum to the items is enough to trigger this.

Reproduction

openapi.yaml:

openapi: 3.0.3
info: {title: t, version: "1"}
paths:
  /items:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                roles:
                  oneOf:
                    - {type: string}
                    - {type: array, items: {type: string, enum: [admin, viewer]}}
      responses:
        "204": {description: ok}
$ oapi-codegen -generate types -package api -o api.gen.go openapi.yaml
$ go build ./...
./api.gen.go:21:6: invalid recursive type: PostItemsJSONBodyRoles1 refers to itself
./api.gen.go:24:6: PostItemsJSONBodyRoles1 redeclared in this block
	./api.gen.go:21:6: other declaration of PostItemsJSONBodyRoles1

No configuration file; the module requires github.com/oapi-codegen/runtime v1.8.0. The generated code:

// PostItemsJSONBodyRoles1 defines parameters for PostItems.
type PostItemsJSONBodyRoles1 = []PostItemsJSONBodyRoles1

// PostItemsJSONBodyRoles1 defines parameters for PostItems.
type PostItemsJSONBodyRoles1 string

On main the first one is type PostItemsJSONBodyRoles1 []PostItemsJSONBodyRoles1 and only the "redeclared" error remains.

The same roles property as a query parameter's schema gives GetItemsParamsRoles1 redeclared. Under components.schemas.Item (referenced from a response) generation fails instead:

error generating code: error generating code for type definitions: duplicate typename 'ItemRoles1' detected, can't auto-rename, please use x-go-name to specify your own name for one of them

It also happens with a single-branch oneOf, with anyOf, with an enum on the string branch too, and with resolve-type-name-collisions: true. It reproduces on v2.4.1 as well. Setting x-go-type-name on the items (items: {type: string, enum: [admin, viewer], x-go-type-name: Role}) works around it.

Expected

Two distinct types, for example PostItemsJSONBodyRoles1 []PostItemsJSONBodyRoles1Item and PostItemsJSONBodyRoles1Item string, and code that compiles.

Versions

v2.8.1 and main (15f5714, v2.8.1-0.20261028140811-15f571472ff8), Go 1.27.3, linux/amd64.

Likely cause

An array's items are generated at the array's own path (generateGoSchema(ctx.at(itemHint), schema.Items, path), pkg/codegen/schema.go:1729 on main), and an inline enum is named from its path (schema.go:1693), so the items' enum takes the array's name. A plain array property never gets a type of its own, so this doesn't show there. But generateUnionElement (pkg/codegen/union.go:89) names the array branch from that same path. #1878 had a similar shape: an array with an enum of its own and an enum on its items, both called ApprovalConfigurationExclude.

Activity

  1. ahm3dwasim
    added a commit that references this issue on Nov 1, 2026

    fix: give inline-enum items of a oneOf/anyOf array branch their own t…

    This issue will close once commit 4e90274 is merged into the 'main' branch.
    4e90274
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

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.