Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading