Class: Swagger::Schema::Headers
- Inherits:
-
Object
- Object
- Swagger::Schema::Headers
- Defined in:
- lib/swagger/schema/headers.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#initialize(schema) ⇒ Headers
constructor
A new instance of Headers.
- #to_json_schema ⇒ Object
Constructor Details
#initialize(schema) ⇒ Headers
Returns a new instance of Headers.
7 8 9 |
# File 'lib/swagger/schema/headers.rb', line 7 def initialize(schema) @schema = schema end |
Instance Method Details
#[](name) ⇒ Object
11 12 13 14 |
# File 'lib/swagger/schema/headers.rb', line 11 def [](name) header = Util.try_hash(@schema, name) Header.new(header) if header end |
#to_json_schema ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/swagger/schema/headers.rb', line 16 def to_json_schema return { "type" => "object" } unless @schema properties = {} required = [] @schema.each do |_name, param| name = _name.to_s header = Header.new(param) properties[name] = header.to_json_schema required << name if header.required if Util.try_hash(properties[name], :type).to_s == "string" && !parameter.allowEmptyValue && Util.try_hash(properties[name], :minLength).nil? properties[name]["minLength"] = 1 end end schema = { "type" => "object", "properties" => properties } schema["required"] = required unless required.empty? schema end |