rakelib/schemas.rake
# Recurses through a definition and JSON-ifies the data types.
Recurses through a definition and JSON-ifies the data types.
Recurses through a definition and JSON - ifies the data types .
def to_schema(data, plugin = false)
  return data unless data.is_a?(Hash)
  if data.key?(:_ref)
    data["$ref"] = "#/definitions/#{data.delete(:_ref)}"
  end
  metadata, data = data.partition do |key, _|
    key.to_s.start_with?('_')
  end.map(&:to_h)
  plugin = metadata[:_plugin] if metadata.key?(:_plugin)
  %i[items additionalProperties].each do |key|
    next unless data.key?(key)
    data[key] = to_schema(data[key], plugin)
  end
  %i[properties definitions].each do |key|
    next unless data.key?(key)
    data[key] = data[key].transform_values { |opt| to_schema(opt, plugin) }
  end
  data[:type] = to_json_types(data[:type]) if data.key?(:type)
  data = plugin ? add_plugin_reference(data) : data
  data.transform_keys(&:to_s)
end
def to_schema ( data , plugin = false ) return data unless data . is_a? ( Hash ) if data . key? ( :_ref ) data [ "$ref" ] = "#/definitions/#{data.delete(:_ref)}" end metadata , data = data . partition do | key , _ | key . to_s . start_with? ( '_' ) end . map ( & :to_h ) plugin = metadata [ :_plugin ] if metadata . key? ( :_plugin ) %i[ items additionalProperties ] . each do | key | next unless data . key? ( key ) data [ key ] = to_schema ( data [ key ] , plugin ) end %i[ properties definitions ] . each do | key | next unless data . key? ( key ) data [ key ] = data [ key ] . transform_values { | opt | to_schema ( opt , plugin ) } end data [ :type ] = to_json_types ( data [ :type ] ) if data . key? ( :type ) data = plugin ? add_plugin_reference ( data ) : data data . transform_keys ( & :to_s ) end
Recurses through a definition and JSON-ifies the data types.
Recurses through a definition and JSON - ifies the data types .
# Creates JSON references # Pull out all metadata since we don't want this in the schema. # Flip plugin to true if the definition allows a plugin reference. # This will allow plugin references for all sub-options and items. # Recurse through some properties, as each can have their own defintions. # Turn Ruby types into JSON types. # Add a plugin definition if supported by the option. # Stringify keys
data
<not_specific>
plugin
<not_specific>