Reputation: 319
schemas.py
import pydantic as _pydantic
import datetime as _dt
class _UserBase(_pydantic.BaseModel):
email = str
class UserCreate(_UserBase):
hashed_password = str
class Config:
orm_mode = True
main.py
import fastapi as _fastapi
import fastapi.security as _security
import sqlalchemy.orm as _orm
import services as _services
import schemas as _schemas
app = _fastapi.FastAPI()
@app.get("/")
def get():
m = _schemas.UserCreate.schema_json()
return m
When i go to localhost:8000/ it returns:
"{\"title\": \"UserCreate\", \"type\": \"object\", \"properties\": {}}"
And i cant see the request body inside swagger doc also. It comes empty.
Upvotes: 0
Views: 823
Reputation: 3083
As you can see in the official pydantic
tutorial, you should use type annotations, not assign the types as class variables:
class _UserBase(_pydantic.BaseModel):
email: str
Upvotes: 3