Sha256: e90da18fdca81f68f98d1e139e873cfa52262a87a0260e41da27dd74a949d473

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

# encoding: utf-8

module Apiary
  module Helpers
    def api_description_source_path(path)
      raise "Invalid path #{path}" unless File.exist? path
      return path if File.file? path
      source_path = choose_one(path)
      return source_path unless source_path.nil?
      raise 'No API Description Document found'
    end

    def api_description_source(path)
      source_path = api_description_source_path(path)
      source = nil
      File.open(source_path, 'r:bom|utf-8') { |file| source = file.read }
      source
    end

    protected

    def choose_one(path)
      apibPath = api_blueprint(path)
      swaggerPath = swagger(path)

      if apibPath && swaggerPath
        warn 'WARNING: Both apiary.apib and swagger.yaml are present. The apiary.apib file will be used. To override this selection specify path to desired file'
      end

      apibPath || swaggerPath
    end

    def api_blueprint(path)
      source_path = File.join(path, 'apiary.apib')
      return source_path if File.exist? source_path
      return nil
    end

    def swagger(path)
      source_path = File.join(path, 'swagger.yaml')
      return source_path if File.exist? source_path
      return nil
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
apiaryio-0.4.2 lib/apiary/helpers.rb
apiaryio-0.4.1 lib/apiary/helpers.rb
apiaryio-0.4.0-x86_64-darwin-13 lib/apiary/helpers.rb