Skip to content

compilers/openapi: an inline union branch's name hint depends on declaration order #181

Description

@OmarAlJarrah

An inline oneOf/anyOf branch whose pointer an outside $ref also names takes its
Naming.Hint from whichever lowering interns the node first. The union lowering derives
variant_<index>; hoistSubSchema, reached through the outside $ref, derives the pointer's
last segment. Both are valid hints and nothing compares them, so the same components compiled in
two declaration orders produce two different documents — silently.

openapi: 3.1.0
info: {title: t, version: "1"}
paths: {}
components:
  schemas:
    Host:
      oneOf:
        - {type: integer, description: d}
        - type: string
    Outside: {$ref: '#/components/schemas/Host/oneOf/0'}

Compiled with Host declared first, t/anon/components/schemas/Host/oneOf/0 is hinted
variant_0; with Outside first, 0. cmp.Diff over the two registries shows only that field.

Why this is filed on its own

The $ref-branch half of the same mechanism is closed: a branch that is a $ref carrying
siblings now derives its hint from the $ref target on both paths, so both agree whichever
arrives first, and TestComposition_BranchAliasIsOrderIndependent pins it for allOf, oneOf
and anyOf.

An inline branch has no target to name, so the two lowerings genuinely hold different
information: the union knows the branch's ordinal within the union, and hoistSubSchema knows
only the pointer it was handed. Closing this means deciding which spelling names the node and
teaching the other path to produce it — a naming decision, not an agreement fix.

Method

Compiled both orders through openapi.New().Compile(...) and diffed Document.Types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions