JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Links broken when used with `scope module:` routes
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Ruby
- Sterne
- 2.3k
- Forks
- 546
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit lib/jsonapi/link_builder.rb#L102 und vergleiche die Behandlung von Modulpfaden dort mit den im Issue gezeigten Rails-Routen. Reproduziere das Beispiel Api/V1/MyResource und sieh dir #361 für weiteren Kontext an. Als abgeschlossen gilt die Änderung, wenn Response-Links /api/my-resource statt /api/v1/my-resource verwenden, wenn scope module: den Namespace entfernt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- rails, ruby
- Bereich
- api, backend
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 42/100