Module: OpenApi::DSL::SchemaObjHelpers
- Included in:
- SchemaObj
- Defined in:
- lib/oas_objs/schema_obj_helpers.rb
Instance Method Summary collapse
- #array_type(t) ⇒ Object
- #auto_generate_desc ⇒ Object
- #hash_type(t) ⇒ Object
- #obj_type(t) ⇒ Object
- #str_range_to_a(val) ⇒ Object
Instance Method Details
#array_type(t) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/oas_objs/schema_obj_helpers.rb', line 32 def array_type(t) { type: 'array', items: recg_schema_type(t.one? ? t[0] : { one_of: t }) } end |
#auto_generate_desc ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/oas_objs/schema_obj_helpers.rb', line 45 def auto_generate_desc if @bang_enum.is_a?(Hash) @bang_enum.each_with_index do |(info, value), index| self._desc = _desc + "<br/>#{index + 1}/ #{info}: #{value}" end else @bang_enum.each_with_index { |value, index| self._desc = _desc + "<br/>#{index + 1}/ #{value}" } end _desc end |
#hash_type(t) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/oas_objs/schema_obj_helpers.rb', line 6 def hash_type(t) # For supporting this: # form 'desc', type: { # id!: { type: Integer, enum: 0..5, desc: 'user id' } # }, should have description within schema if t.key?(:type) SchemaObj.new(t[:type], t).process # For supporting combined schema in nested schema. elsif (t.keys & i[ one_of any_of all_of not ]).present? CombinedSchema.new(t).process else obj_type(t) end end |
#obj_type(t) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/oas_objs/schema_obj_helpers.rb', line 22 def obj_type(t) obj_type = { type: 'object', properties: { }, required: [ ] } t.each do |prop_name, prop_type| obj_type[:required] << prop_name.to_s.delete('!') if prop_name['!'] obj_type[:properties][prop_name.to_s.delete('!').to_sym] = recg_schema_type(prop_type) end obj_type.keep_if &value_present end |
#str_range_to_a(val) ⇒ Object
39 40 41 42 43 |
# File 'lib/oas_objs/schema_obj_helpers.rb', line 39 def str_range_to_a(val) val_class = val.first.class action = :"to_#{val_class.to_s.downcase[0]}" (val.first.to_s..val.last.to_s).to_a.map(&action) end |