Repository navigation
Conversation
Since Rails 7.0, Journey::Path::Pattern#ast returns a Journey::Ast wrapper (and is cleared on eager_load!), so PathResolver failed on ast.type. Pattern#spec returns the raw node tree on every Rails version.
- Relax actionpack / railties upper bound to < 8.2 - Require open_api >= 0.6.3, the first version allowing activesupport 7.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
| - ruby: "3.3" | ||
| gemfile: "gemfiles/rails-7.0.gemfile" |
There was a problem hiding this comment.
wantedly/open_api#18 では 7ad9e95 で Ruby 4.0 × rails-7.0 のセルを追加していますが、こちらには入っていないようです。
annotator は railties / actionpack も読み込むので、対応表の中では Ruby 4.0 × Rails 7.0 がいちばん壊れやすい組み合わせだと思います (手元では spec は通りますが、Rails 7.0 から tsort の deprecation warning が出ます)。open_api#18 に揃えて追加しておくのはどうでしょう。
| - ruby: "3.3" | |
| gemfile: "gemfiles/rails-7.0.gemfile" | |
| - ruby: "3.3" | |
| gemfile: "gemfiles/rails-7.0.gemfile" | |
| - ruby: "4.0" | |
| gemfile: "gemfiles/rails-7.0.gemfile" |
There was a problem hiding this comment.
ありがとうございます、open_api#18 に揃えて Ruby 4.0 × rails-7.0 のセルを追加しました (c1abd20)。
手元 (Docker) でも Ruby 4.0.9 × railties 7.0.10 で 13 examples, 0 failures を確認しています。tsort の warning は railties 7.0 の rails/initializable.rb 由来で 7.1 以降では出ないため、今回はそのままにしています。
なお open_api 0.6.3 の公開前なので、このセルも他と同様に依存解決で落ちる状態です。
There was a problem hiding this comment.
ご対応ありがとうございます、c1abd20 を確認しました。LGTM です。
open_api#18 の merge と 0.6.3 のリリース後に、こちらの CI を再実行して通ったことを確認してから approve します。
There was a problem hiding this comment.
追加の 664f4e8 (belongs_to の $ref の修正と、配列でない has_many のスキップ) も確認しました。こちらも LGTM です。
approve は前回書いたとおり、open_api 0.6.3 のリリース後に CI が通ったことを確認してから行います。
|
wantedly で動作確認したところ、この PR だけでは wantedly の
この PR の変更内容自体は変わっていません。 |
… type - open_api_belongs_to_associations wrapped the serializer's resource name in an array, producing $ref like #/components/schemas/["OpenUser"]. - build_has_many_association_properties called first on the annotated type even when it was not an array (e.g. an ActiveRecord model, which runs a query), and returned nil from the whole method when it got nil, making rake api_spec raise TypeError. Now it calls first only on arrays and skips the association with a warning otherwise.
|
LGTM いただいた後ですが、wantedly で
詳細は本文の What と「wantedly での確認」に追記しています。お手数ですが、差分 (lib 2 ファイルと spec) の確認をお願いします。 |
Why
actionpack/railties < 7.2になっているrake api_specが Rails 7.0 以降、NoMethodError: undefined method 'type' for an instance of ActionDispatch::Journey::Astで失敗するrake api_specを実行して見つかった、既存のバグ 2 つserializer:を指定したbelongs_toの$refが、#/components/schemas/["OpenUser"]のように配列を文字列にしたものになるhas_manyのtype:に配列ではなくクラスなどを書いた serializer が 1 つでもあると、rake api_specが止まるか、不正な$refを出力する。ActiveRecord のモデルを書いた場合、テーブルが空ならTypeError: no implicit conversion of nil into Hashで止まるWhat
RoutesFinderがroute.path.astではなくroute.path.specを使うように直すPattern#astはJourney::Astというラッパーを返し、eager_load!の後は nil になるPattern#specは Rails 5.0〜8.1 のどの版でも、生のノードツリーを返すopen_api_belongs_to_associationsで、serializer:を指定したときの型を配列で包まないようにするhas_manyの行をコピーしたまま[...]が残っていた。has_oneは配列で包んでいないComponentsBuilderで、has_manyの型が配列でないか空の配列のときは、警告を出してその関連だけを飛ばすeachの中のreturnでメソッド全体が nil を返し、merge!(nil)でTypeErrorになっていたfirstは型が配列のときだけ呼ぶようにした。ActiveRecord のモデルだとfirstが DB クエリを実行し、データがあればレコードが返って不正な$refが出力されるため。文字列 ("Author") でも ActiveSupport のString#firstで"A"が返っていたactionpack/railtiesの上限を< 8.2にし、open_api >= 0.6.3を必須にするforwardableを明示的に require する修正 (Support Ruby 3.3, 3.4, 4.0 and Rails 8.1 open_api#18) も入っているrequire "open_api_annotator"したときにNameError: uninitialized constant OpenApi::Paths::Forwardableになる。open_api_annotator がrequire "rails"の直後にrequire "open_api"するためaction_controllerが先に forwardable を読み込むので、表に出ていなかった。この gem の spec でも、spec_helper が先に読む simplecov が forwardable を読み込むので検出できていなかったbundler ~> 2.0を削除し、CI を Ruby 3.3 / 3.4 / 4.0 と Rails 7.0〜8.1 にし、Code Climate を削除する。どれも Support Ruby 3.3, 3.4, 4.0 and Rails 8.1 open_api#18 と同じ内容確認したこと
.ast/.ast.rootに戻す変異や、パラメータを落とす変異で落ちるbelongs_toの型を配列で包む /has_oneの型を配列で包む /has_manyの型の[...]を外すnextをreturnに戻すrequire "open_api_annotator"が通り、修正前の open_api では NameError になるrake api_specを実行した (既存バグの修正の確認は下の「wantedly での確認」)wantedly での確認
wantedly master のコピーに wantedly/open_api#18 とこの PR の gem を入れ、development 環境で
rake api_spec:createを実行した。CandidacySerializerのhas_many :selection_invitation_logsのtype:を配列にする 1 行。wantedly/wantedly#73734 (2025-05-20) からクラスになっていた) を当てた場合swagger/api_v2.ymlと比べて、既存の path と、既存 schema の既存プロパティは、Api::ProjectRecommendationのsupporterの$refが#/components/schemas/OpenUserに直ったこと以外は一致したAttachmentFileschema の削除だけSkipped CandidacySerializer#selection_invitation_logs: ...の警告が出て、Candidacyのselection_invitation_logsだけが出力から抜けるmerge の順番
open_api >= 0.6.3を解決できずに全セルが失敗するbundle exec rake releaseを実行するrake api_spec:createを実行してswagger/api_v2.ymlを再生成する