Skip to content

fix(ruby): autoload models so a client loads in any order, and generate idiomatic Ruby - #8301

Merged
Vincent Biret (baywet) merged 25 commits into
microsoft:mainfrom
andreaTP:fix/ruby-autoload-barrels
Sep 29, 2026
Merged

Vincent Biret (baywet) merged 25 commits into
microsoft:mainfrom
andreaTP:fix/ruby-autoload-barrels

Conversation

@andreaTP

Copy link
Copy Markdown
Contributor

Ruby barrels and models required each other, so loading depended on require order. Barrels now register models with autoload, as Stripe's Ruby SDK does, and a type no barrel can autoload is required directly.

On clients generated by current main, this fixes:

  • GitHub: require "api_client" fails. The IT hid it with an exclusion, now removed.
  • Meraki: 1,315 referenced constants never load.
  • Graph: requiring models/entity raises NameError.
  • A dotted --namespace-name cannot be loaded. The IT hid it with a bridge file, now deleted.

The output now follows RuboCop defaults (29 more cops enforced), ruby -w drops from 36,548 warnings to 2 on Stripe, empty barrel files are gone, and enums are frozen (fixes microsoft/kiota-ruby#68). Public names are unchanged. Models load on first use, so require the client or a barrel rather than a single model file; eager_load! loads them all.

New tests: a three-level inheritance description for every language (its Ruby spec fails on main), Ruby discriminator and query parameter specs, and a check that every referenced constant resolves.

Covers item 1 of #7956. Will be rebased on #8256 once it merges.

…of require order

- barrels register their models and enums with autoload instead of requiring them
- files require a namespace's barrel, never a model file it registers nor their own barrel
- a type no barrel autoloads is required directly, from its own or a parent namespace too
- barrels write ::File so a model named File cannot shadow it
- remove the unused AddInheritedAndMethodTypesImports
- the Ruby IT resolves every registered constant, since a bad registration now fails on first use
- stop linting comment annotations, since API descriptions can start with "Note:"
…-segment namespace

- remove the IT bridge file that was hiding the misplaced barrel
- stabby lambdas and {} instead of lambda blocks and Hash.new
- no trailing comma on the last hash entry, and super or {} for models with no fields of their own
- one include per line, in the order that keeps method lookup unchanged
- spaces around parameter defaults, and no redundant self on the request generator call
- track in the language writer whether a block has just opened, so no blank line starts a class body
- a blank line after guard clauses, and modifier if/unless for one-statement conditionals
- composed-type factories with nothing to assign return the new instance directly
Copilot AI balanced review requested due to automatic review settings September 29, 2026 10:20
@andreaTP
Andrea Peruffo (andreaTP) requested a review from a team as a code owner September 29, 2026 10:20

This comment was marked as outdated.

- the Ruby IT checks that no autoload is left pending after eager_load!
Copilot AI review requested due to automatic review settings September 29, 2026 12:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The autoloading and formatting changes are internally consistent and covered by focused unit and integration tests.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@baywet
Vincent Biret (baywet) added this pull request to the merge queue Sep 29, 2026
Merged via the queue into microsoft:main with commit 8841838 Sep 29, 2026
330 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

generation - ruby enum definitions should be frozen

3 participants