0

我得到了这个代码的端点:

  resource :templates do
    desc 'Add a template for documents' do
      success Entities::Template.add_success
      failure Entities::Template.add_fail
    end

具有此代码的模板实体(除其他外):

def self.add_success
  { examples: { 'application/json' => Entities::Response.parse(201, 'succesful added', '{template_id: 1}') } }
end

def self.add_fail
  [Entities::Response.parse(422, 'ALREADY_REGISTERED_TEMPLATE')]
end

和具有此代码的响应实体:

def self.parse(code, message, data = '')
  case code
  when 200...300
    represent({ code: code, status: 'success', data: data }).as_json
  when 400...600
    represent({ code: code, status: 'fail', message: message }).as_json
  endo
end

如您所见,自动生成的 Swagger 文档包含一个用于失败响应的“模式”字段:

"responses": {
  "201": {
    "description": "Add a template for documents",
    "schema": {
      "$ref": "#/definitions/Template"
  },
  "examples": {
    "application/json": {
      "code": 201,
      "status": "success",
      "data": "{template_id: 1234}"
    }
  }
  },
"422": {
  "description": "ALREADY_REGISTERED_TEMPLATE",
  "schema": {
    "$ref": "#/definitions/Template"
  }
}
},

我已经简化了 422 响应信息以删除“模式”字段,但它继续出现。如何动态删除它。

4

0 回答 0