Sha256: 46714c3389f0ee3459f536d716669b7a396ceab58be702eac27a4d501787538a

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module PUNK
  class GenerateSwaggerService < Service
    def process
      path = File.join(PUNK.get.app.path, '..', 'www', 'swagger.json')
      raise InternalServerError, 'swagger.json already exists' if File.exist?(path) && !PUNK.env.test?
      require 'swagger_yard'
      require_relative '../helpers/swagger'
      SwaggerYard.register_custom_yard_tags!
      SwaggerYard.configure do |config|
        config.api_version = PUNK.version
        config.title = PUNK.get.app.name
        config.description = PUNK.get.app.description
        config.api_base_path = PUNK.get.app.url
        config.controller_path = [File.join(PUNK.get.app.path, 'routes', '**', '*'), File.join(__dir__, '..', 'routes', '**', '*')]
        config.model_path = [File.join(__dir__, '..', 'models', '**', '*'), File.join(__dir__, '..', 'views', '**', '*'), File.join(PUNK.get.app.path, 'models', '**', '*')]
      end
      spec = SwaggerYard::OpenAPI.new
      blob = JSON.pretty_generate(spec.to_h)
      File.open(path, "w") { |f| f << blob } unless PUNK.env.test?
      blob
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
punk-0.3.6 lib/punk/services/generate_swagger.rb
punk-0.3.5 lib/punk/services/generate_swagger.rb
punk-0.3.4 lib/punk/services/generate_swagger.rb
punk-0.3.3 lib/punk/services/generate_swagger.rb
punk-0.3.2 lib/punk/services/generate_swagger.rb
punk-0.3.1 lib/punk/services/generate_swagger.rb
punk-0.2.0 lib/punk/services/generate_swagger.rb