Document "content" parameters
维护者通常 1 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- openapi, python
- 领域
- api, documentation
调研方向
从 _field2parameter 和 #778 中引入的 parameter_attribute_functions 自定义开始。确定参数字段应如何表示 OpenAPI content,同时保留现有的 schema 行为和自定义兼容性。当 JSON 对象参数能够输出适当的 content 条目,并且受影响的行为已由项目测试覆盖时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
https://swagger.io/docs/specification/describing-parameters/
To describe the parameter contents, you can use either the schema or content keyword.
[...]
content is used in complex serialization scenarios that are not covered by style and explode.
apispec assumes schema:
def _field2parameter(
self, field: marshmallow.fields.Field, *, name: str, location: str
) -> dict:
"""Return an OpenAPI parameter as a `dict`, given a marshmallow
:class:`Field <marshmallow.Field>`.
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#parameterObject
"""
ret: dict = {"in": location, "name": name}
prop = self.field2property(field)
if self.openapi_version.major < 3:
ret.update(prop)
else:
if "description" in prop:
ret["description"] = prop.pop("description")
if "deprecated" in prop:
ret["deprecated"] = prop.pop("deprecated")
ret["schema"] = prop # <------------------------ here
for param_attr_func in self.parameter_attribute_functions:
ret.update(param_attr_func(field, ret=ret))
return ret
In my code, I had to override that method to document a field that expects a JSON object and deserializes it into a dict:
[...]
ret["schema"] = prop
if isinstance(field, DictStr):
ret["content"] = {"application/json": {"schema": ret.pop("schema")}}
for param_attr_func in self.parameter_attribute_functions:
ret.update(param_attr_func(field, ret=ret))
return ret
We already added parameter_attribute_functions in #778 for specific cases that couldn't be addressed in field2property. Unfortunately, those functions only add stuff to the doc (their return value is fed to ret.update), so they can't do what is required above.
We could change that to let parameter attribute functions mutate ret for more customization (breaking change). It makes me cringe a bit because if several functions apply to the same field, they may interfere with each other and cause a crash. But after all, we're all grown-ups and I expect those kinds of exceptions to be scarce, so it shouldn't be an issue.
I'll try to carve some time to investigate this. Meanwhile, better ideas welcome.
- 主要语言
- Python
- 星标
- 1.2k
- 派生
- 210
- 平均合并
- 2 天 1 小时
- 30 天内合并 PR
- 4
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
marshmallow-code/apispec 的其他 Issue
-
DateTime(format="timestamp") generates invalid OpenAPI schema using min instead of minimum可能已有人在做 @Sanjays2402 于 103 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
marshmallow-code/apispec#1064 ·
维护者通常 1 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 68/100
marshmallow-code/apispec#750 · 1 条评论 · 5 个 reaction ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 30/100
marshmallow-code/apispec#1033 ·
维护者通常 1 天内回复
-
`apispec` ignores `oneOf` from `marshmallow-oneofschema`可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 4/5 3-5 天 新手友好度 38/100
marshmallow-code/apispec#1012 · 6 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 30/100
marshmallow-code/apispec#981 · 2 条评论 ·
维护者通常 1 天内回复
查看 marshmallow-code/apispec 的全部 Issue
相似的 Issue
-
documentation good first issue priority: P2 status: ready
难度 1/5 1 小时以内 新手友好度 88/100
RhinoLink-Tech/data-fabric#500 ·
维护者通常 1 天内回复
-
backlog
难度 2/5 1-3 小时 新手友好度 78/100
EchoTools/nevr-runtime#2384 ·
维护者通常 1 天内回复
-
[Bug]: The H2 series' and the H3C's fan 3 is labelled "Chamber Fan", Bambu calls it the exhaust fan未关闭area:ui
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
btclib-org/btclib#3062 ·
维护者通常 1 天内回复
-
area:evals area:infra enhancement
难度 2/5 1-3 小时 新手友好度 74/100
jse-avl/support-bot#4 · 1 条评论 ·