pydantic-models-py/examples/api_contract.py
Version 354361d83247.bb1 · MIT. This preview displays packaged text and does not execute code. Treat the contents as untrusted instructions.
← Return to resource and package checksum
"""BB Skills synthetic API contract. MIT; not part of the Microsoft template."""
from pydantic import ConfigDict, BaseModel, Field
class PatchProject(BaseModel):
model_config = ConfigDict(extra='forbid')
name: str | None = Field(default=None, min_length=1, max_length=200)
description: str | None = Field(default=None, max_length=2000)
def apply_patch(existing, incoming, create_model):
"""Allow only editable fields; revalidate after applying an explicit patch.
An omitted description is preserved; explicit None clears it. A project name
remains required after merging. Callers must separately enforce ownership,
authorization, concurrency and persistence before accepting any write.
"""
patch = PatchProject.model_validate(incoming).model_dump(exclude_unset=True)
merged = {**existing, **patch}
return create_model.model_validate(merged)