Module: OpenApi::DSL::Helpers

Extended by:
ActiveSupport::Concern
Included in:
Api, CallbackObj, CombinedSchema, Components, ExampleObj, HeaderObj, ParamObj, RefObj, RequestBodyObj, ResponseObj
Defined in:
lib/open_api/dsl/helpers.rb

Instance Method Summary collapse

Instance Method Details

#_combined_schema(one_of: nil, all_of: nil, any_of: nil, not: nil, **other) ⇒ Object



18
19
20
21
# File 'lib/open_api/dsl/helpers.rb', line 18

def _combined_schema(one_of: nil, all_of: nil, any_of: nil, not: nil, **other)
  input = (_not = binding.local_variable_get(:not)) || one_of || all_of || any_of
  CombinedSchema.new(one_of: one_of, all_of: all_of, any_of: any_of, not: _not) if input
end

#arrow_writing_supportObject

Arrow Writing:

response :RespComponent => [ '200', 'success', :json ]

It is equivalent to:

response :RespComponent, '200', 'success', :json

But I think, in the definition of a component,

the key-value (arrow) writing is more easier to understand.


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/open_api/dsl/helpers.rb', line 40

def arrow_writing_support
  proc do |args, executor|
    args = (args.size == 1 && args.first.is_a?(Hash)) ? args[0].to_a.flatten : args

    if !executor.in?(%w[ _example _security_scheme _base_auth _bearer_auth ]) && args.last.is_a?(Hash)
      send(executor, *args[0..-2], **args[-1])
    else
      send(executor, *args)
    end
  end
end

#process_schema_input(schema_type, schema, name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/open_api/dsl/helpers.rb', line 23

def process_schema_input(schema_type, schema, name)
  if schema.is_a?(Hash)
    schema[:type] ||= schema_type
  else
    schema = { type: schema }
  end
  combined_schema = _combined_schema(**schema)
  return Tip.param_no_type(name) if schema[:type].nil? && combined_schema.nil?
  combined_schema || SchemaObj.new(schema[:type], schema)
end