Sha256: e791af3fe9f4b92a9a861ac383a33bd77d07624a747aca9494c9dd999cb7e245

Contents?: true

Size: 1017 Bytes

Versions: 20

Compression:

Stored size: 1017 Bytes

Contents

require_relative "./util"
require_relative "./header"

module Swagger
  class Schema
    class Headers
      def initialize(schema)
        @schema = schema
      end

      def [](name)
        header = Util.try_hash(@schema, name)
        Header.new(header) if header
      end

      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
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
swagger-serializer-0.9.1 lib/swagger/schema/headers.rb
swagger-serializer-0.9.0 lib/swagger/schema/headers.rb
swagger-serializer-0.8.3 lib/swagger/schema/headers.rb
swagger-serializer-0.8.2 lib/swagger/schema/headers.rb
swagger-serializer-0.8.1 lib/swagger/schema/headers.rb
swagger-serializer-0.8.0 lib/swagger/schema/headers.rb
swagger-serializer-0.7.0 lib/swagger/schema/headers.rb
swagger-serializer-0.6.2 lib/swagger/schema/headers.rb
swagger-serializer-0.6.1 lib/swagger/schema/headers.rb
swagger-serializer-0.6.0 lib/swagger/schema/headers.rb
swagger-serializer-0.5.2 lib/swagger/schema/headers.rb
swagger-serializer-0.5.1 lib/swagger/schema/headers.rb
swagger-serializer-0.5.0 lib/swagger/schema/headers.rb
swagger-serializer-0.4.1 lib/swagger/schema/headers.rb
swagger-serializer-0.4.0 lib/swagger/schema/headers.rb
swagger-serializer-0.3.0 lib/swagger/schema/headers.rb
swagger-serializer-0.2.1 lib/swagger/schema/headers.rb
swagger-serializer-0.2.0 lib/swagger/schema/headers.rb
swagger-serializer-0.1.1 lib/swagger/schema/headers.rb
swagger-serializer-0.1.0 lib/swagger/schema/headers.rb