zero-rails_openapi icon indicating copy to clipboard operation
zero-rails_openapi copied to clipboard

Issues with two routes referencing the same controller method

Open fatigue-science opened this issue 2 years ago • 1 comments

One issue we encountered was when two routes are pointing to the same Controller method.

E.g.

GET /api/posts
GET /api/users/{user-id}/posts

Which point to controller

class API::PostsController
  def index
     posts = policy_scope(Post)
     posts = posts.where(user_id: params[:user_id]) if params[:user_id].present?

     render posts.as_json
  end
end

And API Docs

class API::PostsDoc < ApiDoc
  route_base 'api/posts'

  api :index, "Get Posts" do
    ..
  end
end

So far we haven't found a way to write the definition that generates the correct docs for both endpoints at the same time

fatigue-science avatar Sep 06 '23 17:09 fatigue-science

Did you figure out a solution to this?

matthewaptaylor avatar Mar 30 '25 23:03 matthewaptaylor