Skip to content

Use Pydantic BaseModel description for documentation #281

Description

@willsbit

Proposal

There are three main ways to document Pydantic BaseModel fields:

  1. Using Field(description="a nice description")
  2. Using Annotated[T, "a nice description"]
  3. 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?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions