【问题标题】:How to document RESTful API?如何记录 RESTful API?
【发布时间】:2016-09-20 06:45:01
【问题描述】:

我是 RoR 的新手。

有没有办法像Django REST Swagger这样记录RESTful api?

然后我找到了apipie-rails 来记录我的 api。

但是当我尝试将其与Spree 集成时,出现以下错误:

Unable to autoload constant BaseControllerDecorator, expected /${PATH}/base_controller_decorator.rb to define it.

base_controller_decorator.rb

Spree::Api::BaseController.class_eval do

    # Some overrided functions

end

我在 lib/apipie/application.rb 中找到了以下代码:

def load_controller_from_file(controller_file)
  controller_class_name = controller_file.gsub(/\A.*\/app\/controllers\//,"").gsub(/\.\w*\Z/,"").camelize
  controller_class_name.constantize
end

好像在decorator文件中实例化了控制器,如何解决?

【问题讨论】:

    标签: ruby-on-rails spree apipie


    【解决方案1】:

    如果您将 Grape API Framework 与 Rails 一起使用(我更喜欢),您可以使用 https://github.com/ruby-grape/grape-swagger 获取自动 swagger 文档 - 它会解析定义并动态创建文档。

    如果您不需要/不想使用 Grape on Rails、Sinatra 或纯 Ruby,我建议您使用 https://github.com/fotinakis/swagger-blocks。功能强大,但需要手动编写定义。

    【讨论】:

      猜你喜欢
      • 2016-05-02
      • 2016-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-09
      • 1970-01-01
      • 2016-09-17
      • 2020-04-08
      相关资源
      最近更新 更多