check-my-irve/backend/app/core/ocpp_schemas.py

39 lines
1.2 KiB
Python

import jsonschema
# Schémas simplifiés pour la démo (basés sur la spec OCPP 1.6)
SCHEMAS = {
"BootNotification": {
"type": "object",
"properties": {
"chargePointVendor": {"type": "string", "maxLength": 20},
"chargePointModel": {"type": "string", "maxLength": 20}
},
"required": ["chargePointVendor", "chargePointModel"]
},
"Authorize": {
"type": "object",
"properties": {
"idTag": {"type": "string", "maxLength": 20}
},
"required": ["idTag"]
},
"StartTransaction": {
"type": "object",
"properties": {
"connectorId": {"type": "integer"},
"idTag": {"type": "string"},
"meterStart": {"type": "integer"},
"timestamp": {"type": "string"}
},
"required": ["connectorId", "idTag", "meterStart", "timestamp"]
}
}
def validate_payload(action, payload):
if action in SCHEMAS:
try:
jsonschema.validate(instance=payload, schema=SCHEMAS[action])
return None
except jsonschema.ValidationError as e:
return e.message
return None