Giter Club home page Giter Club logo

pyjo-mdl's Introduction

pyjo-mdl

Model definition language for Pyjo

This package will allow you to dynamically create pyjo models with a domain specific language created ad-hoc.

Model definition language

We can define the structure of the model with a json format. Heres a basic example:

{
  "url": {
    "type": "url",
    "required": false
  },
  "name": {
    "type": "string"
  },
  "rounds": {
    "type": "array",
    "element": {
      "type": "embedded",
      "model": {
        "foo": {
          "type": "string"
        },
        "bar": {
          "type": "integer",
          "min_value": 100
        }
      }
    }
  }
}

This allows to define models as a set of properties with some type and validation.

As you can see, there are many possible properties in this DSL. We want to keep it as simple as possible to start with, so heres a very basic list of stuff that we plan to add from the beginning. More stuff will come in the future as needs arise.

Available properties and options

Some generally available options:

  • required: true if the property must be always filled when providing content. Defaults to true
  • type: type of the property, see below for a proposal of the initial set of properties available

string

Basic string field, may contain any set of UTF-8 characters. Extra options:

  • validation: a regular expression the string must satisfy
  • min_length: Min number of chars in the string, defaults to 0
  • max_length: Max number of chars in the string, defaults to infinite!
  • values: array of all and only possible values for this field

Example:

{
    "tag_version": {
        "type": "string",
        "validation": "^.*-[0-9]\.[0-9]\.[0-9]build[0-9]+$"
        "max_length": 256
    }
}

Example (enum):

{
    "meal_category": {
        "type": "string",
        "values": [
            "smoothie",
            "main dish",
            "dessert",
        ]
    }
}

integer

Integer number. Extras:

  • min_value: min value allowed
  • max_value: max value allowed
{
    "calories": {
        "type": "integer",
        "min_value": 0
    }
}

float

Floating point number. Extras:

  • min_value: min value allowed
  • max_value: max value allowed
{
    "price": {
        "type": "float",
        "min_value": 0,
        "max_value": 99.99
    }
}

boolean

Flag, true or false. Cant be easier than this.

{
    "hidden": {
        "type": "boolean"
    }
}

Booleans will automatically consider values in yes, true, t, y, 1 to be truthy (ignoring case), values in no, false, f, n, 0 to be falsy. Other string values will raise an exception.

url:

URLs are validated with the following regex: http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+

{
    "cover_image": {
        "type": "url"
    }
}

embedded

Represents an embedded model that may have no meaning outside of the main model. Its useful to represent some nested data structure. May contain all the properties of a full model. Must contain:

  • model: the model structure being embedded

Example

{
    "pet": {
        "type": "embedded",
        "model": {
            "name": {
                "type": "string",
            },
            "age": {
                "type": "integer",
                "min_value": 0
            }
        }
    }
}

array

Represents a list of fields of any kind, including embedded. Extras:

  • element: defines the kind of element in this array property. It may be of any kind, including embedded

Examples (primitive content):

{
    "lucky_numbers": {
        "type": "array",
        "element": {
            "type": "integer"
        }
    }
}

Example 2 (embedded complex models):

{
    "pets": {
        "type": "array",
        "element": {
            "type": "embedded",
            "model": {
                "name": {
                    "type": "string"
                },
                "age": {
                    "type": "integer",
                    "min_value": 0
                }
            }
        }
    }
}

pyjo-mdl's People

Contributors

earien avatar emdotem avatar xelhark avatar

Watchers

 avatar

Forkers

earien

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.