Sha256: 3b8db88ec83eb5b18679fc7c68bcc626a6e0fbdf6a85e9f76d4fccf94cf34d42

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module OpenApi
  module Rswag
    module Specs
      class Configuration
        def initialize(rspec_config)
          @rspec_config = rspec_config
        end

        def swagger_root
          @swagger_root ||= begin
            if @rspec_config.swagger_root.nil?
              raise ConfigurationError, 'No swagger_root provided. See swagger_helper.rb'
            end

            @rspec_config.swagger_root
          end
        end

        def swagger_docs
          @swagger_docs ||= begin
            if @rspec_config.swagger_docs.nil? || @rspec_config.swagger_docs.empty?
              raise ConfigurationError, 'No swagger_docs defined. See swagger_helper.rb'
            end

            @rspec_config.swagger_docs
          end
        end

        def swagger_dry_run
          @swagger_dry_run ||= begin
            @rspec_config.swagger_dry_run.nil? || @rspec_config.swagger_dry_run
          end
        end

        def get_swagger_doc(name)
          return swagger_docs.values.first if name.nil?
          raise ConfigurationError, "Unknown swagger_doc '#{name}'" unless swagger_docs[name]

          swagger_docs[name]
        end
      end

      class ConfigurationError < StandardError; end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
open_api-rswag-specs-0.1.0 lib/open_api/rswag/specs/configuration.rb
open_api-rswag-specs-0.0.6 lib/open_api/rswag/specs/configuration.rb
open_api-rswag-specs-0.0.5 lib/open_api/rswag/specs/configuration.rb
open_api-rswag-specs-0.0.4 lib/open_api/rswag/specs/configuration.rb