首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用ruby在swagger中填充http_code 400/401的响应模型?

如何使用ruby在swagger中填充http_code 400/401的响应模型?
EN

Stack Overflow用户
提问于 2015-10-05 09:02:11
回答 1查看 253关注 0票数 0

如何使用ruby在swagger中填充http_code 400/401的响应模型?我想为401 error.My代码添加响应模型,如下所示: user_entity.rb:

代码语言:javascript
复制
module something
  module V1
    class UserEntity < Grape::Entity
      expose :id, documentation: { type: "String", desc: "User id" }
      expose :phone, documentation: { type: "String", desc: "Registered phone number" }
      expose :email, documentation: { type: "String", desc: "Email" }
      expose :created_at, documentation: { type: "String", desc: "format:yyyy-mm-ddThh:mm:ss.364+(gmt) for eg:\"2015-10-04T15:33:39.364+04:00\"" }
      expose :updated_at, documentation: { type: "String", desc: "format:yyyy-mm-ddThh:mm:ss.364+(gmt) for eg:\"2015-10-04T15:33:39.364+04:00\"" }

      expose :access_token,  if: lambda { |object, options| options[:show_access_token] == true }
      expose :access_token_expires,  if: lambda { |object, options| options[:show_access_token] == true }


      private
      def id
        object.id.to_s
      end
    end
  end
end

user_resource.rb:

代码语言:javascript
复制
module something
  module V1

    class UsersResource < Grape::API
      include something::V1::Defaults


      resource :users, desc: 'Operations about users' do

        desc "Returns all users", {
          headers: {
            "Authorization" => {description: "pass the access token as Bearer",
                                required: true
                               }
          },
           http_codes: [
            [401, 'Not authorized: The access token does not exist or is invalid'],
            [200, 'Success',UserEntity]
          ],

          detail: 'This endpoint returns all the users that have successfully registered with a valid phone number.'

        }
        get do
          User.all.to_a
        end

       .....
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-22 12:31:26

我自己想出来的。我刚刚在我的defaults.rb中添加了我需要的所有错误代码,并将它添加到我的http_codes中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32944734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档