使用 mkdocstrings 自动记录 Pydantic BaseModel

问题描述 投票:0回答:1

我正在使用

mkdocs
为我的项目生成自动文档。但是,对于继承自
pydantic.BaseModel
的类,我发现为每个字段包含带有描述和数据类型的文档字符串很乏味,因为此信息已经包含在
pydantic.Field
参数中。这是一个例子:

class MyModel(BaseModel):
    """This text is good.

    :param field_1: redundant description and default value.
    :type field_1: redundant type
    """

    field_1: int = Field(default=3, description="description")

有没有办法添加对

pydantic
模型的支持?我浏览了互联网,但这是一个兔子洞,而且我对整个过程还很陌生。如有任何帮助,我们将不胜感激!

pydantic mkdocstrings
1个回答
0
投票

您可能对 Griffe 的 griffe-fieldz 扩展感兴趣,这是一个从 Python 源(静态或动态)提取信息的工具。

还有我自己创建的 griffe-pydantic 扩展(我是 mkdocstrings 的维护者),但目前仅对赞助商可用。

© www.soinside.com 2019 - 2024. All rights reserved.