Sha256: 6c9bdd87527f09749647d9c533809b2fd6e54d24153edadc469a001c563ed180

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

require 'swagger/swagger_object'
require 'swagger/v2/operation'

module Swagger
  module V2
    # Class representing a Swagger "Path Item Object".
    # @see https://github.com/wordnik/swagger-spec/blob/master/versions/2.0.md#pathItemObject Path Item Object
    class Path < SwaggerObject
      extend Forwardable
      def_delegator :parent, :host

      VERBS = [:get, :put, :post, :delete, :options, :head, :patch]
      VERBS.each do |verb|
        field verb, Operation
      end
      field :parameters, Array[Parameter]

      def initialize(hash)
        hash[:parameters] ||= []
        super
      end

      def operations
        VERBS.each_with_object({}) do |v, h|
          operation = send v
          h[v] = operation if operation
        end
      end

      def uri_template
        "#{parent.host}#{parent.base_path}#{path}"
      end

      def path
        parent.paths.key self
      end

      # Iterates over each Path level parameter.
      def each_parameter
        return if parameters.nil?
        parameters.each do |parameter|
          yield parameter
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
swagger-parser-0.2.6 lib/swagger/v2/path.rb
swagger-parser-0.2.5 lib/swagger/v2/path.rb