Class: Swagger::DSL::Operation
- Inherits:
-
Hash
- Object
- Hash
- Swagger::DSL::Operation
- Defined in:
- lib/swagger/dsl/operation.rb
Constant Summary collapse
- FORMAT_TYPE =
{ json: "application/json", xml: "application/xml", plain: "text/plain", html: "text/html", csv: "text/csv", form: "application/x-www-form-urlencoded", }.freeze
Instance Method Summary collapse
- #body(format: @format, dsl: nil, &block) ⇒ Object
- #body_description(body_description = nil) ⇒ Object
- #body_optional(optional = true) ⇒ Object
-
#initialize(operation_id, format: :json, &block) ⇒ Operation
constructor
A new instance of Operation.
- #params(default_required: Swagger::DSL.current.config.default_required, &block) ⇒ Object
- #render(code = 200, format: @format, dsl: nil, &block) ⇒ Object
Constructor Details
#initialize(operation_id, format: :json, &block) ⇒ Operation
Returns a new instance of Operation.
17 18 19 20 21 22 23 24 |
# File 'lib/swagger/dsl/operation.rb', line 17 def initialize(operation_id, format: :json, &block) self["operationId"] = operation_id self["requestBody"] = { "content" => {}, "required" => true } self["responses"] = {} self["parameters"] = [] @format = format instance_eval(&block) end |
Instance Method Details
#body(format: @format, dsl: nil, &block) ⇒ Object
30 31 32 33 34 |
# File 'lib/swagger/dsl/operation.rb', line 30 def body(format: @format, dsl: nil, &block) formats(format).each do |f| self["requestBody"]["content"][f] = { "schema" => Swagger::DSL::JsonSchema.by(dsl).dsl(&block) } end end |
#body_description(body_description = nil) ⇒ Object
36 37 38 |
# File 'lib/swagger/dsl/operation.rb', line 36 def body_description(body_description = nil) self["requestBody"]["description"] = body_description end |
#body_optional(optional = true) ⇒ Object
40 41 42 |
# File 'lib/swagger/dsl/operation.rb', line 40 def body_optional(optional = true) self["requestBody"]["required"] = optional end |
#params(default_required: Swagger::DSL.current.config.default_required, &block) ⇒ Object
26 27 28 |
# File 'lib/swagger/dsl/operation.rb', line 26 def params(default_required: Swagger::DSL.current.config.default_required, &block) self["parameters"] = Parameters.new(default_required: default_required, &block) end |
#render(code = 200, format: @format, dsl: nil, &block) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/swagger/dsl/operation.rb', line 44 def render(code = 200, format: @format, dsl: nil, &block) self["responses"][code] ||= { "content" => {} } formats(format).each do |f| self["responses"][code]["content"][f] = { "schema" => Swagger::DSL::JsonSchema.by(dsl).dsl(&block) } end end |