如何使用 ruby 大摇大摆地 ui 填充 http_code 400/401 的响应模型?

How to populate the response model for http_code 400/401 in swagger ui using ruby?

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

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:

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

       .....

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