module OasRails::JsonSchemaGenerator

def self.to_json_schema(parsed)

Returns:
  • (Hash) - The JSON schema representation of the parsed data type.

Parameters:
  • parsed (Hash) -- The parsed data type hash.
def self.to_json_schema(parsed)
  case parsed[:type]
  when :object
    schema = {
      type: 'object',
      properties: {}
    }
    required_props = []
    parsed[:properties].each do |key, value|
      schema[:properties][key] = to_json_schema(value)
      required_props << key.to_s if value[:required]
    end
    schema[:required] = required_props unless required_props.empty?
    schema
  when :array
    {
      type: 'array',
      items: to_json_schema(parsed[:items])
    }
  else
    ruby_type_to_json_schema_type(parsed[:type])
  end
end