Class: OasCore::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Configuration

Returns a new instance of Configuration.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/oas_core/configuration.rb', line 16

def initialize(**args)
  @info = args.fetch(:info, Spec::Info.new)
  @servers = args.fetch(:servers, default_servers)
  @tags = []
  @swagger_version = '3.1.0'
  @default_tags_from = :namespace
  @api_path = '/'
  @authenticate_all_routes_by_default = true
  @security_schema = nil
  @security_schemas = {}
  @set_default_responses = true
  @possible_default_responses = i[not_found unauthorized forbidden internal_server_error
                                   unprocessable_entity]
  @http_verbs = i[get post put patch delete]
  @response_body_of_default = 'Hash{ status: !Integer, error: String }'

  @possible_default_responses.each do |response|
    method_name = "response_body_of_#{response}="
    variable_name = "@response_body_of_#{response}"

    define_singleton_method(method_name) do |value|
      raise ArgumentError, "#{method_name} must be a String With a valid object" unless value.is_a?(String)

      OasCore::JsonSchemaGenerator.parse_type(value)
      instance_variable_set(variable_name, value)
    end

    define_singleton_method("response_body_of_#{response}") do
      instance_variable_get(variable_name) || @response_body_of_default
    end
  end
end

Instance Attribute Details

#api_pathObject

Returns the value of attribute api_path.



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

def api_path
  @api_path
end

#authenticate_all_routes_by_defaultObject

Returns the value of attribute authenticate_all_routes_by_default.



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

def authenticate_all_routes_by_default
  @authenticate_all_routes_by_default
end

#default_tags_fromObject

Returns the value of attribute default_tags_from.



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

def default_tags_from
  @default_tags_from
end

#http_verbsObject

Returns the value of attribute http_verbs.



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

def http_verbs
  @http_verbs
end

#infoObject

Returns the value of attribute info.



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

def info
  @info
end

#possible_default_responsesObject

Returns the value of attribute possible_default_responses.



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

def possible_default_responses
  @possible_default_responses
end

#response_body_of_defaultObject

Returns the value of attribute response_body_of_default.



14
15
16
# File 'lib/oas_core/configuration.rb', line 14

def response_body_of_default
  @response_body_of_default
end

#security_schemaObject

Returns the value of attribute security_schema.



14
15
16
# File 'lib/oas_core/configuration.rb', line 14

def security_schema
  @security_schema
end

#security_schemasObject

Returns the value of attribute security_schemas.



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

def security_schemas
  @security_schemas
end

#serversObject

Returns the value of attribute servers.



14
15
16
# File 'lib/oas_core/configuration.rb', line 14

def servers
  @servers
end

#set_default_responsesObject

Returns the value of attribute set_default_responses.



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

def set_default_responses
  @set_default_responses
end

#tagsObject

Returns the value of attribute tags.



14
15
16
# File 'lib/oas_core/configuration.rb', line 14

def tags
  @tags
end

Instance Method Details

#default_serversObject



55
56
57
# File 'lib/oas_core/configuration.rb', line 55

def default_servers
  [Spec::Server.new(url: 'http://localhost:3000', description: 'Development Server')]
end