lib/swagger/dsl/operation.rb in swagger-dsl-1.0.0 vs lib/swagger/dsl/operation.rb in swagger-dsl-1.1.0

- old
+ new

@@ -3,11 +3,16 @@ module Swagger class DSL class Operation < Hash FORMAT_TYPE = { - json: "application/json", xml: "application/xml", plain: "text/plain", html: "text/html", csv: "text/csv" + json: "application/json", + xml: "application/xml", + plain: "text/plain", + html: "text/html", + csv: "text/csv", + form: "application/x-www-form-urlencoded", }.freeze def initialize(operation_id, format: :json, &block) self["operationId"] = operation_id self["requestBody"] = { "content" => {}, "required" => true } @@ -20,13 +25,15 @@ def params(&block) self["parameters"] = Parameters.new(&block) end def body(format: @format, dsl: nil, &block) - self["requestBody"]["content"][FORMAT_TYPE[format]] = { - "schema" => Swagger::DSL::JsonSchema.by(dsl).dsl(&block) - } + formats(format).each do |f| + self["requestBody"]["content"][f] = { + "schema" => Swagger::DSL::JsonSchema.by(dsl).dsl(&block) + } + end end def body_description(body_description = nil) self["requestBody"]["description"] = body_description end @@ -35,12 +42,20 @@ self["requestBody"]["required"] = optional end def render(code = 200, format: @format, dsl: nil, &block) self["responses"][code] ||= { "content" => {} } - self["responses"][code]["content"][FORMAT_TYPE[format]] = { - "schema" => Swagger::DSL::JsonSchema.by(dsl).dsl(&block) - } + formats(format).each do |f| + self["responses"][code]["content"][f] = { + "schema" => Swagger::DSL::JsonSchema.by(dsl).dsl(&block) + } + end + end + + private + + def formats(format) + Array(format).map { |f| FORMAT_TYPE[f] } end end end end