JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Links broken when used with `scope module:` routes
まだ誰も着手していません。
- 主要言語
- Ruby
- スター
- 2.3k
- フォーク
- 546
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Hi,
we use a version parameter inside of the Accept header to be able to switch Api versions. The different versions are grouped in modules. And to remove these modules as namespaces from the generated URLs we use scope module:. This works great but the problem ist that the generated links inside a response still include the module.
The code just checks the module hierarchy of the resource class and completely ignores how rails generates the routes. (See: https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/link_builder.rb#L102).
Also see #361 for a similar problem.
As a workaround we monkey patch the formatted_module_path_from_class method to return the correct path \api\. But that is not an ideal solution.
An example route file:
namespace :api do
scope module: :v1, constraint: ApiConstraint.new(version: 1) do
jsonapi_resources :my_resource
end
end
And an example resource:
module Api
module V1
class MyResource < JSONAPI::Resource
[...]
end
end
end
So Rails generates routes like: /api/my-resource
But the generated links look like this: /api/v1/my-resource
Sascha
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
lib/jsonapi/link_builder.rb#L102 から始め、そこでのモジュールパスの扱いを、issue に示されている Rails のルートと比較します。Api/V1/MyResource の例を再現し、関連するコンテキストについて #361 を確認します。scope module: が namespace を削除したときに、レスポンスリンクが /api/v1/my-resource ではなく /api/my-resource を使用すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- rails, ruby
- 領域
- api, backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 42/100