Class: Rswag::Specs::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rswag/specs/configuration.rb

Instance Method Summary collapse

Constructor Details

#initialize(rspec_config) ⇒ Configuration

Returns a new instance of Configuration.



6
7
8
# File 'lib/rswag/specs/configuration.rb', line 6

def initialize(rspec_config)
  @rspec_config = rspec_config
end

Instance Method Details

#get_openapi_spec(name) ⇒ Object

Raises:



49
50
51
52
53
54
# File 'lib/rswag/specs/configuration.rb', line 49

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



56
57
58
59
# File 'lib/rswag/specs/configuration.rb', line 56

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

#openapi_all_properties_requiredObject



65
66
67
# File 'lib/rswag/specs/configuration.rb', line 65

def openapi_all_properties_required
  @rspec_config.openapi_all_properties_required || false
end

#openapi_formatObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rswag/specs/configuration.rb', line 35

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_no_additional_propertiesObject



69
70
71
# File 'lib/rswag/specs/configuration.rb', line 69

def openapi_no_additional_properties
  @rspec_config.openapi_no_additional_properties || false
end

#openapi_rootObject



10
11
12
13
# File 'lib/rswag/specs/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/rswag/specs/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



61
62
63
# File 'lib/rswag/specs/configuration.rb', line 61

def openapi_strict_schema_validation
  @rspec_config.openapi_strict_schema_validation || false
end

#rswag_dry_runObject



25
26
27
28
29
30
31
32
33
# File 'lib/rswag/specs/configuration.rb', line 25

def rswag_dry_run
  @rswag_dry_run ||= begin
    if ENV.key?('SWAGGER_DRY_RUN') || ENV.key?('RSWAG_DRY_RUN')
      @rspec_config.rswag_dry_run = ENV['SWAGGER_DRY_RUN'] == '1' || ENV['RSWAG_DRY_RUN'] == '1'
    end

    @rspec_config.rswag_dry_run.nil? || @rspec_config.rswag_dry_run
  end
end