Method: Attributor::Type::ClassMethods#as_json_schema

Defined in:
lib/attributor/type.rb

#as_json_schema(shallow: false, example: nil, attribute_options: {}) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/attributor/type.rb', line 186

def as_json_schema( shallow: false, example: nil, attribute_options: {} )
  type_name = self.ancestors.find { |k| k.name && !k.name.empty? }.name
  hash = { type: json_schema_type, 'x-type_name': type_name.gsub( Attributor::MODULE_PREFIX_REGEX, '' )}
  # Add a format, if the type has defined
  if hash[:type] == :string && the_format = json_schema_string_format
    hash[:format] = the_format
  end
  # Common options
  hash[:enum] = attribute_options[:values] if attribute_options[:values]
  
  hash
end