A powerful schema validator!

Overview

MetaYaml

Latest Stable Version Build Status SensioLabsInsight

A [put your file type here] schema validator using [put another file type here] files.
At the moment, file type can be Json, Yaml, or XML. It can generate a documentation about the schema, or a XSD file (experimental).

The name comes from the fact that it was initially made to implement a pseudo-schema for Yaml files.

  1. Installation
  1. Basic usage
  2. How to write a schema
  1. Documentation generator
  2. Notes on XML support
  3. XSD generator
  4. Test
  5. Extending
  6. Thanks

Installation

It is a standalone component:

  • the core requires PHP >= 5.3.3
  • to use the YamlLoader, you will need the Symfony component Yaml (standalone component, does not require Symfony2)
  • to launch the tests, you'll need atoum

To install via composer just do composer require romaricdrigon/metayaml

Basic usage

You have to create a MetaYaml object, and then pass it both the schema and your data as multidimensional php arrays:

use RomaricDrigon\MetaYaml\MetaYaml;

// create object, load schema from an array
$schema = new MetaYaml($schema);

/*
    you can optionally validate the schema
    it can take some time (up to a second for a few hundred lines)
    so do it only once, and maybe only in development!
*/
$schema->validateSchema(); // return true or throw an exception

// you could also have done this at init
$schema = new MetaYaml($schema, true); // will load AND validate the schema

// finally, validate your data array according to the schema
$schema->validate($data); // return true or throw an exception

You can use any of the provided loaders to obtain these arrays (yep, you can validate XML using a schema from an Yaml file!).

Some loader examples:

use RomaricDrigon\MetaYaml\MetaYaml;
use RomaricDrigon\MetaYaml\Loader\YamlLoader;
use RomaricDrigon\MetaYaml\Loader\XmlLoader; // JsonLoader is already available

// create one loader object
$loader = new JsonLoader(); // Json (will use php json_decode)
$loader = new YamlLoader(); // Yaml using Symfony Yaml component
$loader = new XmlLoader(); // Xml (using php SimpleXml)

// the usage is the same then
$array = $loader->load('SOME STRING...');
// or you can load from a file
$array = $loader->loadFromFile('path/to/file');

How to write a schema

Introduction

A schema file will define the array structure (which elements are allowed, where), some attributes (required, can be empty...) and the possible values for these elements (or their type).

Here's a simple example of a schema, using Yaml syntax:

root: # root is always required (note no prefix here)
    _type: array # each element must always have a '_type'
    _children: # array nodes have a '_children' node, defining their children
        flowers:
            _type: array
            _required: true # optional, default false
            _children:
                rose:
                    _required: true
                    _type: text
                violet:
                    _type: text
                # -> only rose and violet are allowed children of flowers

And a valid Yaml file :

flowers:
    rose: "a rose"
    violet: "a violet flower"

We will continue with Yaml examples; if you're not familiar with the syntax, you may want to take a look at its Wikipedia page. Of course the same structure is possible with Json or XML, because the core is the same. Take a look at examples in test/data/ folder.

Schema structure

A schema file must have a root node, which will describe the first-level content. You can optionally define a prefix; by default it is _ (_type, _required...).

You have to define a partials node if you want to use this feature (learn more about it below).

A basic schema file:

root:
    # here put the elements who will be in the file
    # note that root can have any type: an array, a number, a prototype...
prefix: my_ # so it's gonna be 'my_type', 'my_required', 'my_children'...
partials:
    block:
        # here I define a partial called block

Schema nodes

Each node in the schema must have a _type attribute. Here I define a node called paragraph whose content is some text:

paragraph:
    _type: text

Those types are available:

  • text: scalar value
  • number: numeric value
  • boolean: boolean value
  • pattern: check if the value matches the regular expression provided in _pattern, which is a PCRE regex
  • enum: enumeration ; list accepted values in _values node
  • array: array; define children in a _children node; array's children must have determined named keys; any extra key will cause an error
  • prototype: define a repetition of items whose name/index is not important. You must give children's type in _prototype node.
  • choice: child node can be any of the nodes provided in _choices. Keys in _choices array are not important (as long as they are unique). In each choice, it's best to put the discriminating field in first.
  • partial: "shortcut" to a block described in partials root node. Provide partial name in _partial

You can specify additional attributes:

  • general attributes:
  • _required: this node must always be defined (by default false)
  • _not_empty for text, number and array nodes: they can't be empty (by default false). Respective empty values are '', 0 (as a string, an integer or a float), array(). To test for null values, use _required instead.
  • _strict with text, number, boolean and enum will enforce a strict type check (respectively, with a string, an integer or a float, a boolean, any of these values). Be careful when using these with a parser which may not be type-aware (such as the XML one; Yaml and json should be ok)
  • _description: full-text description, cf. Documentation generator
  • only for array nodes:
  • _ignore_extra_keys: the node can contain children whose keys are not listed in _children; they'll be ignored
  • only for prototype nodes:
  • min_items: the prototype node should contain at least 'min' elements
  • max_items: the opposite, the max number of elements in the prototype node (by default 200)

Here's a comprehensive example:

root:
    _type: array
    _children:
        SomeText:
            _type: text
            _not_empty: true # so !== ''
        SomeEnum:
            _type: enum
            _values:
                - windows
                - mac
                - linux
        SomeNumber:
            _type: number
            _strict: true
        SomeBool:
            _type: boolean
        SomePrototypeArray:
            _type: prototype
            _prototype:
                _type: array
                _children:
                    SomeOtherText:
                        _type: text
                        _is_required: true # can't be null
        SomeParagraph:
            _type: partial
            _partial: aBlock # cf 'partials' below
        SomeChoice:
            _type: choice
            _choices:
                1:
                    _type: enum
                    _values:
                        - windows
                        - linux
                2:
                    _type: number
                # so our node must be either #1 or #2
        SomeRegex:
            _type: pattern
            _pattern: /e/
partials:
    aBlock:
        _type: array
        _children:
            Line1:
                _type: text

More information

For more examples, look inside test/data folder. In each folder, you have an .yml file and its schema. There's also a XML example.

If you're curious about an advanced usage, you can check data/MetaSchema.json: schema files are validated using this schema (an yep, the schema validates successfully itself!)

Documentation generator

Each node can have a _description attribute, containing some human-readable text. You can retrieve the documentation about a node (its type, description, other attributes...) like this:

// it's recommended to validate the schema before reading documentation
$schema = new MetaYaml($schema, true);

// get documentation about root node
$schema->getDocumentationForNode();

// get documentation about a child node 'test' in an array 'a_test' under root
$schema->getDocumentationForNode(array('a_test', 'test'));

// finally, if you want to unfold (follow) all partials, set second argument to true
$schema->getDocumentationForNode(array('a_test', 'test'), true);
// watch out there's no loop inside partials!

It returns an associative array formatted like this:

array(
    'name' => 'test', // name of current node, root for first node
    'node' => array(
        '_type' => 'array',
        '_children' => ... // and so on
    ),
    'prefix' => '_'
)

If the targeted node is inside a choice, the result will differ slightly:

array(
    'name' => 'test', // name of current node, from the choice key in the schema
    'node' => array(
        '_is_choice' => 'true', // important: so we know next keys are choices
        0 => array(
            '_type' => 'array' // and so on, for first choice
        ),
        1 => array(
            '_type' => 'text' // and so on, for second choice
        ),
        // ...
    ),
    'prefix' => '_'
)

This behavior allow us to handle imbricated choices, without loosing data (you have an array level for each choice level, and you can check the flag _is_choice)

If you pass an invalid path (e.g. no node with the name you gave exist), it will throw an exception.

Notes on XML support

In XML, you can store a value in a node within a child element, or using an attribute. This is not possible in an array; the only way is to use a child.

Thus, the following conventions are enforced by the XML loader:

  • elements AND attributes are stored as child, using element name and content, or attribute name and value, as respectively key and value
  • if a node has an attribute and a child node with the same name, the attribute will be overwritten
  • if a node has both attribute(s) and a text content, text content will be stored under key _value
  • multiple child node with the same name will be overwritten, only the last will be retained; except if they have a _key attribute, which will be used thus
  • namespaces are not supported
  • empty nodes are skipped

Let's take an example:

<fleurs>
    <roses couleur="rose">
        <opera>une rose</opera>
        <sauvage>
            <des_bois>une autre rose</des_bois>
            <des_sous_bois sauvage="oui">encore</des_sous_bois>
        </sauvage>
    </roses>
    <tulipe>je vais disparaitre !</tulipe>
    <tulipe>deuxieme tulipe</tulipe>
    <fleur couleur="violette" sauvage="false" _key="violette">une violette</fleur>
</fleurs>

will give us this array:

array('fleurs' =>
    'roses' => array(
        'couleur' => 'rose',
        'sauvage' => array(
            'des_bois' => 'une autre rose',
            'des_sous_bois' => array(
                'sauvage' => 'oui',
                '_value' => 'encore'
            )
        )
    ),
    'tulipe' => 'deuxieme tulipe',
    'violette' => array(
        'couleur' => 'violette',
        'sauvage' => 'false',
        '_value' => 'une violette'
    )
)

XSD generator

Please note this feature is still experimental!

MetaYaml can try to generate a XML Schema Definition from a MetaYaml schema. You may want to use this file to pre-validate XML input, or to use in another context (client-side...). The same conventions (cf. above) will be used.

Usage example :

use RomaricDrigon\MetaYaml\MetaYaml\XsdGenerator;

// create a XsdGenerator object (requires Php XMLWriter from libxml, enabled by default)
$generator = new XsdGenerator();

// $schema is the source schema, php array
// second parameter to soft-indent generated XML (default true)
$my_xsd_string = $generator->build($schema, true);

A few limitations, some relative to XML Schema, apply:

  • root node must be an array
  • an element can't have a name beginning by a number
  • all first-level nodes will be mandatory (but they may be empty)
  • choice node are not supported
  • pattern may have a slightly different behavior due to implementations differences
  • prototype children nodes type will not be validated
  • strict mode does not exists
  • ignore_extra_keys attribute will cause all children nodes not to be validated

Test

The project is fully tested using atoum. To launch tests, just run in a shell ./bin/test -d test

Extending

You may want to write your own loader, using anything else.
Take a look at any class in Loader/ folder, it's pretty easy: you have to implement the LoaderInterface, and may want to extend Loader class (so you don't have to write loadFromFile()).

Thanks

Thanks to Riad Benguella and Julien Bianchi for their help & advice.

Top

Comments
  • Is it possible to validate that _type is a yaml sequence?

    Is it possible to validate that _type is a yaml sequence?

    It would be highly yaml loader specific, so I'm not sure it belongs in core, but we have the need to validate that a structure is a yaml sequence. Is this possible, and if so, how would I generally go about it?

    support 
    opened by psynaptic 7
  • Prototype with choices - impossible?

    Prototype with choices - impossible?

    I cannot declare a schema with prototype of choices.

                  'process' => [ '_type' => 'prototype', '_required' => TRUE, '_min_items' => 1, '_prototype' => [
                    '_type' => '_choice', '_required' => TRUE, '_choices' => [
                      0 => [ '_type' => 'array', '_required' => FALSE, '_ignore_extra_keys' => TRUE, '_children' => [
                        'plugin' => [ '_type' => 'text',  '_required' => TRUE ],
                      ]],
                      1 => [ '_type' => 'prototype', '_required' => FALSE, '_min_items' => 1, '_prototype' => [
                        '_type' => 'array', '_required' => FALSE, '_ignore_extra_keys' => TRUE, '_children' => [
                          'plugin' => [ '_type' => 'text',  '_required' => TRUE ],
                        ]
                      ]],
                    ]
                  ]],
    
    

    Is this is a documented limitation or a bug?

    opened by OnkelTem 3
  • Too slow

    Too slow

    I cannot say precisely why but MetaYaml is slow drastically. I know it's rather vague, but here is a sample output of an application which uses MetaYaml:

    Timer result:
    probe                           time, s  mem, Mb  time, %  mem, %  
    ------------------------------  -------  -------  -------  ------  
    TOTAL                            10.194     4.37   100.00   78.18  
    initDeck                          9.882     4.13    96.94   73.82  
    initDeck: validating schema       8.759     0.02    85.92    0.38  <<<
    initDeck: base schema validate    0.948     0.21     9.30    3.72  <<<
    initDeck: generator plugins       0.091     1.22     0.89   21.88  
    initDeck: execution tree          0.043     1.71     0.42   30.64  
    initDeck: service fields          0.035     1.00     0.34   17.81  
    initDeck: services                0.002     0.14     0.02    2.55 
    

    The app builds some dynamic YAMLs and validates them. Total run time is ~10s. Schemas validation takes ~95%.

    Any chances it can be optimized?

    opened by OnkelTem 1
  • Validating a mixed type array

    Validating a mixed type array

    Hello! I'm trying to write a partial to fit some of my data.

    I've got things like, which handles e.g. ['foo', 'bar']

    list_of_texts:
            _type: prototype
            _required: true
            _prototype:
                _type: text
    

    Or for [['foo', 'baz'], ['der', 'dum']]

    list_of_list_of_texts:
            _type: prototype
            _required: true
            _prototype:
                _type: prototype
                _required: true
                _prototype:
                    _type: text
    

    But I'm stuck on: ['foo', ['bing', 'bong']]

    Can I put a _choice inside a prototype somehow?

    opened by AppSynergy 1
  • Uncaught exception 'RomaricDrigon\MetaYaml\Exception\NodeValidatorException' with message 'The node 'root.book.generator.name' is not an array'

    Uncaught exception 'RomaricDrigon\MetaYaml\Exception\NodeValidatorException' with message 'The node 'root.book.generator.name' is not an array'

    # easybook_schema.yml
    root:
        _type: array
        _children:
            book:
                _type: array
                _children:
                    title:
                        _required: true
                        _type: text
                    author:
                        _type: text
                    edition:
                        _type: text
                    language:
                        _type: text
                    publication_date:
                        _type: text
                    generator:
                        _type: prototype
                        _prototype:
                            _type: array
                            _children:
                                name:
                                    _type: text
                                version:
                                    _type: text
                    contents:
                        _type: prototype
                        _prototype:
                            _type: array
                            _children:
                                name:
                                    _type: text
                                version:
                                    _type: text
                    editions:
                        _type: text
    
    # config.yml
    easybook:
        parameters:
            parser.options:
                code_block_type: fenced
    
    book:
        title:            easybook documentation
        author:           Javier Eguiluz
        edition:          First edition
        language:         en
        publication_date: ~
    
        generator: { name: easybook, version: 5.0 }
    
        contents:
            - { element: cover }
            - { element: toc   }
            - { element: chapter,  number: 1,  content: 01-publishing-your-first-book.md }
            - { element: chapter,  number: 2,  content: 02-book-contents-and-configuration.md }
            - { element: chapter,  number: 3,  content: 03-editions.md }
            - { element: chapter,  number: 4,  content: 04-themes.md }
            - { element: chapter,  number: 5,  content: 05-publishing-html-books.md }
            - { element: chapter,  number: 6,  content: 06-publishing-epub-books.md }
            - { element: chapter,  number: 7,  content: 07-publishing-mobi-books.md }
            - { element: chapter,  number: 8,  content: 08-publishing-pdf-books.md }
            - { element: chapter,  number: 9,  content: 09-plugins.md }
            - { element: chapter,  number: 10, content: 10-hacking-easybook.md }
            - { element: appendix, number: A,  content: A-markdown-reference.md }
    
        editions:
            kindle:
                extends:         ebook
                format:          mobi
    
            ebook:
                format:          epub
                include_styles:  true
                highlight_cache: true
                highlight_code:  false
                labels:          ['appendix', 'chapter', 'figure']
                theme:           clean
                toc:
                    deep:        1
                    elements:    ["appendix", "chapter"]
    
            print:
                format:          pdf
                highlight_cache: true
                highlight_code:  true
                isbn:            ~
                include_styles:  true
                labels:          ['appendix', 'chapter', 'figure']
                margin:
                    top:         25mm
                    bottom:      25mm
                    inner:       30mm
                    outter:      20mm
                page_size:       A4
                theme:           clean
                toc:
                    deep:        2
                    elements:    ["appendix", "chapter"]
                two_sided:       true
    
            web:
                format:          html
                include_styles:  true
                highlight_cache: true
                highlight_code:  true
                labels:          ['appendix', 'chapter', 'figure']
                theme:           clean
                toc:
                    deep:        2
                    elements:    ["appendix", "chapter"]
    
            website:
                extends:         web
                format:          html_chunked
                chunk_level:     1
                images_base_dir: /img/doc-en/
    
            easybook-project.org:
                format:          html_chunked
                chunk_level:     2
                images_base_dir: /images/doc-en/
                include_styles:  false
                highlight_cache: false
                highlight_code:  true
                labels:          ['appendix', 'chapter', 'figure']
                theme:           clean
                toc:
                    deep:        2
                    elements:    ["appendix", "chapter"]
    
    <?php
    
    include __DIR__.'/vendor/autoload.php';
    
    use RomaricDrigon\MetaYaml\MetaYaml;
    use RomaricDrigon\MetaYaml\Loader\YamlLoader;
    
    $loader = new YamlLoader(); // Yaml using Symfony Yaml component
    
    // or you can load from a file
    $schema = $loader->loadFromFile(__DIR__.'/easybook_schema.yml');
    $data = $loader->loadFromFile(__DIR__.'/config.yml');
    
    // create object, load schema from an array
    $schemaEngine = new MetaYaml($schema);
    $schemaEngine->validateSchema(); // return true or throw an exception
    
    // finally, validate your data array according to the schema
    $schemaEngine->validate($data); // return true or throw an exception
    
    echo "Successful validation";
    
    ~ php run.php                                                                               Luiss-MacBook-Pro-2 [3:30:28]
    PHP Fatal error:  Uncaught exception 'RomaricDrigon\MetaYaml\Exception\NodeValidatorException' with message 'The node 'root.book.generator.name' is not an array' in /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/NodeValidator/ArrayNodeValidator.php:14
    Stack trace:
    #0 /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/SchemaValidator.php(48): RomaricDrigon\MetaYaml\NodeValidator\ArrayNodeValidator->validate('root.book.gener...', Array, 'easybook')
    #1 /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/NodeValidator/PrototypeNodeValidator.php(30): RomaricDrigon\MetaYaml\SchemaValidator->validateNode('root.book.gener...', 'array', Array, 'easybook')
    #2 /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/SchemaValidator.php(48): RomaricDrigon\MetaYaml\NodeValidator\PrototypeNodeValidator->validate('root.book.gener...', Array, Array)
    #3 /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/NodeValidator/ArrayNodeValidator.php(24): RomaricDrigon\MetaYaml\SchemaVali in /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/NodeValidator/ArrayNodeValidator.php on line 14
    
    Fatal error: Uncaught exception 'RomaricDrigon\MetaYaml\Exception\NodeValidatorException' with message 'The node 'root.book.generator.name' is not an array' in /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/NodeValidator/ArrayNodeValidator.php on line 14
    
    RomaricDrigon\MetaYaml\Exception\NodeValidatorException: The node 'root.book.generator.name' is not an array in /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/NodeValidator/ArrayNodeValidator.php on line 14
    
    Call Stack:
        0.0002     231216   1. {main}() /Users/cordoval/Sites/schema_generate/run.php:0
        0.0467     887840   2. RomaricDrigon\MetaYaml\MetaYaml->validate() /Users/cordoval/Sites/schema_generate/run.php:19
        0.0467     888072   3. RomaricDrigon\MetaYaml\SchemaValidator->validate() /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/MetaYaml.php:61
        0.0467     888120   4. RomaricDrigon\MetaYaml\SchemaValidator->validateNode() /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/SchemaValidator.php:32
        0.0467     888248   5. RomaricDrigon\MetaYaml\NodeValidator\ArrayNodeValidator->validate() /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/SchemaValidator.php:48
        0.0467     888408   6. RomaricDrigon\MetaYaml\SchemaValidator->validateNode() /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/NodeValidator/ArrayNodeValidator.php:24
        0.0467     888536   7. RomaricDrigon\MetaYaml\NodeValidator\ArrayNodeValidator->validate() /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/SchemaValidator.php:48
        0.0468     889320   8. RomaricDrigon\MetaYaml\SchemaValidator->validateNode() /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/NodeValidator/ArrayNodeValidator.php:24
        0.0468     889448   9. RomaricDrigon\MetaYaml\NodeValidator\PrototypeNodeValidator->validate() /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/SchemaValidator.php:48
        0.0468     890176  10. RomaricDrigon\MetaYaml\SchemaValidator->validateNode() /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/NodeValidator/PrototypeNodeValidator.php:30
        0.0468     890304  11. RomaricDrigon\MetaYaml\NodeValidator\ArrayNodeValidator->validate() /Users/cordoval/Sites/schema_generate/src/RomaricDrigon/MetaYaml/SchemaValidator.php:48
    
    opened by cordoval 1
  • Fix atoum configuration

    Fix atoum configuration

    This commit fixes the atoum configuration so we can use the following commands to launch tests :

    • bin/test which launches test in loop mode and can take additional arguments like --debug
    • php vendor/mageekguy/atoum/bin/atoum --test-all : which is a more commonway to launch tests (using the standard command)

    So this PR lets us use one of these two commands which can be very usefull when using CI like Coconut-CI or Travis-CI.

    For example : Coconut-CI has some predefined configuration to run atoum tests and it assumes that the test suite can be launched with the standard command. Otherwise, you would have to define a custom build script which is more complicated ;)

    opened by jubianchi 1
  • Support symfony/yaml 4.x

    Support symfony/yaml 4.x

    I am using this library in a project where another component started depending on symfony/yaml 4.x. The latest release version of this library however only accepts 2.x or 3.x. I see that this has been changed in the master branch (https://github.com/romaricdrigon/MetaYaml/commit/1481b99679b29cbb50c88f3e10e4951ac64b8ad3), but this has not been released.

    How about doing a release that supports symfony/yaml 4.x?

    opened by Nikerabbit 4
  • Unable to run tests on PHP 7.2.x

    Unable to run tests on PHP 7.2.x

    composer install doesn't work:

    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - atoum/atoum 1.2.5 requires php >=5.3.3,<7 -> your PHP version (7.2.15) does not satisfy that requirement.
        - atoum/atoum 1.2.4 requires ext-xml * -> the requested PHP extension xml is missing from your system.
        - atoum/atoum 1.2.3 requires ext-xml * -> the requested PHP extension xml is missing from your system.
        - atoum/atoum 1.2.2 requires ext-xml * -> the requested PHP extension xml is missing from your system.
        - atoum/atoum 1.2.1 requires ext-xml * -> the requested PHP extension xml is missing from your system.
        - atoum/atoum 1.2.0 requires ext-xml * -> the requested PHP extension xml is missing from your system.
        - atoum/atoum 1.1.0 requires ext-xml * -> the requested PHP extension xml is missing from your system.
        - atoum/atoum 1.0.0 requires ext-xml * -> the requested PHP extension xml is missing from your system.
        - Installation request for atoum/atoum ~1 -> satisfiable by atoum/atoum[1.0.0, 1.1.0, 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.2.5].
    

    So you require "atoum/atoum": "~1" which doesn't support PHP 7.2.

    opened by OnkelTem 1
  • Enhance error reporting and clean code

    Enhance error reporting and clean code

    It seems to me the bad part of this tool is error reporting as it rarely reports anything reasonable when validating schema for example. So I started to enhance this part. I'm not sure though what is the best way to do so due to architecture specifics: exceptions logic is mixed with real errors and it's very difficult to distinguish. I'm going to provide a PR today so that you @romaricdrigon could check it out.

    P.S. While I was editing this message I got notification that you finally replied in my other issue lol

    opened by OnkelTem 3
  • Cannot write even basic schema

    Cannot write even basic schema

    I cannot explain why my schema doesn't work, I just continue getting some frustrating error message not explaining anything.

    Sample input:

    database:
      type: sqlite
      params:
        path: "some_path"
    

    Schema:

    root:
      _type: array
      _children:
        database:
          _type: array
          _required: true
          _description: "Database details"
          _children:
            type:
              _required: true
              _type: text
              _description: "Database plugin to use: sqlite, mysql, etc... Check the list of available db plugins."
            params:
              _required: true
              _type: partial
              _description: "Database plugin parameters."
              _partial: sqlite
    
    
    partials:
      sqlite:
        _type: array
        _required: true
        _children:
          path:
            _type: text
            _required: true
    

    And the error message I'm getting:

    Unable to validate schema with error: The choice node 'node' is invalid with error: The value 'array' is not allowed for node 'node_text._type'
    

    So it is saying about node. I don't have any node. And I don't have any arrays inside texts - just check it out above. What I do wrong eh?

    opened by OnkelTem 1
  • Fix min_items and max_items attribute names

    Fix min_items and max_items attribute names

    It's required to user _min_items and _max_items attributes.

    Method SchemaValidator::getFullName adds prefix "_" before search of min and max values

    opened by MaximDovk 0
Owner
Romaric Drigon
Romaric Drigon
laminas-password-validator provides a validator for character-set based input validation.

laminas-password-validator laminas-password-validator provides a validator for character-set based input validation. Installation composer require pra

null 1 Mar 8, 2022
Argentinian CUIT and CUIL Validator

CUIT/CUIL Validator Argentinian CUIT and CUIL Rules for laravel validation Installation $ composer require iutrace/laravel-cuit-validator Usage Exampl

iutrace 6 Sep 20, 2022
Custom Laravel Validator for combined unique indexes

unique_with Validator Rule For Laravel This package contains a variant of the validateUnique rule for Laravel, that allows for validation of multi-col

Felix Kiss 383 Oct 18, 2022
PHP Email address validator - A library for validating emails against several RFC.

EmailValidator A library for validating emails against several RFC. Supported RFCs This library aims to support RFCs: 5321, 5322, 6530, 6531, 6532, 10

Eduardo Gulias Davis 10.7k Jun 13, 2022
Modern PHP validator on steroids for validating forms and/or array's.

Modern PHP Validator - Standalone Validation on Steroids Introduction Head first example Installation Adding fields for validation Execute validation

Kris Kuiper 5 Oct 5, 2022
Light and extendable schema validation library

Light PHP validation library For everyone who uses MongoDB or other NoSQL solution and cares about what client sends to his/her database and looking f

Alexander Serkin 43 Sep 28, 2022
MetaYaml - A powerful schema validator

MetaYaml A [put your file type here] schema validator using [put another file type here] files. At the moment, file type can be Json, Yaml, or XML. It

Romaric Drigon 100 Sep 28, 2022
laminas-password-validator provides a validator for character-set based input validation.

laminas-password-validator laminas-password-validator provides a validator for character-set based input validation. Installation composer require pra

null 1 Mar 8, 2022
Database Abstraction Layer, Schema Introspection, Schema Generation, Query Builders

Cycle DBAL Secure, multiple SQL dialects (MySQL, PostgreSQL, SQLite, SQLServer), schema introspection, schema declaration, smart identifier wrappers,

Cycle ORM 30 Oct 18, 2022
:envelope: E-Mail Address Validator (syntax, dns, trash, typo)

✉️ E-Mail Address Validator for PHP Warning The best way to validate an e-mail address is still to send a duplicate opt-in-mail, when the user clicks

Lars Moelleken 41 Dec 25, 2022
JSONP callback validator.

JsonpCallbackValidator JsonpCallbackValidator allows you to validate a JSONP callback in order to prevent XSS attacks. Usage $validator = new \JsonpCa

William Durand 632 Dec 22, 2022
laravel-model-validator

laravel-model-validator This is a simple validator. The validator can be created by command. The validator has all common table column constraint, eg:

null 6 May 22, 2022
OpenAPI(v3) Validators for Symfony http-foundation, using `league/openapi-psr7-validator` and `symfony/psr-http-message-bridge`.

openapi-http-foundation-validator OpenAPI(v3) Validators for Symfony http-foundation, using league/openapi-psr7-validator and symfony/psr-http-message

n1215 2 Nov 19, 2021
This is a simple url bot validator made with laravel and react

?? This is a simple URL validator. Used Technologies React - Javascript framework Laravel - PHP framework Mysql - Relational database Installation Ins

Vanderson Telema 1 Oct 27, 2021
Laravel Disposable Email Validator

Laravel Disposable Email Validator Prevent users from registrering with a disposable email addresses! Table of Contents Installation Usage Translation

Tim Wassenburg 2 Oct 12, 2022
Laravel Common Password Validator

laravel-common-password-validator Laravel Common Password Validator An optimized and secure validator to check if a given password is too common. By d

WedgeHR 1 Nov 6, 2021
Argentinian CUIT and CUIL Validator

CUIT/CUIL Validator Argentinian CUIT and CUIL Rules for laravel validation Installation $ composer require iutrace/laravel-cuit-validator Usage Exampl

iutrace 6 Sep 20, 2022
Custom Laravel Validator for combined unique indexes

unique_with Validator Rule For Laravel This package contains a variant of the validateUnique rule for Laravel, that allows for validation of multi-col

Felix Kiss 383 Oct 18, 2022
Laravel Dutch Phone Number Validator

Laravel Dutch Phone Number Validator Validate if the given phone number is a valid Dutch phone number Table of Contents Installation Usage Translation

Tim Wassenburg 0 May 30, 2022
A simple validator package to check if the given zipcode has a valid Dutch zipcode format

Laravel Dutch Zipcode Validator A simple validator package to check if the given zipcode has a valid Dutch zipcode format Table of Contents Installati

Tim Wassenburg 0 May 30, 2022