Class: OpenapiRuby::DSL::Context
- Inherits:
-
Object
- Object
- OpenapiRuby::DSL::Context
- 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
-
#operations ⇒ Object
readonly
Returns the value of attribute operations.
-
#path_parameters ⇒ Object
readonly
Returns the value of attribute path_parameters.
-
#path_template ⇒ Object
readonly
Returns the value of attribute path_template.
-
#schema_name ⇒ Object
readonly
Returns the value of attribute schema_name.
Instance Method Summary collapse
-
#initialize(path_template, schema_name: nil) ⇒ Context
constructor
A new instance of Context.
- #parameter(attributes = {}) ⇒ Object
- #to_openapi ⇒ Object
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
#operations ⇒ Object (readonly)
Returns the value of attribute operations.
6 7 8 |
# File 'lib/openapi_ruby/dsl/context.rb', line 6 def operations @operations end |
#path_parameters ⇒ Object (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_template ⇒ Object (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_name ⇒ Object (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_openapi ⇒ Object
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 |