Skip to content

Write to output, rather than below it - #16

Closed
Jack97 wants to merge 2 commits into
masterfrom
output-is-exact-path
Closed

Jack97 wants to merge 2 commits into
masterfrom
output-is-exact-path

Conversation

@Jack97

@Jack97 Jack97 commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator
output: app/lib/api/v3/generated   # where the tree goes
modules: [Api, V3, Generated]      # what it declares

output used to be a root the namespace was appended to, so the tree landed at output/<modules as a path>. That inferred a file layout from a namespace, which only works if output is an autoload root — and it forced the generated tree into a directory of its own, since the generator claimed everything under output.

Now output is the directory, modules is only the namespace, and whether the two line up for Zeitwerk is the caller's call. The generated tree can sit beside the hand-written code implementing it.

The generator owns output and the .rb beside it naming the namespace — Zeitwerk wants Api::V3::Generated in generated.rb, not inside generated/. Nothing else in the parent is touched, which is what lets the tree live inside an existing root.

module_path stays for Rails routing, where to: takes a constant path rather than a file path.

Golden output is byte-identical: the fixtures point output at the directory the old convention produced.

196 examples, 0 failures; rubocop and srb tc clean.

`when`, `else` and `end` sat one column right of `case`, which is what
`Layout/CaseIndentation` and `Layout/EndAlignment` reject. The rest of the
document's Ruby already agrees with the cops.
`output` was a root that the namespace was appended to, so a tree declaring
`Api::V3::Generated` landed in `output/api/v3/generated`. Inferring a file
layout from a namespace only holds where `output` is an autoload root, and it
forced the tree into a directory of its own, because the generator claimed
everything under `output` and nothing hand-written could share it.

`output` is now the directory itself and `modules` only says what the code
declares. Whether the two agree, so Zeitwerk resolves the constants, is the
caller's to arrange, which is what lets the tree sit beside the code that
implements it.

What the generator owns shrinks to match: `output`, and the `.rb` beside it
that names the namespace, because Zeitwerk looks for `Api::V3::Generated` in
`generated.rb` rather than inside `generated/`. The rest of the parent
directory is not its business.

`module_path` survives for Rails routing, where `to:` wants a constant path and
not a file path. Golden output is byte-identical, since the fixtures now point
`output` at the directory the old convention derived.
@Jack97

Jack97 commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator Author

Parking this. The change forces the namespace file outside output, and none of the three ways to resolve that landed: owning a sibling file, a generated global on Registry, or moving the binding onto controller_base. The branch keeps the work; nexus-api ships on app/openapi_kit/api/generated/v3, which needs no release.

@Jack97 Jack97 closed this Sep 14, 2026
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.

1 participant