class Swagger::Data::Responses

Public Class Methods

new() click to toggle source
# File lib/ruby-swagger/data/responses.rb, line 7
def initialize
  @responses = {}
end
parse(responses) click to toggle source
# File lib/ruby-swagger/data/responses.rb, line 11
def self.parse(responses)
  return nil unless responses

  r = Swagger::Data::Responses.new

  responses.each do |response_key, response_value|
    r.add_response(response_key, response_value)
  end

  r
end

Public Instance Methods

[](key) click to toggle source
# File lib/ruby-swagger/data/responses.rb, line 34
def [](key)
  @responses[key]
end
add_response(response_code, response) click to toggle source
# File lib/ruby-swagger/data/responses.rb, line 23
def add_response(response_code, response)
  raise ArgumentError.new('Swagger::Data::Responses#add_response - response is nil') unless response

  if !response.is_a?(Swagger::Data::Reference) && !response.is_a?(Swagger::Data::Response)
    # it's a reference object or it's a parameter object
    response = response['$ref'] ? Swagger::Data::Reference.parse(response) : Swagger::Data::Response.parse(response)
  end

  @responses[response_code] = response
end
as_swagger() click to toggle source
# File lib/ruby-swagger/data/responses.rb, line 38
def as_swagger
  res = {}

  @responses.each do |other_name, other_value|
    res[other_name] = other_value.to_swagger
  end

  res
end