Class: Docit::Configuration

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

Overview

Holds global API documentation settings: metadata, authentication, tags, and servers.

Constant Summary collapse

SUPPORTED_UIS =
%i[scalar swagger].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/docit/configuration.rb', line 12

def initialize
  @title = "API Documentation"
  @version = "1.0.0"
  @description = "Welcome to the API documentation. Browse the endpoints below to get started."
  @base_url = "/"
  @system_graph_enabled = true
  @system_graph_excluded_paths = []
  @default_ui = :scalar
  @security_schemes = {}
  @tags = []
  @servers = []
  @license = nil
  @contact = nil
  @terms_of_service = nil
end

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



8
9
10
# File 'lib/docit/configuration.rb', line 8

def base_url
  @base_url
end

#default_uiObject

Returns the value of attribute default_ui.



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

def default_ui
  @default_ui
end

#descriptionObject

Returns the value of attribute description.



8
9
10
# File 'lib/docit/configuration.rb', line 8

def description
  @description
end

#system_graph_enabledObject

Returns the value of attribute system_graph_enabled.



8
9
10
# File 'lib/docit/configuration.rb', line 8

def system_graph_enabled
  @system_graph_enabled
end

#system_graph_excluded_pathsObject

Returns the value of attribute system_graph_excluded_paths.



8
9
10
# File 'lib/docit/configuration.rb', line 8

def system_graph_excluded_paths
  @system_graph_excluded_paths
end

#titleObject

Returns the value of attribute title.



8
9
10
# File 'lib/docit/configuration.rb', line 8

def title
  @title
end

#versionObject

Returns the value of attribute version.



8
9
10
# File 'lib/docit/configuration.rb', line 8

def version
  @version
end

Instance Method Details

#auth(type, **options) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/docit/configuration.rb', line 37

def auth(type, **options)
  case type.to_s.downcase
  when "basic"
    @security_schemes[:basic_auth] = {
      type: "http",
      scheme: "basic"
    }
  when "bearer"
    @security_schemes[:bearer_auth] = {
      type: "http",
      scheme: "bearer",
      bearerFormat: options[:bearer_format] || "JWT"
    }
  when "api_key"
    @security_schemes[:api_key] = {
      type: "apiKey",
      name: options[:name] || "X-API-Key",
      in: options[:location] || "header"
    }
  else
    raise ArgumentError, "Unsupported auth type: #{type}"
  end
end

#contact(name: nil, email: nil, url: nil) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/docit/configuration.rb', line 95

def contact(name: nil, email: nil, url: nil)
  entry = {}
  entry[:name] = name if name
  entry[:email] = email if email
  entry[:url] = url if url
  @contact = entry
end

#contact_infoObject



103
104
105
# File 'lib/docit/configuration.rb', line 103

def contact_info
  @contact&.dup
end

#license(name:, url: nil) ⇒ Object



85
86
87
88
89
# File 'lib/docit/configuration.rb', line 85

def license(name:, url: nil)
  entry = { name: name }
  entry[:url] = url if url
  @license = entry
end

#license_infoObject



91
92
93
# File 'lib/docit/configuration.rb', line 91

def license_info
  @license&.dup
end

#security_schemesObject



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

def security_schemes
  @security_schemes.dup
end

#server(url, description: nil) ⇒ Object



75
76
77
78
79
# File 'lib/docit/configuration.rb', line 75

def server(url, description: nil)
  entry = { url: url.to_s }
  entry[:description] = description if description
  @servers << entry
end

#serversObject



81
82
83
# File 'lib/docit/configuration.rb', line 81

def servers
  @servers.dup
end

#tag(name, description: nil) ⇒ Object



65
66
67
68
69
# File 'lib/docit/configuration.rb', line 65

def tag(name, description: nil)
  entry = { name: name.to_s }
  entry[:description] = description if description
  @tags << entry
end

#tagsObject



71
72
73
# File 'lib/docit/configuration.rb', line 71

def tags
  @tags.dup
end

#terms_of_service(url) ⇒ Object



107
108
109
# File 'lib/docit/configuration.rb', line 107

def terms_of_service(url)
  @terms_of_service = url
end

#terms_of_service_urlObject



111
112
113
# File 'lib/docit/configuration.rb', line 111

def terms_of_service_url
  @terms_of_service
end