I want to specify a List of dict
and the keys of that dicts also in my swagger documentation,
class GetCustomerDetailsByIdPOUT(BaseModel):
profileData: Customer
scanData : Reports
Scan: list
Currently, I am getting this
"Scan": [
"string"
]
You can also see in the image
I want something like this
"scans": [
{
"id": 0,
"cameraId": 0,
"reportId": 0,
"sequenceNo": 1,
"raw": [
"string"
],
"spectrum": 1,
"view": 1
}
]
>Solution :
I think that you don’t provide the information on what list will contain. I don’t know what you want to have in there, but for example:
from typing import List
class GetCustomerDetailsByIdPOUT(BaseModel):
profileData: Customer
scanData : Reports
Scan: List[MyScan]
within the type hinting you can provide the type – you class or build-in type, like List[float].
For python <= 3.8 you should use typing module, for 3.9+ you don’t have to. More on typing aliases.
Also, if possible, think of aligning your naming convention to PEP8. For example profileData -> profile_data.
