Hey guys,
I have a graph object that has nodes and edges. Each edge has a source and a target which are references to node ids. I've implemented a custom field validator that checks that each source and target exist in the node list of the graph. It all works great, but the openapi schema generation fails because of this validator. Both the nodes and edges have a default factory for the id field in shortuuid.uuid(). The error is the error of the validator:
{
status_code: 400,
detail: null,
value_error: "1 validation error for GraphDto
edges
Value error, Invalid edges: pZYhKCKNYmpNtrleyqIv,pZYhKCKNYmpNtrleyqIv don't have a targets, the target nodes don't exist, or the target equals the source [type=value_error, input_value=[Edge(id='pZYhKCKNYmp...kqgXYT', disabled=True)], input_type=list]
For further information visit https://errors.pydantic.dev/2.9/v/value_error"
}
I'm trying to understand the right approach here. I was thinking to add an example on the pydantic field where I can specify hard-coded id values for 2 nodes and have one edge where the source and target is one of each. Using the examples field from here: https://docs.pydantic.dev/latest/concepts/json_schema/#customizing-json-schema doesn't seem to translate to the openapi schema generation.
With that, I wanted to have a discussion on what the right approach is in this case. I feel like providing pre-determined examples should work, but I can't understand from the documentation if it's even supported.
Thanks!
Litestar Version: 2.12.1
Pydantic Version: 2.9.2