Implement select_schema
on EndpointCreator
and crud_router
#169
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Template for FastCRUD
Description
Adds an optional kwarg for the
EndpointCreator
andcrud_router
to specify a Pydantic schema for returning objects rather than dicts.I've added documentation on the classes docstrings wrt to the new kwarg, but will need some guidance/help to add to the pages and on what to build examples.
Closes #113
Changes
select_schema
optional kwarg toEndpointCreator
andcrud_router
SelectSchemaType
BaseModel
in theschema_to_select
arguments and appropriate returnsFastCRUD._read_item
andFastCRUD._read_items
is_paginated
andhas_offset_limit
inFastCRUD._read_items
select_schema
set toread_schema
fixture and tests with model validationTests
I copy pasted the "simple" client tests for
get
andget_multi
items, replacing the client for the new client withselect_schema
and addedread_schema.model_validate(...)
in the assertions.I've created them on the SQLModel side, happy to duplicate that on the SQLAlchemy side, but it's not part of my current cases so I'll have to learn how.
I'm not certain tests with
read_schema.model_validate(...)
are quite enough, I would prefer aisinstance
somewhere, but couldn't find the right set of tests to build upon.Checklist
Additional Notes
Fairly new to SQLModel and FastAPI, there might be things I missed.