Class: Miniswag::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
11
12
13
14
15
16
# File 'lib/miniswag/configuration.rb', line 9

def initialize
  @openapi_root = nil
  @openapi_specs = {}
  @openapi_format = :json
  @openapi_all_properties_required = false
  @openapi_no_additional_properties = false
  @dry_run = ENV.key?('MINISWAG_DRY_RUN') ? ENV['MINISWAG_DRY_RUN'] == '1' : true
end

Instance Attribute Details

#dry_runObject

Returns the value of attribute dry_run.



5
6
7
# File 'lib/miniswag/configuration.rb', line 5

def dry_run
  @dry_run
end

#openapi_all_properties_requiredObject

Returns the value of attribute openapi_all_properties_required.



5
6
7
# File 'lib/miniswag/configuration.rb', line 5

def openapi_all_properties_required
  @openapi_all_properties_required
end

#openapi_formatObject

Returns the value of attribute openapi_format.



5
6
7
# File 'lib/miniswag/configuration.rb', line 5

def openapi_format
  @openapi_format
end

#openapi_no_additional_propertiesObject

Returns the value of attribute openapi_no_additional_properties.



5
6
7
# File 'lib/miniswag/configuration.rb', line 5

def openapi_no_additional_properties
  @openapi_no_additional_properties
end

#openapi_rootObject

Returns the value of attribute openapi_root.



5
6
7
# File 'lib/miniswag/configuration.rb', line 5

def openapi_root
  @openapi_root
end

#openapi_specsObject

Returns the value of attribute openapi_specs.



5
6
7
# File 'lib/miniswag/configuration.rb', line 5

def openapi_specs
  @openapi_specs
end

Instance Method Details

#get_openapi_spec(name) ⇒ Object

Raises:



18
19
20
21
22
23
# File 'lib/miniswag/configuration.rb', line 18

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

#validate!Object

Raises:



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

def validate!
  raise ConfigurationError, 'No openapi_root provided. See openapi_helper.rb' if openapi_root.nil?
  if openapi_specs.nil? || openapi_specs.empty?
    raise ConfigurationError, 'No openapi_specs defined. See openapi_helper.rb'
  end
  return if %i[json yaml].include?(openapi_format)

  raise ConfigurationError, "Unknown openapi_format '#{openapi_format}'"
end