package yocaml

  1. Overview
  2. Docs

To attach additional content to documents, YOCaml uses a Metadata mechanism. Generally, the formats used for this kind of metadata (Yaml, JSON or even TOML) can be abstractly represented as abstract objects, like a key-value table.

This module abstracts the validation logic and the representation for key-value structured data.

Validation

To be able to validate structured data, one must first provide visitors for each data type supported by the metadata description logic.

type ('a, 'b, 'c) visitor = ('b -> 'c) -> (unit -> 'c) -> 'a -> 'c

A visitor takes a structured data structure and if it respects the expected schema, applies a function with the extracted data, otherwise it applies another function. In a slightly less generic way, the function that acts on the extracted data can act as a validation and the one that is applied in case of non respect of the structure is the failure function.

The set of visitors for a key-value structurable object

module type VALIDABLE = sig ... end

Creating a set of validators for a key-value structure only involves implementing the VALIDABLE module.

Description of a set of validation rules

If we have a representation of a key-value object (VALIDABLE) we can derive the API of its validator.

module type VALIDATOR = sig ... end

The full API derived by operating a representation.

Producing a concrete module of validation rules

Produces a module from a module with type VALIDABLE to a module with type VALIDATOR.

module Make_validator (KV : VALIDABLE) : VALIDATOR with type t = KV.t

Representation

Provides the minimal combinators to describe a key-value object.

module type DESCRIBABLE = sig ... end

Jsonm

The representation proposed by the Jsonm library has become so popular that it is the representation used for ocaml-mustache and ocaml-yaml. As the AST is described by means of polymorphic variants, it is possible to provide validators without the need to depend on the library.

Structure description

module Jsonm_object : sig ... end

Validators

Descriptor

OCaml

Innovation. Community. Security.