Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation not working when same name of controllers reside in scopes #455

Closed
vkeziah opened this issue Apr 26, 2016 · 6 comments · Fixed by #855
Closed

Documentation not working when same name of controllers reside in scopes #455

vkeziah opened this issue Apr 26, 2016 · 6 comments · Fixed by #855

Comments

@vkeziah
Copy link

vkeziah commented Apr 26, 2016

I have 2 controllers having the same name but in different scopes and have the different routes but documentation not considering both , its considering only one , please look at the following example

  scope module: :courier do 
    resources :devices, path: "/couriers/devices"
  end

  scope module: :user do  
    resources :devices, path: "/users/devices"
  end

courier devices controller

  api :POST, '/couriers/devices', 'Create device for courier'

user devices controller

  api :POST, '/users/devices', 'Create device for user'

on documentation I see only couriers part like the following

  POST /api/couriers/devices"   Create device for courier

I dont see my users url documentation, Whats wrong in that ? is this gem not working for scopes?

@javvarcar
Copy link

Same here. I have 2 routes:
POST '/parts/favorites' in parts/favorites#create
POST 'stories/favorites' in stories/favorites#create

, and apipie only shows one.

I found this closed issue from 2013: #104

Any idea?

@BrahimDahmani
Copy link

+1

@yr0
Copy link

yr0 commented Dec 21, 2016

I've found the solution - actually the library supports it, but you have to opt-in in this behavior (for whatever reason). See https://github.com/Apipie/apipie-rails#configuration-reference - the configuration parameter namespaced_resources needs to be set to true:

# config/initializers/apipie.rb
Apipie.configure do |config|
  # ...
  config.namespaced_resources = true
end

Even after you do this, the names of api resources will be ugly (MyNamespace::DetailsController will be named My namespacedetails). I think this will be addressed in the future.

@javvarcar
Copy link

@yr0 it works ;)

@esen
Copy link

esen commented Dec 25, 2017

Before the ugly names addressed, monkey patching can save our eyes:

module Apipie
  class Application
    def get_resource_name(klass)
      if klass.class == String
        klass
      elsif @controller_to_resource_id.has_key?(klass)
        @controller_to_resource_id[klass]
      elsif Apipie.configuration.namespaced_resources? && klass.respond_to?(:controller_path)
        return nil if klass == ActionController::Base
        path = klass.controller_path
        path.gsub(version_prefix(klass), " -> ").gsub("/", "-")
      elsif klass.respond_to?(:controller_name)
        return nil if klass == ActionController::Base
        klass.controller_name
      else
        raise "Apipie: Can not resolve resource #{klass} name."
      end
    end
  end
end

@jmugatu
Copy link

jmugatu commented Oct 9, 2019

This doesn't appear to work with response validation, i.e. auto_validate_rendered_views. With v0.5.16 the following error is raised with config.namespaced_resources = true:

  NoMethodError:
    undefined method `method_description' for nil:NilClass
    Did you mean?  method_missing


  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/apipie-rails-0.5.15/lib/apipie/application.rb:259:in `json_schema_for_method_response'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/apipie-rails-0.5.15/lib/apipie/apipie_module.rb:24:in `json_schema_for_method_response'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/apipie-rails-0.5.15/lib/apipie/rspec/response_validation_helper.rb:92:in `schema_validation_errors_for_response'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/apipie-rails-0.5.15/lib/apipie/rspec/response_validation_helper.rb:184:in `validate_response_and_abort_with_info_if_errors'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/apipie-rails-0.5.15/lib/apipie/rspec/response_validation_helper.rb:172:in `validate_response'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/apipie-rails-0.5.15/lib/apipie/rspec/response_validation_helper.rb:166:in `process'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/actionpack-4.2.11.1/lib/action_controller/test_case.rb:67:in `process'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/devise-4.7.1/lib/devise/test/controller_helpers.rb:35:in `block in process'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/devise-4.7.1/lib/devise/test/controller_helpers.rb:102:in `catch'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/devise-4.7.1/lib/devise/test/controller_helpers.rb:102:in `_catch_warden'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/devise-4.7.1/lib/devise/test/controller_helpers.rb:35:in `process'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/actionpack-4.2.11.1/lib/action_controller/test_case.rb:526:in `patch'
  # ./spec/controllers/api/v2/agent/events_controller_spec.rb:61:in `block (4 levels) in <top (required)>'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:254:in `instance_exec'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:254:in `block in run'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:500:in `block in with_around_and_singleton_context_hooks'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:457:in `block in with_around_example_hooks'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:464:in `block in run'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:604:in `block in run_around_example_hooks_for'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:342:in `call'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-rails-3.8.1/lib/rspec/rails/example/controller_example_group.rb:191:in `block (2 levels) in <module:ControllerExampleGroup>'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:447:in `instance_exec'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:447:in `instance_exec'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:373:in `execute_with'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:606:in `block (2 levels) in run_around_example_hooks_for'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:342:in `call'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-rails-3.8.1/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:447:in `instance_exec'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:447:in `instance_exec'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:373:in `execute_with'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:606:in `block (2 levels) in run_around_example_hooks_for'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:342:in `call'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-retry-0.6.1/lib/rspec/retry.rb:123:in `block in run'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-retry-0.6.1/lib/rspec/retry.rb:110:in `loop'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-retry-0.6.1/lib/rspec/retry.rb:110:in `run'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-retry-0.6.1/lib/rspec_ext/rspec_ext.rb:12:in `run_with_retry'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-retry-0.6.1/lib/rspec/retry.rb:37:in `block (2 levels) in setup'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:447:in `instance_exec'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:447:in `instance_exec'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:373:in `execute_with'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:606:in `block (2 levels) in run_around_example_hooks_for'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:342:in `call'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:607:in `run_around_example_hooks_for'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:464:in `run'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:457:in `with_around_example_hooks'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:500:in `with_around_and_singleton_context_hooks'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:251:in `run'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:629:in `block in run_examples'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:625:in `map'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:625:in `run_examples'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:591:in `run'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:592:in `block in run'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:592:in `map'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:592:in `run'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:592:in `block in run'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:592:in `map'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:592:in `run'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:116:in `block (3 levels) in run_specs'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:116:in `map'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:116:in `block (2 levels) in run_specs'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:1989:in `with_suite_hooks'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:111:in `block in run_specs'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/reporter.rb:74:in `report'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:110:in `run_specs'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:87:in `run'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:71:in `run'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:45:in `invoke'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/rspec-core-3.8.0/exe/rspec:4:in `<top (required)>'
  # /Users/jmugatu/.rbenv/versions/2.3.8/bin/rspec:22:in `load'
  # /Users/jmugatu/.rbenv/versions/2.3.8/bin/rspec:22:in `<top (required)>'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:74:in `load'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:74:in `kernel_load'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/cli/exec.rb:28:in `run'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/cli.rb:463:in `exec'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/cli.rb:27:in `dispatch'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/cli.rb:18:in `start'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/exe/bundle:30:in `block in <top (required)>'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
  # /Users/jmugatu/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/bundler-1.17.3/exe/bundle:22:in `<top (required)>'
  # /Users/jmugatu/.rbenv/versions/2.3.8/bin/bundle:22:in `load'
  # /Users/jmugatu/.rbenv/versions/2.3.8/bin/bundle:22:in `<main>'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants