class GovukSchemas::Schema

def self.all(schema_type: "*")

Returns:
  • (Array) - List of JSON schemas as hashes

Parameters:
  • schema_type (String) -- The type: frontend, publisher, notification or links
def self.all(schema_type: "*")
  schema_type = "publisher_v2" if schema_type == "publisher"
  Dir.glob("#{GovukSchemas.content_schema_dir}/dist/formats/*/#{schema_type}/*.json").each_with_object({}) do |file_path, hash|
    hash[file_path] = JSON.parse(File.read(file_path))
  end
end

def self.find(schema)

Returns:
  • (Hash) - the JSON schema as a hash

Parameters:
  • schema (Hash) -- Type => Name of the schema/format:
def self.find(schema)
  file_path = "#{GovukSchemas.content_schema_dir}/dist/formats/#{location_for_schema_name(schema)}"
  JSON.parse(File.read(file_path))
end

def self.location_for_schema_name(schema)

Other tags:
    Private: -
def self.location_for_schema_name(schema)
  type, schema_name = schema.to_a.flatten
  {
    links_schema: "#{schema_name}/publisher_v2/links.json",
    frontend_schema: "#{schema_name}/frontend/schema.json",
    publisher_schema: "#{schema_name}/publisher_v2/schema.json",
    notification_schema: "#{schema_name}/notification/schema.json",
  }[type]
end

def self.random_schema(schema_type:)

Returns:
  • (Hash) - a JSON schema as a hash

Parameters:
  • schema_type (String) -- The type: frontend, publisher, notification or links
def self.random_schema(schema_type:)
  all(schema_type:).values.sample
end

def self.schema_names

Returns:
  • (Array) - all the schema names
def self.schema_names
  Dir.glob("#{GovukSchemas.content_schema_dir}/dist/formats/*").map do |directory|
    File.basename(directory)
  end
end