Skip to content

Commit

Permalink
Merge pull request #95 from shashankrnr32/shashankrnr32-patch-1
Browse files Browse the repository at this point in the history
Fix pydantic field documentation for List/Set/Tuple
  • Loading branch information
pawamoy authored Feb 25, 2021
2 parents ca30e50 + b99c661 commit beddb31
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pytkdocs/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ def get_pydantic_field_documentation(node: ObjectNode) -> Attribute:
path=path,
file_path=node.file_path,
docstring=prop.field_info.description,
attr_type=prop.type_,
attr_type=prop.outer_type_,
properties=properties,
)

Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/pydantic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Set

from pydantic import BaseModel, Field


Expand All @@ -6,3 +8,4 @@ class Person(BaseModel):

name: str = Field("PersonA", description="The person's name")
age: int = Field(18, description="The person's age which must be at minimum 18")
labels: Set[str] = Field(set(), description="Set of labels the person can be referred by")
5 changes: 5 additions & 0 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
from pathlib import Path
from typing import Set

import pytest
from marshmallow import fields
Expand Down Expand Up @@ -223,6 +224,10 @@ def test_loading_pydantic_model():
assert age_attr.type == int
assert age_attr.docstring == "The person's age which must be at minimum 18"
assert "pydantic-field" in age_attr.properties
labels_attr = next(attr for attr in obj.attributes if attr.name == "labels")
assert labels_attr.type == Set[str]
assert labels_attr.docstring == "Set of labels the person can be referred by"
assert "pydantic-field" in labels_attr.properties


def test_loading_marshmallow_model():
Expand Down

0 comments on commit beddb31

Please sign in to comment.