mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
Using jsonschema for create_template.
Updated jsonschema to Draft7, this allowed a conditional validation on subject, if template_type == 'email' or 'letter' then subject is required. This version is backward compatible with Draft4. When creating TempalteRedacted, I've built the dict depending on if the created_by or created_by_id exists.
This commit is contained in:
28
app/template/template_schemas.py
Normal file
28
app/template/template_schemas.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from app.models import (
|
||||
TEMPLATE_PROCESS_TYPE,
|
||||
TEMPLATE_TYPES,
|
||||
)
|
||||
from app.schema_validation.definitions import uuid
|
||||
|
||||
post_create_template_schema = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"description": "POST create new template",
|
||||
"type": "object",
|
||||
"title": "payload for POST /service/<uuid:service_id>/template",
|
||||
"properties": {
|
||||
"name": {"type": "string"},
|
||||
"template_type": {"enum": TEMPLATE_TYPES},
|
||||
"service": uuid,
|
||||
"process_type": {"emun": TEMPLATE_PROCESS_TYPE},
|
||||
"content": {"type": "string"},
|
||||
"subject": {"type": "string"},
|
||||
"created_by": uuid
|
||||
},
|
||||
"if": {
|
||||
"properties": {
|
||||
"template_type": {"enum": ["email", "letter"]}
|
||||
}
|
||||
},
|
||||
"then": {"required": ["subject"]},
|
||||
"required": ["name", "template_type", "content", "service", "created_by"]
|
||||
}
|
||||
Reference in New Issue
Block a user