-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enhance schema handling with new json schema generation
- Updated `TypeIDType` in `typeid.py` to enhance JSON schema generation by overriding the `__get_pydantic_json_schema__` method. - Modified the `pyproject.toml` to add new dependencies: `pydantic` and `fastapi`. - Added new test files `fastapi_test.py` and `models.py` to verify functionality and model behaviors. - Refactored `typeid_test.py` to utilize new model definitions, removing redundant class definitions. Generated-by: aiautocommit
- Loading branch information
1 parent
61d5849
commit 3ba47b6
Showing
5 changed files
with
70 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,6 @@ dev = [ | |
"pdbr>=0.8.9", | ||
"psycopg[binary]>=3.2.3", | ||
"pytest>=8.3.3", | ||
"pydantic>=2.10.0", | ||
"fastapi>=0.115.6", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from fastapi import FastAPI | ||
|
||
from test.models import ExampleWithId | ||
|
||
|
||
def fake_app(): | ||
api_app = FastAPI() # type: ignore | ||
|
||
@api_app.get("/typeid") | ||
async def index() -> ExampleWithId: | ||
return "hi" | ||
|
||
return api_app | ||
|
||
|
||
def test_openapi(): | ||
openapi = fake_app().openapi() | ||
breakpoint() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from activemodel import BaseModel | ||
from activemodel.mixins import TypeIDMixin | ||
from activemodel.types.typeid import TypeIDType | ||
from sqlmodel import Relationship | ||
|
||
TYPEID_PREFIX = "myid" | ||
|
||
|
||
class AnotherExample(BaseModel, TypeIDMixin("myotherid"), table=True): | ||
pass | ||
|
||
|
||
class ExampleWithId(BaseModel, TypeIDMixin(TYPEID_PREFIX), table=True): | ||
another_example_id: TypeIDType = AnotherExample.foreign_key(nullable=True) | ||
another_example: AnotherExample = Relationship() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters