【发布时间】:2018-02-27 15:09:29
【问题描述】:
我正在尝试在我的烧瓶应用程序中实现一个路由,以提供给定资源的 OPTIONS 方法并返回与所述资源关联的棉花糖模式的描述。类似于 django 所做的事情:
{
"name": "Dataset List",
"description": "",
"renders": [
"application/json",
"text/html"
],
"parses": [
"application/json",
"application/x-www-form-urlencoded",
"multipart/form-data"
],
"actions": {
"POST": {
"id": {
"type": "integer",
"required": false,
"read_only": true,
"label": "ID"
},
"url": {
"type": "field",
"required": false,
"read_only": true,
"label": "Url"
},
"name": {
"type": "string",
"required": true,
"read_only": false,
"label": "Name",
"help_text": "The dataset name.",
"max_length": 256
}
}
}
}
我似乎在Schema 或返回此描述的文档中找不到任何方法,并且AlbumSchema.opts.fields 是空的。是否可以遍历整个字段并构建我需要的描述?类似的东西:
desc = {f: {"required": f.required,
"type": f.__class__.__name__,
...}
for f in AlbumSchema.fields}
【问题讨论】:
标签: python rest flask marshmallow