Class: AppMap::Swagger::Configuration

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

Constant Summary collapse

DEFAULT_VERSION =
'1.0'
DEFAULT_OUTPUT_DIR =
'swagger'
DEFAULT_DESCRIPTION =
'Generate Swagger from AppMaps'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



25
26
27
28
29
30
# File 'lib/appmap/swagger/configuration.rb', line 25

def initialize
  @project_name = nil
  @project_version = DEFAULT_VERSION
  @output_dir = DEFAULT_OUTPUT_DIR
  @description = DEFAULT_DESCRIPTION
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



10
11
12
# File 'lib/appmap/swagger/configuration.rb', line 10

def description
  @description
end

#output_dirObject

Returns the value of attribute output_dir.



10
11
12
# File 'lib/appmap/swagger/configuration.rb', line 10

def output_dir
  @output_dir
end

#project_nameObject



32
33
34
# File 'lib/appmap/swagger/configuration.rb', line 32

def project_name
  @project_name || default_project_name
end

#project_versionObject

Returns the value of attribute project_version.



10
11
12
# File 'lib/appmap/swagger/configuration.rb', line 10

def project_version
  @project_version
end

#templateObject



36
37
38
# File 'lib/appmap/swagger/configuration.rb', line 36

def template
  @template || default_template
end

Class Method Details

.load(config_data) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/appmap/swagger/configuration.rb', line 16

def load(config_data)
  Configuration.new.tap do |config|
    config_data.each do |k,v|
      config.send "#{k}=", v
    end
  end
end

Instance Method Details

#default_project_nameObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/appmap/swagger/configuration.rb', line 56

def default_project_name
  # https://www.rubydoc.info/docs/rails/Module#module_parent_name-instance_method
  module_parent_name = ->(cls) { cls.name =~ /::[^:]+\Z/ ? $`.freeze : nil }

  # Lazy-evaluate this so that Rails.application will be defined.
  # If this code runs too early in the lifecycle, Rails.application is nil.
  if defined?(::Rails)
    [module_parent_name.(::Rails.application.class).humanize.titleize, "API"].join(" ")
  else
    "MyProject API"
  end
end

#default_templateObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/appmap/swagger/configuration.rb', line 40

def default_template
  YAML.load "    openapi: 3.0.1\n    info:\n      title: \#{project_name}\n      version: \#{project_version}\n    paths:\n    components:\n    servers:\n    - url: http://{defaultHost}\n      variables:\n        defaultHost:\n          default: localhost:3000\n    TEMPLATE\nend\n"