I configured json-resouce-api. But the self link generated by json-resource-api is wrong.
The code seems to checks the module hierarchy of the resource class and completely ignores how rails generates the routes.
routes.rb
require 'api_constraints'
Rails.application.routes.draw do
namespace :api, defaults: { format: :json }, constraints: { subdomain: 'api' }, path: '/' do
scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do
# resources :subscriptions, only: [:index, :new, :create]
# jsonapi_resources :subscriptions, only: [:index, :new, :create]
jsonapi_resources :subscriptions
end
end
resouces/api/V1/subscription_recource.rb
class Api::V1::SubscriptionResource < JSONAPI::Resource
attributes :id, :third-service_id, :created_at, :updated_at
model_name 'Subscription'
# def custom_links(options)
# {self: nil}
# end
end
What I got => http://api.localhost.local:3000/api/v1/subscriptions/1
but it should be http://api.localhost.local:3000/subscriptions/1
How can I fix this?
UPDATE
rake routes
[DUPLICATE ATTRIBUTE] `id` has already been defined in SubscriptionResource.
Prefix Verb URI Pattern Controller#Action
api_v1_subscriptions GET /subscriptions(.:format) api/v1/subscriptions#index {:format=>:json, :subdomain=>"api"}
POST /subscriptions(.:format) api/v1/subscriptions#create {:format=>:json, :subdomain=>"api"}
api_v1_subscription GET /subscriptions/:id(.:format) api/v1/subscriptions#show {:format=>:json, :subdomain=>"api"}
PATCH /subscriptions/:id(.:format) api/v1/subscriptions#update {:format=>:json, :subdomain=>"api"}
PUT /subscriptions/:id(.:format) api/v1/subscriptions#update {:format=>:json, :subdomain=>"api"}
DELETE /subscriptions/:id(.:format) api/v1/subscriptions#destroy {:format=>:json, :subdomain=>"api"}
stripe_event /stripe-events StripeEvent::Engine
UPDATE2
This issue is totally the same as github.com/cerebris/jsonapi-resources/issues/591 Monkey Pack can be applied, but it's little bit risky. For now ( 2016, Oct 5th ), I couldn't find any other ways than
namespace :api do
namespace :v1 do
jsonapi_resources :subscriptions
end
end