Um validador para schema json usado em APIs Rest
Project description
Validator-Schema
Esta é uma lib usada para validar que vem de um jsonschema em API Rest. A capacidade de validação dele vem de expressões regulares, strings, numeros, enums, datas (formato YYYY-MM-DD) e hora (formato HH:MM)
INSTALAÇÃO
Para realizar a instalação deste módulo basta executar
pip install validator-schema
UTILIZAÇÃO
Vamos supor que você tenha um servidor com Flask onde você vai receber por paramêtros um json e quer validar os campos name e password. Onde o name não deve vir vazio e password deve ter ao menos 8 caracteres. Isto pode ser validado de forma simples com o validator-schema
from flask import request
import json
from validator_schema import ValidatorString, Validator
...
@app.route('/', methods = ['POST'])
def login():
data = request.get_json()
list_validators = [
ValidatorString('name', min = 1, msg_error = 'Field name without value'),
ValidatorString('password', min = 8, msg_error = 'Field password minimum 8 caracters.)
]
requireds = ['name', 'password']
v = Validator(list_validators, requireds)
try:
v.is_valid(data)
except ValueError as err:
return json.dumps({'error': str(err)})
# Fields validates
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file validator_schema-0.1.0.tar.gz.
File metadata
- Download URL: validator_schema-0.1.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.19.0-43-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bce45dcbe297701d321c4bf781927de7e108626cab0cb9193e565d6dd5c9f4ad
|
|
| MD5 |
7b9f056579d4293bff97c93701269f65
|
|
| BLAKE2b-256 |
b683c3d1a4686626dc35fe6783b9799105850116482c3297a3344e38c07149c3
|
File details
Details for the file validator_schema-0.1.0-py3-none-any.whl.
File metadata
- Download URL: validator_schema-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.19.0-43-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10d5d24c3a8f523e89163c0a85ec4dc4633fdcbf2afa71eed5be567380522dfb
|
|
| MD5 |
7653e54164b70eb2edaa80046a7196bb
|
|
| BLAKE2b-256 |
43bd9b438dad813501e31e5d6c68eb1de278f2c56489c4c82e6be097b66902ed
|