Sha256: 5c91054fd7d5247804a24f6fb935d1ab0497b61a24ca1074f54d0891fd02c881

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require 'swagger/swagger_object'

module Swagger
  module V2
    # Class representing a Swagger "Parameter Object".
    # @see https://github.com/wordnik/swagger-spec/blob/master/versions/2.0.md#parameterObject Parameter Object
    class Parameter < SwaggerObject
      # @!group Fixed Fields
      # required_field :name, String
      field :name, String
      # required_field :in, String
      field :in, String
      field :description, String
      field :required, Swagger::Boolean
      alias required? required
      # @!endgroup

      # @!group Body Fields
      field :schema, Schema
      # @!endgroup

      # @!group Non-Body Fields
      field :type, String
      field :format, String
      field :items, Hash # TODO: Items Object
      field :collectionFormat, String
      field :default, Object
      # @!endgroup

      def parse
        # resolve $ref parameters
        schema = clone
        if schema.key?('$ref')
          #  TODO: Make this smarter than just split, assuming local ref
          key = schema.delete('$ref').split('/').last
          model = root.parameters[key]
          schema.merge!(model)
        end

        schema.to_hash
      end

      include DeterministicJSONSchema
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
swagger-core-0.3.0 lib/swagger/v2/parameter.rb