Proposal
There are three main ways to document Pydantic BaseModel fields:
- Using
Field(description="a nice description")
- Using
Annotated[T, "a nice description"]
- Using docstrings below each field
"""a nice description""".
Example:
from pydantic import BaseModel
class Color(BaseModel):
"""General Color class docstring."""
r: int = Field(description="Amount of red.")
g: Annotated[int, "Amount of green."]
b: int
"""Amount of blue."""
As of now, only option 3 generates documentation with great-docs.
Would it be possible to use the Field(description"...") or the Annotated patterns to generate documentation?
I know Pydantic allows setting the config use_attribute_docstrings so docstrings get turned into field descriptions, but most of my code has descriptions using the Field notation.
If that's technicallly not feasible, would it be possible to at least show all fields of a Pydantic BaseModel in docs, even if they don't have documentation docstrings?
Proposal
There are three main ways to document Pydantic
BaseModelfields:Field(description="a nice description")Annotated[T, "a nice description"]"""a nice description""".Example:
As of now, only option 3 generates documentation with great-docs.
Would it be possible to use the
Field(description"...")or theAnnotatedpatterns to generate documentation?I know Pydantic allows setting the config
use_attribute_docstringsso docstrings get turned into field descriptions, but most of my code has descriptions using theFieldnotation.If that's technicallly not feasible, would it be possible to at least show all fields of a Pydantic BaseModel in docs, even if they don't have documentation docstrings?