module Croods::Resource::JsonSchema::Definition

Constants

TYPES

Public Class Methods

converted_types(type) click to toggle source
# File lib/croods/resource/json_schema/definition.rb, line 52
def converted_types(type)
  TYPES[type] || [type.to_s]
end
format(attribute) click to toggle source
# File lib/croods/resource/json_schema/definition.rb, line 29
def format(attribute)
  case attribute.type
  when :datetime
    { format: 'date-time' }
  when :date
    { format: 'date' }
  else
    {}
  end
end
items(attribute) click to toggle source
# File lib/croods/resource/json_schema/definition.rb, line 23
def items(attribute)
  return {} unless %i[json jsonb].include?(attribute.type)

  { items: { type: %w[string number object] } }
end
schema(attribute) click to toggle source
# File lib/croods/resource/json_schema/definition.rb, line 17
def schema(attribute)
  { type: types(attribute) }
    .merge(format(attribute))
    .merge(items(attribute))
end
types(attribute) click to toggle source
# File lib/croods/resource/json_schema/definition.rb, line 40
def types(attribute)
  types = []
  converted_types(attribute.type).each do |converted_type|
    types << converted_type
  end
  null = (
    attribute.null || attribute.default || attribute.default_function
  )
  types << 'null' if null
  types
end