Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FastAPI schema can not show the fields in parent odmantic.Model class #358

Open
SolardiaX opened this issue Jun 20, 2023 · 2 comments
Open
Labels
bug Something isn't working

Comments

@SolardiaX
Copy link

Bug

# odmantic model
class User(odmantic.Model):
    username: str
    password: str

# model in fastapi for response
class CurrentUser(User):
    token: str


class LoginForm(pydantic.Model):
    username: str = pydantic.Field(description="Username")
    password: str = pydantic.Field(description="Password")


@router.post("/login", description="Method to login user",
             response_model=CurrentUser,
             response_model_exclude_none=True)
async def login(request: Request, db: AsyncEngine = Depends(get_engine), form = Body()) -> CurrentUser {
  ...
}

Current Behavior

The response model in FastAPI swagger for CurrentUser only has the token field, username and password in parent class is missing.

Expected behavior

The response model in FastAPI swagger for CurrentUser should contains username, password and token.

Environment

  • ODMantic version: 0.9.2
  • MongoDB version: ...
  • Pydantic infos (output of python -c "import pydantic.utils; print(pydantic.utils.version_info())):

pydantic version: 1.10.9
pydantic compiled: True
install path: ...
python version: 3.11.3 (main, Apr 7 2023, 20:13:31) [Clang 14.0.0 (clang-1400.0.29.202)]
platform: macOS-13.4-arm64-arm-64bit
optional deps. installed: ['typing-extensions']

  • Version of additional modules (if relevant):
    • ...

Additional context

@SolardiaX SolardiaX added the bug Something isn't working label Jun 20, 2023
@tristantoupin
Copy link

tristantoupin commented Apr 14, 2024

I've got the same behavior. Here's my classes:

from odmantic import Field, Model

class CoreModel(Model):
    created_at: int = Field(
        default_factory=lambda: int(time.time()),
        description="Unix timestamp when the user was created",
    )
    updated_at: int = Field(
        default_factory=lambda: int(time.time()),
        description="Unix timestamp of the last update",
    )

class User(CoreModel):
    first_name: str
    last_name: str
    

@tristantoupin
Copy link

@SolardiaX any fixes/workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants