Class: OpenapiRuby::DSL::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_ruby/dsl/context.rb

Constant Summary collapse

HTTP_METHODS =
%i[get post put patch delete head options trace].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path_template, schema_name: nil) ⇒ Context

Returns a new instance of Context.



10
11
12
13
14
15
# File 'lib/openapi_ruby/dsl/context.rb', line 10

def initialize(path_template, schema_name: nil)
  @path_template = path_template
  @schema_name = schema_name
  @operations = {}
  @path_parameters = []
end

Instance Attribute Details

#operationsObject (readonly)

Returns the value of attribute operations.



6
7
8
# File 'lib/openapi_ruby/dsl/context.rb', line 6

def operations
  @operations
end

#path_parametersObject (readonly)

Returns the value of attribute path_parameters.



6
7
8
# File 'lib/openapi_ruby/dsl/context.rb', line 6

def path_parameters
  @path_parameters
end

#path_templateObject (readonly)

Returns the value of attribute path_template.



6
7
8
# File 'lib/openapi_ruby/dsl/context.rb', line 6

def path_template
  @path_template
end

#schema_nameObject (readonly)

Returns the value of attribute schema_name.



6
7
8
# File 'lib/openapi_ruby/dsl/context.rb', line 6

def schema_name
  @schema_name
end

Instance Method Details

#parameter(attributes = {}) ⇒ Object



17
18
19
20
21
# File 'lib/openapi_ruby/dsl/context.rb', line 17

def parameter(attributes = {})
  param = deep_stringify(attributes)
  param["required"] = true if param["in"] == "path"
  @path_parameters << param
end

#to_openapiObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/openapi_ruby/dsl/context.rb', line 34

def to_openapi
  result = {}

  result["parameters"] = @path_parameters if @path_parameters.any?

  @operations.each do |verb, op|
    result[verb] = op.to_openapi
  end

  result
end