Skip to content

Add path_params to context in ParamModel resolve#1639

Open
nfd wants to merge 1 commit intovitalik:masterfrom
nfd:master
Open

Add path_params to context in ParamModel resolve#1639
nfd wants to merge 1 commit intovitalik:masterfrom
nfd:master

Conversation

@nfd
Copy link
Copy Markdown

@nfd nfd commented Jan 2, 2026

When validating, it's convenient to get path_params as part of context. For example, PATCH /items/<item id>/ might want to validate that item id, if supplied, references a record of a specific type. Obviously this could be done after validation, but it feels like it should be part of the validation process.

This PR adds path_params to the context for model validation.

Comment thread docs/docs/whatsnew_v1.md Outdated

@model_validator(mode="wrap")
def validate_item_id(cls, values, handler, info):
item_id = context["path_params"].get("item_id")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context[...] -> info.context[...]

@Lokker29
Copy link
Copy Markdown

Lokker29 commented Jan 9, 2026

I endorse the idea of the request. I need this feature time to time too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants