Skip to content

anyOf in parameters is not well supported #2090

Description

@kwent
"/v1/resource/{id}": {
  "parameters": [
    {
      "name": "id",
      "in": "path",
      "schema": {
        "anyOf": [
          {
            "type": "string",
            "format": "uuid",
            "description": "Resource UUID"
          },
          {
            "type": "string",
            "pattern": "^[a-z0-9_-]+$",
            "description": "Resource slug"
          }
        ]
      },
      "required": true
    }
  ],
...
acme/client.gen.go:27357:6: Id0 redeclared in this block
        acme/client.gen.go:27351:6: other declaration of Id0
acme/client.gen.go:27360:6: Id1 redeclared in this block
        acme/client.gen.go:27354:6: other declaration of Id1
acme/client.gen.go:27363:6: Id0 redeclared in this block
        acme/client.gen.go:27351:6: other declaration of Id0
acme/client.gen.go:27366:6: Id1 redeclared in this block
        acme/client.gen.go:27354:6: other declaration of Id1
acme/client.gen.go:27374:6: Id0 redeclared in this block
        acme/client.gen.go:27351:6: other declaration of Id0
acme/client.gen.go:27377:6: Id1 redeclared in this block
        acme/client.gen.go:27354:6: other declaration of Id1
acme/client.gen.go:27380:6: Id0 redeclared in this block
        acme/client.gen.go:27351:6: other declaration of Id0
acme/client.gen.go:27383:6: Id1 redeclared in this block
        acme/client.gen.go:27354:6: other declaration of Id1
acme/client.gen.go:27386:6: Id0 redeclared in this block
        acme/client.gen.go:27351:6: other declaration of Id0
acme/client.gen.go:27389:6: Id1 redeclared in this block
        acme/client.gen.go:27354:6: other declaration of Id1
acme/client.gen.go:27389:6: too many errors

Activity

  1. mromaszewicz commented on Jul 13, 2026

    @mromaszewicz
    Member

    I can't fix this automatically, but I can detect that a collision will happen when we validate the spec before code generation.

    Two path level based parameters with the same name id, will conflict with each other, since they create global types. The codegen will now error out with a message recommending to use a spec overlay or x-go-type-name or simply to rename one of the parameters out of conflict. x-go-type-name preserves the name on the wire, but the name on the wire doesn't matter very much for the path parameters, since it's never referenced by name, just by position. There are some bugs related around this that I'm fixing to make it a little more robust, but I can't make a general fix without some major upheaval in the generated code that will break a lot of users.

    After my fix, it will work if you only have a single path level parameter named id in your spec.

    If you have lots of paths referencing an id parameter, it's better to put it under #/components/schemas/parameters.

  2. added 2 commits that reference this issue on Jul 13, 2026
    ea399ff
    bce67cf
  3. added a commit that references this issue on Jul 13, 2026
    a07731d
  4. mromaszewicz commented on Jul 17, 2026

    @mromaszewicz
    Member

    This is hard to fix.

    I am reverting the PR above as part of my fix.

    When two different paths hoist parameters to named types to add functions onto them, they can collide within a single pathItem, and across multiple pathItems, so the global parameters must be decorated with some kind of prefix or suffix.

    The only thing which differentiates them from each other is the path itself. So, what I'm going to do is detect potential collisions across params globally, and if there are collisions, they're going to get suffixed with a few characters of the hash of the path. This makes them stable with respect to paths. i considered ordinal numbering, which is unstable, and also turning the path into a word, but I'd argue this is uglier than the hash suffix.

  5. added a commit that references this issue on Jul 17, 2026
    4f69fd3
  6. added a commit that references this issue on Jul 17, 2026
    bd52535
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