Title: fix: autoload Engine when Rails loads after openapi_ruby by mortik · Pull Request #35 · openapi-ruby/openapi-ruby · GitHub
Open Graph Title: fix: autoload Engine when Rails loads after openapi_ruby by mortik · Pull Request #35 · openapi-ruby/openapi-ruby
X Title: fix: autoload Engine when Rails loads after openapi_ruby by mortik · Pull Request #35 · openapi-ruby/openapi-ruby
Description: Summary In hybrid mode (FRAMEWORK=hybrid), the generated subprocess script requires openapi_ruby/rspec and openapi_ruby/minitest at the top — both pull in lib/openapi_ruby.rb before Rails is loaded. The eager require_relative "openapi_ruby/engine" if defined?(Rails::Engine) then no-ops, so when the first spec file later requires rails_helper and Rails boots routes, mount OpenapiRuby::Engine raises NameError: uninitialized constant OpenapiRuby::Engine. Fall back to autoload :Engine, "openapi_ruby/engine" when Rails::Engine isn't yet defined at require time. The constant resolves lazily when routes reference it, by which point Rails has booted and class Engine < ::Rails::Engine works. Normal Rails boot still hits the eager path — Bundler.require runs after rails/all, so initializer registration timing is preserved. During schema generation the engine's middleware initializer is a no-op anyway (gated on OPENAPI_RUBY_GENERATING), so missing the initializer-collection window is harmless on the deferred path. Why this only bit hybrid mode The rspec-only script doesn't pre-require openapi_ruby/rspec — the user's openapi_helper.rb controls require order (typically rails_helper first). The hybrid script forces the bad order. Minitest-only would have the same problem but the user hadn't hit it. Test plan bundle exec rspec — 299/299 pass New regression spec spawns a subprocess simulating the bad load order — confirmed it fails with the exact NameError: uninitialized constant OpenapiRuby::Engine against the unfixed code, passes with the fix. 🤖
Open Graph Description: Summary In hybrid mode (FRAMEWORK=hybrid), the generated subprocess script requires openapi_ruby/rspec and openapi_ruby/minitest at the top — both pull in lib/openapi_ruby.rb before Rails is loade...
X Description: Summary In hybrid mode (FRAMEWORK=hybrid), the generated subprocess script requires openapi_ruby/rspec and openapi_ruby/minitest at the top — both pull in lib/openapi_ruby.rb before Rails is loade...
Opengraph URL: https://github.com/openapi-ruby/openapi-ruby/pull/35
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:0711a9ed-8282-c2b2-3f2e-b881e16b0a73 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A660:213839:1CC684B:24CA01F:6B014B7E |
| html-safe-nonce | 042bbbdefee4a76929970ff5c97506d8627159db8cb4a8e77c3dc497f6af9c66 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjYwOjIxMzgzOToxQ0M2ODRCOjI0Q0EwMUY6NkIwMTRCN0UiLCJ2aXNpdG9yX2lkIjoiMjgyNjcxODIyMzU1MzA4ODM4MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ee0431bb510a8055303b55dfbfd93c2d92eefd45b2b435be8e46a32b176dea88 |
| hovercard-subject-tag | pull_request:3832024496 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/openapi-ruby/openapi-ruby/pull/35/files |
| twitter:image | https://avatars.githubusercontent.com/u/517703?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/517703?s=400&v=4 |
| og:image:alt | Summary In hybrid mode (FRAMEWORK=hybrid), the generated subprocess script requires openapi_ruby/rspec and openapi_ruby/minitest at the top — both pull in lib/openapi_ruby.rb before Rails is loade... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/openapi-ruby/openapi-ruby git https://github.com/openapi-ruby/openapi-ruby.git |
| octolytics-dimension-user_id | 276587259 |
| octolytics-dimension-user_login | openapi-ruby |
| octolytics-dimension-repository_id | 1211860664 |
| octolytics-dimension-repository_nwo | openapi-ruby/openapi-ruby |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1211860664 |
| octolytics-dimension-repository_network_root_nwo | openapi-ruby/openapi-ruby |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width