Yocaml.Key_value
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.
To be able to validate structured data, one must first provide visitors for each data type supported by the metadata description logic.
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.
module type VALIDABLE = sig ... end
Creating a set of validators for a key-value structure only involves implementing the VALIDABLE
module.
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.
Produces a module from a module with type VALIDABLE
to a module with type VALIDATOR
.
Provides the minimal combinators to describe a key-value object.
module type DESCRIBABLE = sig ... end
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.
module Jsonm_object : sig ... end
module Jsonm_validator : VALIDATOR with type t = Jsonm_object.t
module Jsonm_descriptor : DESCRIBABLE with type t = Jsonm_object.t