Class: RSpec::Swag::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/swag/configuration.rb

Instance Method Summary collapse

Constructor Details

#initialize(rspec_config) ⇒ Configuration

Returns a new instance of Configuration.



6
7
8
# File 'lib/rspec/swag/configuration.rb', line 6

def initialize(rspec_config)
  @rspec_config = rspec_config
end

Instance Method Details

#get_openapi_spec(name) ⇒ Object

Raises:



47
48
49
50
51
52
# File 'lib/rspec/swag/configuration.rb', line 47

def get_openapi_spec(name)
  return openapi_specs.values.first if name.nil?
  raise ConfigurationError, "Unknown openapi_spec '#{name}'" unless openapi_specs[name]

  openapi_specs[name]
end

#get_openapi_spec_version(name) ⇒ Object



54
55
56
57
# File 'lib/rspec/swag/configuration.rb', line 54

def get_openapi_spec_version(name)
  doc = get_openapi_spec(name)
  doc[:openapi] || doc[:swagger]
end

#openapi_formatObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rspec/swag/configuration.rb', line 33

def openapi_format
  @openapi_format ||= begin
    if @rspec_config.openapi_format.nil? || @rspec_config.openapi_format.empty?
      @rspec_config.openapi_format = :json
    end

    unless [:json, :yaml].include?(@rspec_config.openapi_format)
      raise ConfigurationError, "Unknown openapi_format '#{@rspec_config.openapi_format}'"
    end

    @rspec_config.openapi_format
  end
end

#openapi_rootObject



10
11
12
13
# File 'lib/rspec/swag/configuration.rb', line 10

def openapi_root
  @openapi_root ||=
    @rspec_config.openapi_root || raise(ConfigurationError, "No openapi_root provided. See swagger_helper.rb")
end

#openapi_specsObject



15
16
17
18
19
20
21
22
23
# File 'lib/rspec/swag/configuration.rb', line 15

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

    @rspec_config.openapi_specs
  end
end

#openapi_strict_schema_validationObject



59
60
61
# File 'lib/rspec/swag/configuration.rb', line 59

def openapi_strict_schema_validation
  @rspec_config.openapi_strict_schema_validation || false
end

#swagger_dry_runObject



25
26
27
28
29
30
31
# File 'lib/rspec/swag/configuration.rb', line 25

def swagger_dry_run
  @swagger_dry_run ||= begin
    @rspec_config.swagger_dry_run = ENV["SWAGGER_DRY_RUN"] == "1" if ENV.key?("SWAGGER_DRY_RUN")

    @rspec_config.swagger_dry_run.nil? || @rspec_config.swagger_dry_run
  end
end