简体   繁体   中英

list of dicts swagger python

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
                }
            ]

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM