Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #6 from warp/nested_controllers

fixes swagger routes for namespaced controllers
  • Loading branch information...
commit 3608e0b8573d397f8789ecb856232974b48636e8 2 parents dfd81db + df2b614
Leon Dewey leondewey authored
2  lib/api_canon.rb
View
@@ -84,7 +84,7 @@ def document_controller(opts={}, &block)
# @see ApiCanon::DocumentedAction#response_code
def document_method(method_name, &block)
document do |document|
- documented_action = ApiCanon::DocumentedAction.new method_name, controller_name
+ documented_action = ApiCanon::DocumentedAction.new method_name, controller_path, controller_name
documented_action.instance_eval &block if block_given?
document.add_action documented_action
end
5 lib/api_canon/documented_action.rb
View
@@ -2,9 +2,10 @@ module ApiCanon
class DocumentedAction
include ActiveModel::Serialization
attr_reader :params, :response_codes, :response_model_name, :description, :action_name,
- :controller_name, :http_method
- def initialize(action_name, controller_name)
+ :controller_name, :controller_path, :http_method
+ def initialize(action_name, controller_path, controller_name)
@action_name = action_name
+ @controller_path = controller_path
@controller_name = controller_name
@params={}
# TODO: This should check routes to see if params[:format] is expected
8 lib/api_canon/routes.rb
View
@@ -11,7 +11,11 @@ def self.draw(map, options={})
end
# TODO: make :path => 'swagger-doc' customisable
- map.resources :path => 'swagger-doc', :controller => 'api_canon/swagger', :only => [:index, :show], :as => :api_canon_swagger_doc
+ map.resources :path => 'swagger-doc',
+ :controller => 'api_canon/swagger',
+ :only => [:index, :show],
+ :constraints => { :id => /.+/ },
+ :as => :api_canon_swagger_doc
end
end
-end
+end
2  lib/api_canon/swagger/api_declaration.rb
View
@@ -28,7 +28,7 @@ def path
def url_params
url_params = {
- :controller => object.controller_name,
+ :controller => object.controller_path,
:action => object.action_name,
:only_path => true
}
2  spec/lib/api_canon/documented_action_spec.rb
View
@@ -1,7 +1,7 @@
require 'spec_helper'
describe ApiCanon::DocumentedAction do
- let(:document) {ApiCanon::DocumentedAction.new :index, 'controller_name'}
+ let(:document) {ApiCanon::DocumentedAction.new :index, 'controller_path', 'controller_name'}
let(:description) {'ID is the unique identifier of the object'}
subject { document }
its(:action_name) { should == :index }
2  spec/lib/api_canon/swagger_spec/api_declaration_spec.rb
View
@@ -2,7 +2,7 @@
describe ApiCanon::Swagger::ApiDeclaration do
let(:documented_action) {
- documented_action = ApiCanon::DocumentedAction.new('action_name', 'controller_name')
+ documented_action = ApiCanon::DocumentedAction.new('action_name', 'controller_path', 'controller_name')
documented_action.describe 'description'
documented_action.response_class 'Thing'
documented_action.response_code '404', 'reason'
Please sign in to comment.
Something went wrong with that request. Please try again.