rjbs / rx Goto Github PK
View Code? Open in Web Editor NEWthe Rx schema and validation system
Home Page: http://rjbs.manxome.org/rx
License: Other
the Rx schema and validation system
Home Page: http://rjbs.manxome.org/rx
License: Other
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.
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,
Hi rjbs, you working is amazing.
I just have some problem when usging the demonstration for check data on website.
It seems the page load some javascript in http protocol which blocked by Chrome.
Appreciate if you can fix it.
site address : https://rjbs.manxome.org/rx/demo.html
chrom ver : Version 112.0.5615.138 (Official Build) (64-bit)
os : windows 11
hope you well.
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.
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.
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.
Does this make sense? Would it be helpful for other users, or is it just me?
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
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)
I am stuck trying to figure out if I broke something I need to fix, or if this should be fixed in the module itself.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.