Sha256: d5f1d1060736b095efdd27f1c5a2bf31500ed784bb5a2121f303e73c1af0c580

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

require 'r2-oas/deploy/client'
require 'r2-oas/tool/paths/ls'
require 'r2-oas/tool/paths/stats'
require 'r2-oas/task_logging'
load File.expand_path('common.rake', __dir__)

namespace :routes do
  namespace :oas do
    desc 'Deploy OAS Document'
    task deploy: [:common] do
      start do
        client_options = {}
        client = R2OAS::Deploy::Client.new(client_options)

        download_dist_th = Thread.new do
          puts 'Download swagger-api/swagger-ui/dist ... (async)'
          client.download_swagger_ui_dist
        end

        builder_options = { unit_paths_file_path: unit_paths_file_path }
        builder = R2OAS::Schema::Builder.new(builder_options)
        builder.build_docs

        download_dist_th.join
        client.deploy
      end
    end

    desc 'Display paths list'
    task paths_ls: [:common] do
      fd = IO.sysopen('/dev/null', 'w+')
      $stdout = IO.new(fd)
      logger.level = :null

      start do
        $stdout = StringIO.new

        paths_ls_options = {}
        paths_ls = R2OAS::Tool::Paths::Ls.new(paths_ls_options)
        paths_ls.print
      end

      result = $stdout.string
      $stdout = STDOUT
      puts result
    end

    desc 'Display paths stats'
    task paths_stats: [:common] do
      fd = IO.sysopen('/dev/null', 'w+')
      $stdout = IO.new(fd)
      logger.level = :null

      start do
        builder_options = { skip_load_dot_paths: true }
        builder = R2OAS::Schema::Builder.new(builder_options)
        builder.build_docs

        $stdout = StringIO.new

        paths_log_options = {}
        paths_log = R2OAS::Tool::Paths::Stats.new(paths_log_options)
        paths_log.print
      end

      result = $stdout.string
      $stdout = STDOUT
      puts result
    end

    private

    def unit_paths_file_path
      ENV.fetch('PATHS_FILE', '')
    end

    def existing_schema_file_path
      ENV.fetch('OAS_FILE', '')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
r2-oas-0.3.4 lib/r2-oas/tasks/tool.rake
r2-oas-0.3.3 lib/r2-oas/tasks/tool.rake
r2-oas-0.3.2 lib/r2-oas/tasks/tool.rake