Sha256: de66119ee683ff859ec8407fa14813a33b6cdfd6bb4f15dd34bcac0aa17eb57c

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module SwaggerYard
  class Api
    attr_accessor :path, :description

    def self.path_from_yard_object(yard_object)
      if tag = yard_object.tags.detect {|t| t.tag_name == "path"}
        tag.text
      else
        nil
      end
    end

    def self.from_yard_object(yard_object, api_declaration)
      path = path_from_yard_object(yard_object)
      description = yard_object.docstring

      new(path, description, api_declaration)
    end

    def initialize(path, description, api_declaration)
      @api_declaration = api_declaration
      @description = description
      @path = path

      @operations = []
    end

    def add_operation(yard_object)
      @operations << Operation.from_yard_object(yard_object, self)
    end

    def to_h
      {
        "path"        => path,
        "description" => description,
        "operations"  => @operations.map(&:to_h)
      }
    end

    def model_names
      @operations.map(&:model_names).flatten.compact.uniq
      # @parameters.select {|p| ref?(p['type'])}.map {|p| p['type']}.uniq
    end

    def ref?(data_type)
      @api_declaration.ref?(data_type)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
swagger_yard-0.1.0 lib/swagger_yard/api.rb