SchemaMaximal
district42 schemas ⇆ JSON Schema
Installation
pip3 install schemax
Usage
>>> import schemax
>>> from district42 import schema
>>> ExampleSchema = schema.str.len(1, 10)
>>> schemax.to_json_schema(ExampleSchema)
{'type': 'string', 'minLength': 1, 'maxLength': 10}
Also, you could use schemax to translate from JSON-Schema to d42 and generate tests interfaces (in future releases) via command line:
$ python3 -m schemax translate schema.json
Translation from JSON-Schema to d42-schema for schema.json:
schema.dict({
'number': schema.int.min(1),
optional('street_name'): schema.str,
...: ...
})
schema.json:
{
"type": "object",
"properties": {
"number": { "type": "integer", "minimum": 1 },
"street_name": { "type": "string" }
},
"required": ["number"],
"additionalProperties": true
}
Supported d42 -> JSON Schema types and features
(✅ - done; 🔧 - planned support; ❌ - unsupportable)
- None:
- Bool:
- Int:
- Float:
- Str:
- List:
- Dict:
- Any:
- ❌ schema.const
- ❌ schema.bytes
Supported JSON Schema -> d42 types and features
(✅ - done; 🔧 - planned support; ❌ - unsupportable)
- ✅ null
- ✅ boolean
- ✅ integer
- ✅ minimum
- ✅ maximum
- ✅ exclusiveMinimum Keep in mind, that we're just taking exclusiveMinimum + 1 as schema.int.min
- ✅ exclusiveMaximum Keep in mind, that we're just taking exclusiveMaximum - 1 as schema.int.max
- ❌ multiples
- ✅ number
- ✅ minimum
- ✅ maximum
- 🔧 exclusiveMinimum
- 🔧 exclusiveMaximum
- ❌ multiples
- ✅ string
- ✅ array
- ✅ items
- ✅ length
- ✅ prefixItems
- ✅ unevaluatedItems
- ❌ uniqueness
- ✅ object