处理所有请求的通用控制器的 API 文档
我需要为 postgres 数据库中的某些数据库视图动态生成 api 端点,因为我们可能会添加/删除视图,但我们不想每次执行此操作时都更新代码。
为此,我有一个通用控制器来处理所有请求,并根据需要访问的视图动态创建模型类。
当基于传递的 end_point
请求发送到 generic_api#index
时,我会动态创建某些模型类并查询它们。
routes.rb
namespace 'api' do
namespace 'v2' do
get '*end_point', to: 'generic_api#index'
end
end
const = ClassFactory.class_object(end_point.classify, result)
Octopus.using(result['shrad'].to_sym) do
result = const.ransack(params[:q]).result.page(params[:page]).per(10000)
render json: result.to_json
end
API 本身按预期工作,但是我不确定生成 API 文档的好方法是什么,因为我只有一个控制器。我们之前使用了apipie
gem,但文档似乎与每个端点的控制器紧密耦合。
当我有一个控制器处理多个端点请求时,任何关于如何生成 api 文档的帮助都会很棒,谢谢。
I need to generate api endpoints for certain database views we have in our postgres database dynamically, as we may add / delete views we don't want to update the code every time we do this.
for this i have a generic controller which handles all requests and I create model class on the fly based on which view needs to be accessed.
when a request is sent to the generic_api#index
based on the end_point
passed i create certain model classes on the fly and query them.
routes.rb
namespace 'api' do
namespace 'v2' do
get '*end_point', to: 'generic_api#index'
end
end
const = ClassFactory.class_object(end_point.classify, result)
Octopus.using(result['shrad'].to_sym) do
result = const.ransack(params[:q]).result.page(params[:page]).per(10000)
render json: result.to_json
end
The api itself is working as expected, however i am not sure what's a good way to generate documentation for the API since i only have one controller. we were earlier using the apipie
gem but the documentation seems to be tightly coupled with controllers for each end point.
Any help on how to generate api documentation when I have a single controller handling multiple end point requests would be great, Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论