Skip to content

Fix pydantic field documentation for List/Set/Tuple #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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