Apipie / apipie-rails

Ruby on Rails API documentation tool
Apache License 2.0
2.47k stars 463 forks source link

Param validation from a concern does not correctly raise errors #500

Open Tybot204 opened 8 years ago

Tybot204 commented 8 years ago

I have a large API that I am developing. Many controllers have custom actions inside of them, and I decided to move all of my Apipie documentation into concerns to make the controller's more readable. However, the param validation Apipie provides does not seem to be raising any errors like it does when the documentation is inside of the controller.

My setup: app/docs/v2/comments_doc.rb

module V2
  module CommentsDoc
    extend Apipie::DSL::Concern

    namespace 'v2'
    resource :comments

    def_param_group :comment do
      error 422, 'The Comment failed to save with the given parameters'
      param :comment, Hash, required: true, action_aware: true do
        param :body, String, desc: 'Content to post in the Comment', required: true
      end
    end

    api! 'Create a new Comment'
    authentication_required
    param_group :comment
    def create
      # Blank since this is just a stub
    end
  end
end

app/controllers/v2/comments_controller.rb

module V2
  class CommentsController < ApplicationController
    include V2::CommentsDoc

    def create
      # Body of create
    end
  end
end
Tybot204 commented 7 years ago

As an update to this, it appears to work fine when the documentation files are included after the body of the controller.

app/controllers/v2/comments_controller.rb

module V2
  class CommentsController < ApplicationController
    def create
      # Body of create
    end

    include V2::CommentsDoc
  end
end
iNecas commented 7 years ago

Interesting, I plan to touch the dsl definitions (to be able to extend exising documentation from external plugins: I can try to cover this as well)

nosleinfull commented 3 years ago

I get the same problem.