https://github.com/38elements/django-simple-jsonschema
django-simple-jsonschema is middleware for integrating django and jsonschema.
https://github.com/38elements/django-simple-jsonschema
Last synced: 2 months ago
JSON representation
django-simple-jsonschema is middleware for integrating django and jsonschema.
- Host: GitHub
- URL: https://github.com/38elements/django-simple-jsonschema
- Owner: 38elements
- License: mit
- Created: 2015-11-23T11:22:45.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-01-16T02:22:02.000Z (over 10 years ago)
- Last Synced: 2026-01-20T18:51:39.542Z (5 months ago)
- Language: Python
- Homepage: https://pypi.python.org/pypi/django-simple-jsonschema
- Size: 18.6 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## django-simple-jsonschema
##### Warning this project is Alpha.
`django-simple-jsonschema` is middleware for integrating [django](https://github.com/django/django) and [jsonschema](https://github.com/Julian/jsonschema).
If the request is invalid, such as the following response will be sent.
```
{
"errors": [
{
"message": "'id' is a required property",
"path": [],
"schema_path": [
"required"
]
},
{
"message": "1 is not of type 'string'",
"path": [
"password"
],
"schema_path": [
"properties",
"password",
"type"
]
}
],
"url": "/foo/bar/",
"method": "POST"
}
```
## Requirements
* Python 3+
* Django 1.8+
* jsonschema 2.5+
## Installation
You can install `django-simple-jsonschema` using `pip3`.
```
pip3 install django-simple-jsonschema
```
Add `'django_simple_jsonschema.SimpleJsonschemaMiddleware'` to your `MIDDLEWARE_CLASSES` setting.
```
MIDDLEWARE_CLASSES = [
# ...
'django_simple_jsonschema.SimpleJsonschemaMiddleware'
]
```
## Configuration
You define the following variables in your project’s settings.
##### SIMPLE_JSONSCHEMA
`SIMPLE_JSONSCHEMA` is `dict`.
`SIMPLE_JSONSCHEMA` has key which is `('', '')` or `(('', ''), ''))`.
`SIMPLE_JSONSCHEMA` has value which is schema.
###### Example
```
SIMPLE_JSONSCHEMA = {
('post', 'namespace1:namespace2:name1'): {
'$schema': 'http://json-schema.org/schema#',
'type': 'object',
'properties': {
'login_id': {'type': 'string'},
'password': {'type': 'string'},
},
'required': ['id']
},
(('post', 'put'), 'namespace3:name2'): {
'$schema': 'http://json-schema.org/schema#',
'type': 'object',
'properties': {
'name': {'type': 'string'},
'message': {'type': 'string'},
}
}
}
```
You can validate schema using following command.
```
python3 manage.py check_schema
```