Skip to content

API Reference parrot_formdesigner.api.operations

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.api.operations

View source

PATCH /api/v1/forms/{form_uid}/operations — atomic batched-edit endpoint.

Per FEAT-152 §2 Internal Behavior:

  1. Parse the OperationsEnvelope from the body (Pydantic discriminated union over op).
  2. Optionally honour If-Match: <version> (Q1: optimistic concurrency).
  3. Apply ops sequentially on a Pydantic-deep-copied working form.
  4. On any per-op failure → 422 with the offending op's index + name.
  5. Run FormValidator.check_schema on the working copy → 422 if errors.
  6. Bump the form version via _bump_version.
  7. Persist via registry.register(working_copy, persist=True, overwrite=True).
  8. Return 200 with {"form": working_copy.model_dump()}.

Per Q2 (resolved): the existing PUT (update_form) and RFC-7396 PATCH (patch_form) endpoints stay alongside this — full-replace and merge-patch use cases differ from granular UI edits.

Class AddField

Insert a new field into an existing section.

field may carry a client-supplied field_uid (upsert origin); when omitted, FormField's default_factory mints a fresh one. Rejected if it (or field.field_id) already exists anywhere in the form (FEAT-393 — per-FORM uniqueness, not per-section).

Example (wire body)::

{"op": "add_field", "section_uid": "3c3b0847-56fb-493f-bb84-2554b502a31e",
 "field": {"field_id": "phone", "field_type": "text", "label": "Phone"}}

Attributes:

Attribute Type Description
op Literal['add_field']
section_uid uuid.UUID
field FormField
position int | None

Class AddSection

Insert a new section. Optional position indexes the section list.

Attributes:

Attribute Type Description
op Literal['add_section']
section FormSection
position int | None

Class DuplicateField

Duplicate a field within the same (or another) section.

The clone always gets a fresh, server-minted field_uid — never the source's. as_field_id becomes the clone's new editable key.

Example (wire body)::

{"op": "duplicate_field",
 "from": {"section_uid": "...", "field_uid": "..."},
 "as_field_id": "phone_2"}

Attributes:

Attribute Type Description
op Literal['duplicate_field']
from_ dict
as_field_id str

Alias FormField

Re-exported from parrot_formdesigner.core.schema.FormField.

Alias FormSchema

Re-exported from parrot_formdesigner.core.schema.FormSchema.

Alias FormSection

Re-exported from parrot_formdesigner.core.schema.FormSection.

Alias FormSubsection

Re-exported from parrot_formdesigner.core.schema.FormSubsection.

Alias FormValidator

Re-exported from parrot_formdesigner.services.validators.FormValidator.

Class MoveField

Move a field across (or within) sections.

from is a Python keyword, so the wire field is aliased to from_. Set model_config = ConfigDict(populate_by_name=True) so both the alias and the field name are accepted.

Example (wire body)::

{"op": "move_field",
 "from": {"section_uid": "...", "field_uid": "..."},
 "to": {"section_uid": "...", "position": 0}}

Attributes:

Attribute Type Description
op Literal['move_field']
from_ dict
to dict

Attribute Operation

Class OperationError

Per-op apply failure carried back to the HTTP layer.

Parameter Type Default Description
index int
op_name str
message str

Attributes:

Attribute Type Description
index 0-based index of the failing op within the envelope.
op_name Discriminator value (e.g., "add_field").
message Human-readable reason.

Class OperationsEnvelope

Top-level body shape for PATCH .../operations.

Fields:

Field Type Default Description
operations list[Operation]

Class RemoveField

Remove a field from a section (or subsection).

Example (wire body)::

{"op": "remove_field", "section_uid": "...", "field_uid": "..."}

Attributes:

Attribute Type Description
op Literal['remove_field']
section_uid uuid.UUID
field_uid uuid.UUID

Class UpdateField

Apply RFC 7396 merge-patch to a single field, addressed by UID.

patch may rename field_id (subject to per-form uniqueness); a patch touching field_uid is rejected — the identity is immutable.

Example (wire body)::

{"op": "update_field", "section_uid": "...", "field_uid": "...",
 "patch": {"label": "New Label"}}

Attributes:

Attribute Type Description
op Literal['update_field']
section_uid uuid.UUID
field_uid uuid.UUID
patch dict[str, Any]

Class UpdateFormMeta

Apply RFC 7396 merge-patch to the form-level meta.

Attributes:

Attribute Type Description
op Literal['update_form_meta']
patch dict[str, Any]

Class UpdateSectionMeta

Apply RFC 7396 merge-patch to a section's metadata.

Example (wire body)::

{"op": "update_section_meta", "section_uid": "...", "patch": {"collapsed": true}}

Attributes:

Attribute Type Description
op Literal['update_section_meta']
section_uid uuid.UUID
patch dict[str, Any]

Alias declared_tenant

Re-exported from parrot_formdesigner.api.tenant.declared_tenant.

Alias extract_form_uid

Re-exported from parrot_formdesigner.api.handlers.extract_form_uid.

Function handle_operations

PATCH /api/v1/forms/{form_uid}/operations — atomic batched edits.

Steps (per spec §2 Internal Behavior):

  1. Parse and validate form_uid from match_info (FEAT-389).
  2. Load form from request.app['form_registry']; 404 if missing.
  3. Parse + validate the OperationsEnvelope body; 422 on shape errors.
  4. Honour If-Match header (Q1); 412 on mismatch.
  5. Apply ops sequentially on a deep-copy working form (address fields/sections by field_uid/section_uid, FEAT-393). On the first OperationError, return 422 with the offending op's index/name.
  6. Re-resolve rule references (core.resolution. resolve_rule_references, FEAT-393) — rewrites any authored field_id rule references introduced by an update_field patch; 422 on an unknown/ambiguous/empty reference.
  7. FormValidator.check_schema on the working copy; 422 if errors.
  8. Bump the version via _bump_version.
  9. Persist via registry.register(working_copy, persist=True, overwrite=True).
  10. Return 200 with {"form": working_copy.model_dump()}.

handle_operations(request: web.Request) -> web.Response

Parameter Type Default Description
request web.Request

Returns: web.Response

Attribute logger

Alias resolve_rule_references

Re-exported from parrot_formdesigner.core.resolution.resolve_rule_references.

Alias walk_fields

Re-exported from parrot_formdesigner.core.schema.walk_fields.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally