Class: Docit::Configuration
- Inherits:
-
Object
- Object
- Docit::Configuration
- 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
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#default_ui ⇒ Object
Returns the value of attribute default_ui.
-
#description ⇒ Object
Returns the value of attribute description.
-
#title ⇒ Object
Returns the value of attribute title.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #auth(type, **options) ⇒ Object
- #contact(name: nil, email: nil, url: nil) ⇒ Object
- #contact_info ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #license(name:, url: nil) ⇒ Object
- #license_info ⇒ Object
- #security_schemes ⇒ Object
- #server(url, description: nil) ⇒ Object
- #servers ⇒ Object
- #tag(name, description: nil) ⇒ Object
- #tags ⇒ Object
- #terms_of_service(url) ⇒ Object
- #terms_of_service_url ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/docit/configuration.rb', line 11 def initialize @title = "API Documentation" @version = "1.0.0" @description = "Welcome to the API documentation. Browse the endpoints below to get started." @base_url = "/" @default_ui = :scalar @security_schemes = {} @tags = [] @servers = [] @license = nil @contact = nil @terms_of_service = nil end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
8 9 10 |
# File 'lib/docit/configuration.rb', line 8 def base_url @base_url end |
#default_ui ⇒ Object
Returns the value of attribute default_ui.
9 10 11 |
# File 'lib/docit/configuration.rb', line 9 def default_ui @default_ui end |
#description ⇒ Object
Returns the value of attribute description.
8 9 10 |
# File 'lib/docit/configuration.rb', line 8 def description @description end |
#title ⇒ Object
Returns the value of attribute title.
8 9 10 |
# File 'lib/docit/configuration.rb', line 8 def title @title end |
#version ⇒ Object
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
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/docit/configuration.rb', line 34 def auth(type, **) 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: [:bearer_format] || "JWT" } when "api_key" @security_schemes[:api_key] = { type: "apiKey", name: [:name] || "X-API-Key", in: [:location] || "header" } else raise ArgumentError, "Unsupported auth type: #{type}" end end |
#contact(name: nil, email: nil, url: nil) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/docit/configuration.rb', line 92 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_info ⇒ Object
100 101 102 |
# File 'lib/docit/configuration.rb', line 100 def contact_info @contact&.dup end |
#license(name:, url: nil) ⇒ Object
82 83 84 85 86 |
# File 'lib/docit/configuration.rb', line 82 def license(name:, url: nil) entry = { name: name } entry[:url] = url if url @license = entry end |
#license_info ⇒ Object
88 89 90 |
# File 'lib/docit/configuration.rb', line 88 def license_info @license&.dup end |
#security_schemes ⇒ Object
58 59 60 |
# File 'lib/docit/configuration.rb', line 58 def security_schemes @security_schemes.dup end |
#server(url, description: nil) ⇒ Object
72 73 74 75 76 |
# File 'lib/docit/configuration.rb', line 72 def server(url, description: nil) entry = { url: url.to_s } entry[:description] = description if description @servers << entry end |
#servers ⇒ Object
78 79 80 |
# File 'lib/docit/configuration.rb', line 78 def servers @servers.dup end |
#tag(name, description: nil) ⇒ Object
62 63 64 65 66 |
# File 'lib/docit/configuration.rb', line 62 def tag(name, description: nil) entry = { name: name.to_s } entry[:description] = description if description @tags << entry end |
#tags ⇒ Object
68 69 70 |
# File 'lib/docit/configuration.rb', line 68 def @tags.dup end |
#terms_of_service(url) ⇒ Object
104 105 106 |
# File 'lib/docit/configuration.rb', line 104 def terms_of_service(url) @terms_of_service = url end |
#terms_of_service_url ⇒ Object
108 109 110 |
# File 'lib/docit/configuration.rb', line 108 def terms_of_service_url @terms_of_service end |