Skip to content

Commit beddb31

Browse files
authored
Merge pull request #95 from shashankrnr32/shashankrnr32-patch-1
Fix pydantic field documentation for List/Set/Tuple
2 parents ca30e50 + b99c661 commit beddb31

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/pytkdocs/loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ def get_pydantic_field_documentation(node: ObjectNode) -> Attribute:
679679
path=path,
680680
file_path=node.file_path,
681681
docstring=prop.field_info.description,
682-
attr_type=prop.type_,
682+
attr_type=prop.outer_type_,
683683
properties=properties,
684684
)
685685

tests/fixtures/pydantic.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Set
2+
13
from pydantic import BaseModel, Field
24

35

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

79
name: str = Field("PersonA", description="The person's name")
810
age: int = Field(18, description="The person's age which must be at minimum 18")
11+
labels: Set[str] = Field(set(), description="Set of labels the person can be referred by")

tests/test_loader.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import sys
55
from pathlib import Path
6+
from typing import Set
67

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

227232

228233
def test_loading_marshmallow_model():

0 commit comments

Comments
 (0)