autodoc_pydantic: Show fields from parent model

343 Views Asked by At

I'm using the autodoc_pydantic plugin for Sphinx to document my pydantic.BaseModel classes. However, there are cases where I have something like

class Foo(pydantic.BaseModel):
    '''Foo class'''

    x: str = pydantic.Field(description='The x.')

class Bar(Foo):
    '''Bar class'''

    y: int = pydantic.Field(description='The y.')

My .rst file contains the directive

.. automodule:: foo.foo
    :members:

When the documentation is generated, only the y field is shown for the Bar class. Is there a way to get autodoc_pydantic to show both x and y in Bar's description?

1

There are 1 best solutions below

0
Daniel Walker On BEST ANSWER

It can be accomplished via the :inherited-members: option:

.. automodule:: foo.foo
    :inherited-members: BaseModel