Skip to content

[Bug]: Preprocessor doesn't handle "ucp_request": "optional" string marker #30

@xiaoxuanz-hub

Description

@xiaoxuanz-hub

Describe the bug

The eval_prop_inclusion function in preprocess_schemas.py does not handle the "optional" value when ucp_request is a simple string (as opposed to a per-operation dict). This causes fields marked "ucp_request": "optional" to remain required in both generated create and update request models, even though the schema author intended them to be optional.

To Reproduce

Source schema for shipping_destination.json:

{
...
  "type": "object",
  "required": ["id"],
  "properties": {
    "id": {
      "type": "string",
      "ucp_request": "optional"
    }
  }
...
}

Expected behavior

Expected generated output (shipping_destination_create_request.py):

id: str | None = None

Screenshots

Actual generated output for shipping_destination_create_request.py

id: str  # still required
Image

Additional context

Root Cause

In eval_prop_inclusion, the string-form marker only checks for "omit" and ["required"]:

if marker == "omit":
    include = False
elif marker == "required":
    is_required = True
# "optional" falls through — is_required stays True from base schema

Since id is in the base required list, is_required defaults to True and is never overridden.

Fix

Add an elif branch for "optional":

if marker == "omit":
    include = False
elif marker == "required":
    is_required = True
elif marker == "optional":
    is_required = False

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions