I'm using pydantic 1.6.1 and fastapi 0.61.1 with Python 3.8.3. Here's how I've tried defining the models:
class UserBase(BaseModel):
name: str
class UserCreate(UserBase):
password: str
class UserInfo(UserBase):
id: str
group: Optional[GroupInfo] = None
The issue I'm having with this setup is that the schema is built such that the name attribute is on top of the remaining attributes like so - in this case, while using UserInfo as the endpoint's response_model:
[
{
"name": "string",
"id": "string",
"group": {
"name": "string"
}
}
]
Yet I'd like to be able to set them up like this:
[
{
"id": "string",
"name": "string",
"group": {
"name": "string"
}
}
]
Is there a way I can manually set a custom order for the attributes in the JSON response's schema?