Support default values specified in Pydantic Models
Problem Description
My codebase leverages Pydantic heavily. In particular, we use Pydantic Models heavily as a "superpowered" form of dataclasses. In particular, we use the Field() function heavily to validate, specify defaults, and otherwise impose restrictions on the values passed into a given field.
Unfortunately, for Pydantic Model fields, it seems that the default value -- whether specified in Field() or "normally" -- ends up not rendering properly in pdoc.
For example, the following results in the default value of 1 not showing up properly:
from pydantic import BaseModel
class Foo(BaseModel):
"""Test class."""
bar: int = Field(default=1)
Nor does the following:
from pydantic import BaseModel
class Foo(BaseModel):
"""Test class."""
bar: int = 1
Proposal
As "esoteric" as Pydantic can be at times, it would be nice to have native support for Pydantic models. Full-blown support for all of Pydantic is a heavy request, so I'd be happy with just supporting rendering default values properly (for the time being 😇).
I think pydantic is mainstream enough that it's worth to support this - contributions welcome!
+1 for support for Pydantic Field syntax, including both Pydantic defaults and Pydantic description within Field().
I've specifically run into this also because for one use case, we are using Puydantic Field() objects and description= set inside Field. The reason the docs are being set this way is due to the fact that we are rendering these into a JSON Schema file output, and we want description (and other fields like examples) to be populated into the Pydantic-generated JSON Schema.