feat: add schema validation for doc input
This commit is contained in:
parent
150bb16220
commit
8239c4d57a
|
|
@ -1,8 +1,10 @@
|
|||
{
|
||||
"client_name": "Acme Ltd",
|
||||
"provider_name": "John Doe 2",
|
||||
"provider_name": "Will Smith",
|
||||
"payment_type": "hourly",
|
||||
"hourly_rate_gbp": 40,
|
||||
"include_confidentiality": false,
|
||||
"include_ip_clause": false,
|
||||
"termination_notice_days": 14,
|
||||
"governing_law": "England and Wales"
|
||||
}
|
||||
7
main.py
7
main.py
|
|
@ -2,12 +2,17 @@ import json
|
|||
from pathlib import Path
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
from schema import DocumentInput
|
||||
|
||||
|
||||
def main():
|
||||
# load input data
|
||||
# path() over hardcoding str
|
||||
data = json.loads(Path("examples/input.json").read_text(encoding="utf-8"))
|
||||
|
||||
# validate + normalise input
|
||||
doc_input = DocumentInput(**data)
|
||||
|
||||
# setup template eng
|
||||
# create jinja2 env for templates
|
||||
env = Environment(
|
||||
|
|
@ -20,7 +25,7 @@ def main():
|
|||
# load template to render
|
||||
# **data spreads dict so keys become template vars
|
||||
template = env.get_template("doc.md.j2")
|
||||
out = template.render(**data)
|
||||
out = template.render(**doc_input.model_dump())
|
||||
|
||||
# write output - render md to file
|
||||
Path("out.md").write_text(out, encoding="utf-8")
|
||||
|
|
|
|||
16
schema.py
Normal file
16
schema.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
from typing import Literal, Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class DocumentInput(BaseModel):
|
||||
client_name: str = Field(..., min_length=1)
|
||||
provider_name: str = Field(..., min_length=1)
|
||||
|
||||
payment_type: Literal["hourly", "fixed", "other"]
|
||||
|
||||
hourly_rate_gbp: Optional[float] = Field(None, gt=0)
|
||||
fixed_fee_gbp: Optional[float] = Field(None, gt=0)
|
||||
|
||||
include_confidentiality: bool = False
|
||||
governing_law: str
|
||||
|
|
@ -24,4 +24,14 @@ not included.
|
|||
laws of england and wales.
|
||||
{% else %}
|
||||
{{ governing_law }}.
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
## intellectual property
|
||||
{% if include_ip_clause %}
|
||||
all intellectual property created during the services remains with the provider.
|
||||
{% else %}
|
||||
no intellectual property clause is included.
|
||||
{% endif %}
|
||||
|
||||
## termination
|
||||
either party may terminate this agreement with {{ termination_notice_days }} days' written notice.
|
||||
|
|
|
|||
Loading…
Reference in a new issue