[英]list of dicts swagger python
I want to specify a List of dict and the keys of that dicts also in my swagger documentation,我还想在我的 swagger 文档中指定字典列表和该字典的键,
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]
.在类型提示中,您可以提供类型 - 您 class 或内置类型,如
List[float]
。
For python <= 3.8 you should use typing module, for 3.9+ you don't have to.对于 python <= 3.8 你应该使用 typing 模块,对于 3.9+ 你不必。 More on typing aliases .
有关键入别名的更多信息。
Also, if possible, think of aligning your naming convention to PEP8 .此外,如果可能,请考虑将您的命名约定与PEP8 对齐。 For example
profileData
-> profile_data
.例如
profileData
-> profile_data
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.