Code Monkey home page Code Monkey logo

rx's Introduction

What is Rx?

When adding an API to your web service, you have to choose how to encode the
data you send across the line. XML is one common choice for this, but it can
grow arcane and cumbersome pretty quickly. Lots of webservice authors want to
avoid thinking about XML, and instead choose formats that provide a few simple
data types that correspond to common data structures in modern programming
languages. In other words, JSON and YAML.

Unfortunately, while these formats make it easy to pass around complex data
structures, they lack a system for validation. XML has XML Schemas and RELAX
NG, but these are complicated and sometimes confusing standards. They're not
very portable to the kind of data structure provided by JSON, and if you wanted
to avoid XML as a data encoding, writing more XML to validate the first XML is
probably even less appealing.

Rx is meant to provide a system for data validation that matches up with
JSON-style data structures and is as easy to work with as JSON itself.

rx's People

Contributors

cesiumlifejacket avatar danlucraft avatar osfameron avatar rjbs avatar tamias avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rx's Issues

Documentation issue: RX "rest" attribute

Hello,

I'm crushing my head to forge a YAML validating a RX schema containing this line :

        rest:
            type: //any
            of:
                - type: //arr
                  contents: //str
                - type: //map
                  values:
                      type: //any
                      of:
                          - type: //str
                          - type: //arr
                            contents: //str
                            length:
                                min: 2

Although this realluy means something I don't get yet, I can't find easy reference of rule specificication, not in https://rx.codesimply.com/, nor in this GitHub repository.

Is it possible to explain better the content of key elements in some place, for instance the exact sense of the rest keyword? (documentation issue)

Thank you,

Support for default values in optional fields

Afaict there is no such support. Basically, an entry default: <some-val> as part of an optional field definition, were the value corresponds to the field type. Happy to provide a patch for the Python library.

Rest paramater usage

Hopefully you can give me some guidance on using the rest parameter.

Here’s my YAML data:

title: "Things"
patterns:
  some-pattern:
    title: "Stuff"
  unknown:
    title: "Stuff"

I believe the rest parameter will allow be to validate the patterns key because I don’t know the names of the keys inside patterns but each key will follow specific format.

This is my schema, but it’s still giving me errors related to the keys not existing:

type: "//rec"
optional:
  title: "//str"
  patterns:
    type: "//rec"
    rest:
      type: "//rec"
      optional:
        title: "//str"

I’m getting the “Hash has extra keys [some-patterns, unknown]” error message.

I’m using the Ruby implementation.

How to define custom types?

Hi! I see the code hasn't been touched in a while, but there has been some activity at the beginning of this year, so I'm hopeful.

I would like to use Rx (in Python), and I wrote a schema that I also want to use as documentation. For that use case, it is best if there are many small custom types. I can't find anything specified on how to locate schemas for subtypes, which I suppose is left to the caller that will have to register them.

I feel this can be improved and have a suggestion for having all related types inside the same file. Please let me know if this may be interesting to include as a core feature.

  • A schema file can contain multiple documents.
  • The first document is the main schema.
  • The following documents describe the custom types and include an additional "schema" tag at the beginning, that has as value the URI to use for referring to that type.
  • An implementation of the validator reads all documents, registers each type with their URI, and proceeds to handle the main schema as usual.

Does this make sense? Would it be helpful for other users, or is it just me?

  • As an extra finesse, it would be possible to replace a custom schema with a reference to a file to read it from, allowing sharing of types.

Example

For this simple case the reduced indentation is small, but you can easily imagine a more complex case. Also the URIs should be full tag:s, but it's not really necessary because the references are all in the same file.

One big schema:

---
type: //rec
required:
  foo: 
    type: //rec
      required:
        name: //str
      optional:
        date: //int

Split schema:

---
type: //rec
required:
  foo: /my/element
---
schema: /my/element
type: //rec
required:
  name: //str
optional:
  date: //int

Split schema with a referenced file:

---
type: //rec
required:
  foo: /my/element
---
schema: /my/element
file: ./element.rx

Coretype suggestion: LazyType

Hi,

I have a suggestion for a new coretype.

I want to validate a recursive schema (an item list where each item can itself be an item list).
Instead of creating a //recursive type, I propose a //lazy type:

# /.meta/lazy, the schema for //lazy definitions:
{
  "type": "//rec",
  "required": {
    "type": { "type": "//str", "value": "//lazy" },
    "of": { "type": "//str" }
  }
}

Example if we define a new /example/itemlist type (a list of elements, that are either string or itemlist):

  type: //seq
  contents:
    - //str
    - type: //lazy
      of: /example/itemlist

The //lazy type should not be resolved during the schema construction, but at validation time.

Implementation example in python:

class LazyType(_CoreType):
  @staticmethod
  def subname(): return 'lazy'

  def __init__(self, schema, rx):
    if not {'type', 'of'}.issuperset(schema):
      raise SchemaError('unknown parameter for //lazy')

    if not schema.get('of'):
      raise SchemaError('no actual type provided for //lazy')

    self.schema = schema['of']
    self.rx = rx

  def validate(self, value, name='value'):
    validator = self.rx.make_schema(self.schema)
    validator.validate(value)

More than recursive schema, it allows to use a schema that will be later defined (in case of circular inclusion)

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.