module OpenApi::DSL::Helpers

Public Instance Methods

_combined_schema(one_of: nil, all_of: nil, any_of: nil, not: nil, **other) click to toggle source
# File lib/open_api/dsl/helpers.rb, line 27
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_enable(method) click to toggle source
# File lib/open_api/dsl/helpers.rb, line 59
def arrow_enable method
  alias_method :"_#{method}", method
  define_method method do |*args|
    arrow_writing_support.call(args, "_#{method}")
  end
end
arrow_writing_support() click to toggle source

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.
# File lib/open_api/dsl/helpers.rb, line 46
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
load_schema(model) click to toggle source
# File lib/open_api/dsl/helpers.rb, line 18
def load_schema(model) # TODO: test
  return unless Config.model_base && model.try(:superclass) == Config.model_base
  model.columns.map do |column|
      type = column.sql_type_metadata.type.to_s.camelize
      type = 'DateTime' if type == 'Datetime'
      [ column.name.to_sym, Object.const_get(type) ]
    end.to_h rescue ''
end
process_schema_input(schema_type, schema, name, model: nil) click to toggle source
# File lib/open_api/dsl/helpers.rb, line 32
def process_schema_input(schema_type, schema, name, model: nil)
  schema = { type: schema } unless schema.is_a?(Hash)
  combined_schema = _combined_schema(**schema)
  type = schema[:type] ||= schema_type
  return Tip.param_no_type(name) if type.nil? && combined_schema.nil?
  combined_schema || SchemaObj.new(type, load_schema(model) || schema)
end