Class: PathItem
Instance Method Summary collapse
- #check_parameters(path) ⇒ Object
-
#initialize(parent, summary = nil, ref: nil) ⇒ PathItem
constructor
A new instance of PathItem.
- #parameter(name = nil, ref: nil, **named, &block) ⇒ Object
- #path(url, summary = nil, **named, &block) ⇒ Object
- #to_spec ⇒ Object
Methods included from ServerMethods
Constructor Details
#initialize(parent, summary = nil, ref: nil) ⇒ PathItem
Returns a new instance of PathItem.
16 17 18 19 20 21 |
# File 'lib/tiki/path-item.rb', line 16 def initialize(parent, summary = nil, ref: nil) @parameters = [] @parent = parent @summary = summary @ref = ref end |
Instance Method Details
#check_parameters(path) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/tiki/path-item.rb', line 64 def check_parameters(path) parameters = @parent.parameters + @parameters params = path.scan(/\{([a-zA-Z0-9_]+)\}/).map(&:first) params.each do |param| @parameters << Parameter.new(param, in: :path) unless parameters.find { |p| p.get_name == param } end end |
#parameter(name = nil, ref: nil, **named, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tiki/path-item.rb', line 32 def parameter(name = nil, ref: nil, **named, &block) if ref reference = Reference.new ref @parameters.push reference else named[:in] ||= :path parameter = Parameter.new name, **named parameter.instance_eval(&block) if block @parameters.push parameter end end |
#path(url, summary = nil, **named, &block) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/tiki/path-item.rb', line 44 def path(url, summary = nil, **named, &block) child = @parent.child url, @parameters path = PathItem.new child, summary, **named path.instance_eval(&block) if block child.add path end |
#to_spec ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/tiki/path-item.rb', line 51 def to_spec if @ref { :$ref => @ref } else props = @operations&.map(&->((n, s)) { { n => s.to_spec } })&.inject(&:merge) || {} parameters = @parent.parameters + @parameters props[:parameters] = parameters.map(&:to_spec) unless parameters.empty? scalar_props props array_props props props end end |