Skip to content

Label a union whose variants share a type once - #63

Merged
glenn-jocher merged 2 commits into
mainfrom
dedupe-union-labels
Nov 30, 2026
Merged

glenn-jocher merged 2 commits into
mainfrom
dedupe-union-labels

Conversation

@glenn-jocher

@glenn-jocher glenn-jocher commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

schemaLabel joins the label of every oneOf/anyOf variant, so a union whose variants share a type but differ in their values renders the type once per variant. A field that accepts either of two string enums is labeled string | string, and a request body with three object variants is labeled object | object | object. The repeated type tells the reader nothing, and the values are already listed separately by schemaConstraints.

This flattens nested unions into one list of distinct types, and puts a union inside an array in parentheses so the array reads correctly:

Union Before After
Two string enums string | string string
Three numeric enums number | number | number number
Two object variants and a ref UpdateModelResponse | object | object UpdateModelResponse | object
A nullable string inside a string union string | null | string string | null
An integer, or an array of integers or strings integer | integer | string[] | null integer | (integer | string)[] | null

A few lines in schemaLabel, plus three assertions beside the existing label tests. The labels are display-only: the API reference and other docs consumers render them, and no generator reads them for types.

Testing

  • bun test: 21 pass, including the new assertions (two string enums → string; nullable string inside a union → string | null; integer or array of integer-or-string → integer | (integer | string)[]).
  • On a real-world spec with 22 distinct union labels, none repeats a type after this change.
  • bun run typecheck and bun run lint pass.

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Updated schemaLabel to display distinct union types once and parenthesize union types inside arrays.

📊 Key Changes

  • Flattens oneOf and anyOf labels and removes duplicate type labels, so variants like two string enums display as string.
  • Preserves distinct labels such as string | null when nullable and non-nullable variants are combined.
  • Wraps array item unions in parentheses, so an array of integers or strings displays as (integer | string)[].
  • Added assertions covering duplicate labels, nullable unions, and arrays of unions.

🎯 Purpose & Impact

  • API reference labels are clearer for unions with repeated types; the change affects display labels, not generated types.

@UltralyticsAssistant UltralyticsAssistant added the bug Something isn't working label Nov 30, 2026

@UltralyticsAssistant UltralyticsAssistant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 PR Review

Made with ❤️ by Ultralytics Actions

LGTM. The change deduplicates identical union labels while preserving their first-seen order; enum constraints remain available separately. No concrete behavioral regression found.

@glenn-jocher
glenn-jocher merged commit 2e42474 into main Nov 30, 2026
7 checks passed
@glenn-jocher
glenn-jocher deleted the dedupe-union-labels branch November 30, 2026 21:01
@UltralyticsAssistant

Copy link
Copy Markdown
Member

🎉 The PR was merged! Thanks, @glenn-jocher, for improving API reference labels by removing duplicate union types, preserving nullable variants, and clearly parenthesizing unions inside arrays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants