Giter Club home page Giter Club logo

yes's Introduction

YES - YAML Easy Schema

YES is a schema system for YAML that is intuitive and powerful. YES schemas are also YAML documents, so it "eats its own dog food", as they say.

HOW IT WORKS

The design of YES is rather simple. A YES schema is composed of YPath selectors mapped to document constraints. A YES document can be either a mapping or a sequence of such constraints. YPath is a syntax for selecting nodes from a YAML document.

When validating a YAML document against a YES schema a "lint" program simply collects all matching nodes with their applicable constraints into a collection of unit-validations. Then this collection is filtered of all passing validations. All that is left are the failures. If the filtered list is empty the document is completely valid. If not empty, the lint program can provide a detailed editorial list of the failures.

In general, contraints limit the possible nodes in a document. Some contraints are specifiers which instruct parsers how to interpret a document based on it's structure (as opposed to document tags).

Note About miniKanren

Although YES was conceived of and partially implemented before we ever heard of miniKanren, it later become apparent that YES is essentially a DSL variant on miniKanren for the specific purpose of creating schema for YAML documents. This presents a rather fruitful possibility that core logic of miniKanren implementations, already in the wild, could be used as a basis for creating YES implementations.

Examples

Lets take an example schema:

people/*/name:
  implicit: !name
  regexp: '[^/n]'

This simple schema selects all nodes under a people sequence of mappings with a name key, the value of which cannot contain newlines due to the regex constraint, and should be parsed with implcit tag of !name, as specified by the implicit constraint.

The following document would satisfy the schema:

people:
  - name: Charlie Adams
  - name: Julie Ann Rose

But this would not:

people:
  - name: |
      Charlie
      Adams

Sometimes multiple constraints of the same type need to be applied to a set of nodes. This can be done by expressing the same YPath with different constraints, for example:

- people/*/name:
    regexp: '[^/t]'
- people/*/name:
    regexp: '[^/n]'

But to make the intent more succinct a sequence of constraints instead of a mapping can be given.

people/*/name:
  - regexp: '[^/t]'
  - regexp: '[^/n]'

This construct implies logical-and relation. This can be explicitly given with a !!and tag.

people/*/name: !!and
  - regexp: '[^/t]'
  - regexp: '[^/n]'

Which as you may have guessed means !!or can be used to explicity create a logical-or constraint relation:

people/*/name: !!or
  - regexp: '[^/t]'
  - regexp: '[^/n]'

In this way complex logical relationships of constraints can be created.

people/*/login: !!or
  - !!and
    - implicit: !id
    - regexp: '^\d+$'
  - !!and
    - implicit: !name
    - regexp: '^\w+$'

(Of course these examples can be better handled via more sophisticated regular expressions, but the intent is only to show that logical operations are possible.)

(NOT IMPLEMENTED YET) By preceding a subentry with slash (/) YES will interpret the entry as a continutation of the parent YPATH rather than node criteria.

- people/*:
    /name:
      regexp: '[^/t]'

In this way schemas can often be more reflective of the the actual structure of the document they formailze.

In the above example we have only shown examples of regexp and implicit contraints, but there are many other types including: count, length, required, tag, value, etc. See the DEMO.md file for details.

COMMAND LINE

To use on the command line lint tool. Say we have a schema.yes file:

--- !!yes
name:
  type: str
  regexp: '[^\n]'
  required: true
age:
  type: int
birth:
  type: date

Try it on sample.yaml.

---
name: Thomas T. Thomas
age: 42
birth: 1976-07-04

Using the executable.

$ yes-lint schema.yes sample.yaml

In code that is:

require 'yes'

lint = YES::Lint.new(File.new('schema.yes'))

lint.validate(File.new('sample.yaml'))

CONTRIBUTE

Come on folks! Let's get YAML up to snuff. A good Schema could really help YAML go the distance and penetrate some of those "Enterprisey" worlds.

And please contribute to {Rubyworks Ruby Development Fund}[http://rubyworks.github.org] so us poor Ruby OSS developers can eat :)

COPYRIGHT

Copyright (c) 2011 Rubyworks

BSD-2 License

See LICENSE.txt for details.

yes's People

Contributors

trans avatar

Stargazers

David T. Crosby avatar 404 avatar

Watchers

 avatar 404 avatar James Cloos avatar  avatar  avatar

yes's Issues

Stream Validation

Need to add the ability to validate multiple documents and streams give a set of schemas.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.