v3: prefix template variables with entity type (like in json-api)
This commit is contained in:
parent
b2ba9383eb
commit
c9fc88fa9a
|
@ -4,7 +4,7 @@ module Travis::API::V3
|
|||
extend DSL
|
||||
|
||||
resource :repository do
|
||||
route '/repo/:id'
|
||||
route '/repo/{repository.id}'
|
||||
get :find_repository
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,11 +4,12 @@ module Travis::API::V3
|
|||
@required_params ||= []
|
||||
end
|
||||
|
||||
def self.params(*list, optional: false)
|
||||
def self.params(*list, optional: false, prefix: nil)
|
||||
@params ||= []
|
||||
list.each do |param|
|
||||
param = param.to_s
|
||||
define_method(param) { params[param] }
|
||||
method = param = param.to_s
|
||||
param = "#{prefix}.#{method}" if prefix
|
||||
define_method(method) { params[param] }
|
||||
required_params << param unless optional
|
||||
@params << param
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module Travis::API::V3
|
||||
class Services::FindRepository < Service
|
||||
params :id, :github_id, :slug, optional: true
|
||||
params :id, :github_id, :slug, optional: true, prefix: :repository
|
||||
|
||||
def run
|
||||
raise NotFound, :repository unless repository and access_control.visible? repository
|
||||
|
|
|
@ -9,7 +9,7 @@ describe Travis::API::V3::ServiceIndex do
|
|||
describe "custom json entry point" do
|
||||
let(:expected_resources) {{
|
||||
"repository" => {
|
||||
"find" => [{"request-method"=>"GET", "uri-template"=>"#{path}repo/{id}"}]
|
||||
"find" => [{"request-method"=>"GET", "uri-template"=>"#{path}repo/{repository.id}"}]
|
||||
}
|
||||
}}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user