Skip to content

Support Ruby 3.3, 3.4, 4.0 and Rails 8.1 - #18

Draft
snhrm wants to merge 5 commits into
masterfrom
chore/support-ruby-4-0-rails-8-1
Draft

snhrm wants to merge 5 commits into
masterfrom
chore/support-ruby-4-0-rails-8-1

Conversation

@snhrm

@snhrm snhrm commented Oct 30, 2026 •

Copy link
Copy Markdown

Why

open_api を (open_api_annotator 経由で) 使っているアプリを Ruby 3.4 / 4.0、Rails 8.1 に上げられるようにするため。現在の 0.6.2 は activesupport < 7.2 なので、Rails 7.2 以降と一緒に入れられない。

What

  • activesupport の上限を < 8.2 に緩める (下限 >= 5.0 は Bump Ruby and Rails #17 と同じく据え置き)
  • 開発依存の bundler ~> 2.0 を削除する。Ruby 4.0 は Bundler 4 を同梱しているため、残すと bundle install が失敗する
  • lib/open_api.rb で forwardable を明示的に require する
    • Paths / Responses / Callback / SecurityRequirement は extend Forwardable しているが、どこでも require していなかった。ほかのライブラリが先に forwardable を読み込んでいないと、require "open_api" は NameError: uninitialized constant OpenApi::Paths::Forwardable になる。require "open_api" だけなら Ruby 3.2 でも同じ
    • psych は 5.1.0 まで forwardable を読み込んでいた。このため Ruby 3.2 まで (同梱の psych 5.0 系を使う場合) は、yaml を読み込むもの (require "rails" を含む) の後なら動いていた
    • psych 5.1.1 以降 (Ruby 3.3 同梱の 5.1.2 を含む) は読み込まないので、require "rails" の後でも NameError になる
    • open_api_annotator は require "rails" の直後に require "open_api" するので、Ruby 3.3 以降ではこれに当たる
    • Rails アプリの中では、action_controller/railtie が (strong_parameters → rack-test 経由で) 先に forwardable を読み込むので、表に出ていなかった
  • spec を追加する
    • 別プロセスで require "open_api" だけを読み込めること。spec_helper が先に読む simplecov が forwardable を読み込むので、同じプロセスでは検出できない
    • open_api_annotator と同じ手順で組み立てた文書の YAML を、完全一致で比べる (Parameter、Components、nullable、required、allOf などを含む)
    • == が、中身の違うオブジェクトに対して false を返すこと。これまでは == を常に true にしても既存の spec がすべて通っていた。.load の spec は結果を eq (内部で == を使う) で比べているので、== 自体の誤りは検出できない
  • CI を次の組み合わせにする
    • Ruby 3.3 / 3.4 / 4.0 × Rails 8.1
    • Ruby 3.3 × Rails 7.0 / 7.1 / 7.2 / 8.0
    • Ruby 4.0 × Rails 7.0
    • gemfiles は rails-6.1.gemfile を削除し、rails-7.1 / rails-7.2 / rails-8.0 を追加する
  • Ruby 3.0〜3.2 と Rails 6.1 は、CI と CHANGELOG 0.6.3 の対応表に含めない。gemspec の制約 (Ruby の指定なし、activesupport >= 5.0) は変えていないので、インストール自体はできる
  • .ruby-version を 3.2.2 から 4.0.9 に上げる
  • Code Climate の coverage 送信ステップとバッジを削除する。Code Climate の API は 2025-07-18 に停止していて、ステップを残すと CI が失敗する
  • 0.6.3 に上げ、CHANGELOG を追記する

確認したこと

  • spec が全件通る (82 examples, 0 failures)
    • CI と同じ 8 通りに加え、CI に入れていない Ruby 3.4 × Rails 7.0〜8.0 と Ruby 4.0 × Rails 7.1〜8.0 でも確認した
  • 追加した spec で、次の書き換えがすべて落ちることを確認した (Ruby 3.3 / 3.4 / 4.0)
    • require "forwardable" を外す
    • Parameter の in を Symbol のまま出す
    • Operation の parameters、Parameter の schema、Specification の components を出力から落とす
    • Schema の配列要素の to_s を外す
    • == を「常に true」「クラスだけ比べる」「ivar 名だけ比べる」「最初の ivar / 最後の ivar だけ比べる」に変える
  • ゴールデン YAML の期待値は、Ruby 3.2 + activesupport 7.1 (前回のリリースで対応していた構成) で master が出す YAML と同じ
  • RUBYOPT=-W:deprecated を付けても、lib と spec から警告が出ない

バージョンで出力が変わるもの (今回は直していない)

  • psych 5.2 以降 (Ruby 3.4 以降に同梱) は、文字列 "Y" / "N" を引用符付きで出力する。読み戻したときの値は同じ
  • Schema の値 (properties / items 以外) に Hash を渡すと、to_s で文字列になる (既存のバグ)。その書式が、Ruby 3.4 の Hash#inspect の変更で変わる
  • open_api_annotator が出す形の文書では、Hash の件は起きない。"Y" / "N" の件も、スキーマ名・プロパティ名・パスパラメータ名・format・config.info の値がちょうど "Y" / "N" でない限り起きない

リリース

snhrm added 2 commits October 29, 2026 23:22
- Relax activesupport upper bound to < 8.2
- Drop bundler ~> 2.0 dev dependency, which conflicts with Bundler 4 bundled with Ruby 4.0
- Test Ruby 3.3, 3.4, 4.0 and Rails 7.0 to 8.1 on CI
- Remove Code Climate coverage upload, whose API was shut down
snhrm added 3 commits October 30, 2026 15:49
Paths, Responses, Callback and SecurityRequirement extend Forwardable,
but nothing required it. psych up to 5.1.0 happened to load it, so
requiring open_api after yaml (e.g. right after rails) worked on Ruby 3.2.
psych 5.1.1+ (bundled with Ruby 3.3+) no longer loads it, which makes
require "open_api" raise NameError unless something else loaded it first.

The spec runs in a separate process because simplecov, loaded by
spec_helper, requires forwardable and hides the problem.
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