pytkdocs icon indicating copy to clipboard operation
pytkdocs copied to clipboard

[BUG] Pydantic model fields don't display in documentation

Open ysfchn opened this issue 4 years ago • 4 comments

Describe the bug I just saw the issue #9, and it looks like Pydantic models are supported, however I couldn't manage adding a Pydantic model in documentation. I use pytkdocs through mkdocstrings so I didn't install pytkdocs myself, it is installed with mkdocstrings. Am I doing something wrong?

To Reproduce I referenced the model like this, (I also tried clearing the filters and enabled inherited_members to see if I can solve myself, but it didn't work anyway.) however only Pydantic's own methods shows up, nothing more.

relay/models.py

from pydantic import BaseModel

class TestModel(BaseModel):
    a : int
    """test"""

    b : str
    """test 2"""

    c : Optional[str] = None

reference2.md

::: relay.models.TestModel
    selection:
      inherited_members: true
      filters: []

Expected behavior It should display attributes of a Pydantic model.

Screenshots resim

System (please complete the following information):

  • pytkdocs version: 0.12.0 (installed automatically with mkdocstrings==0.16.0)
  • Python version: 3.9.7 (x64)
  • OS: Windows 10

Additional context

  • pydantic version: 1.8.2

  • docs/requirements.txt

    mkdocs==1.2.2
    mkdocs-material==7.3.0
    mkdocs-autorefs==0.3.0
    mkdocstrings==0.16.0
    mkdocs-static-i18n>=0.19
    
  • mkdocs.yml (partial - only mkdocstrings part)

    plugins:
    - mkdocstrings:
      default_handler: python
      handlers:
        python:
          selection:
            inherited_members: true
            filters:
              - "!^_[^_]"
          rendering:
            show_root_heading: true
            heading_level: 1
            show_root_toc_entry: true
            show_root_full_path: false
            show_source: false
            show_bases: false
    
  • I also have a custom CSS to hide keyword arguments:

     .doc.doc-heading > code.highlight.language-python > span:not(:first-child) {
         display: none !important;
     }
    

Edit: Looks like attributes only shows up as table when I add Attributes section to model's own docstring. But I expected to see all attributes without adding them to model's own docstring.

ysfchn avatar Nov 15 '21 16:11 ysfchn

Hello @ysfchn, my apologies, I realize I never answered to your issue. Please note you can definitely ping me next time if you don't get an answer :sweat_smile:

Did you manage to find a workaround, or did you just stop using mkdocstrings? I kinda stopped working on pytkdocs because I was busy bringing an improved version to life (Griffe). Maybe you should try with the new Python handler :slightly_smiling_face:

pawamoy avatar Mar 06 '22 17:03 pawamoy

No problem! I realized the right way to do was defining all attributes in root of class definition instead of adding docstring under every field. So I closed the issue as it is not relevant anymore. I still use mkdocstrings and currently works great so far! 👍

ysfchn avatar Mar 06 '22 17:03 ysfchn

I see, thanks! I'm glad mkdocstrings is working for you :slightly_smiling_face:

pawamoy avatar Mar 06 '22 17:03 pawamoy

Hi, I'm having a similar issue, but the default always says required, I'm assuming that's because there's no __init__ method for it. This happens for all of my pydantic models here: https://icebotyt.github.io/pynoonlight

IceBotYT avatar Sep 10 '22 18:09 IceBotYT