Class: RswagSchemaExport::Export

Inherits:
Object
  • Object
show all
Defined in:
lib/rswag_schema_export/schema_export.rb

Instance Method Summary collapse

Instance Method Details

#runObject

rubocop:disable Metrics/AbcSize



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rswag_schema_export/schema_export.rb', line 3

def run # rubocop:disable Metrics/AbcSize
  abort("Set up RswagSchemaExport.config.schemas") unless RswagSchemaExport.config.schemas

  RswagSchemaExport.config.schemas.map do |schema|
    next if File.file?(schema)

    message = "Not found schema at #{schema}.
           For generate schema run: RAILS_ENV=test rake rswag:specs:swaggerize"
    abort(message)
  end

  begin
    client = ::RswagSchemaExport::Client.new(ENV["STAGE"])
    RswagSchemaExport.config.schemas.map do |schema|
      schema_id = schema.gsub(/[^a-zA-Z0-9\-]/, "_")
      key = "schemas/#{client.app_name}/#{client.stage}_#{schema_id}/versions/#{Time.now.getutc.iso8601}.json"
      # Upload latest version to the cloud
      client.upload_file(key, schema)

      puts("Schema has been successfully exported. Stage: #{client.stage} | Key: #{key}")
    end
    puts("Export finished")
  rescue StandardError => e
    abort(e.message)
  end
end