Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import collections.abc
from collections import OrderedDict
import datetime
import decimal
import inspect
import sys
import typing
import typing_extensions
import uuid
from dataclasses import MISSING, Field, dataclass
from types import NoneType, UnionType
from typing_extensions import (
Expand Down Expand Up @@ -236,6 +239,31 @@ def convert_to_type_node(py_type: object) -> TypeNode:
if py_type is Self:
return ThisTypeReferenceNode

# Standard library types supported by Pydantic
if py_type is datetime.datetime:
return Annotated(
StringTypeReferenceNode,
"ISO 8601 date-time string (e.g., '2022-08-20T08:30:00.000Z')"
)
if py_type is datetime.date:
return Annotated(StringTypeReferenceNode, "ISO 8601 date string (e.g., '2022-08-20')")
if py_type is datetime.time:
return Annotated(StringTypeReferenceNode, "ISO 8601 time string (e.g., '08:30:00')")
if py_type is datetime.timedelta:
return Annotated(StringTypeReferenceNode, "ISO 8601 duration string (e.g., 'PT1H')")
if py_type is uuid.UUID:
return Annotated(
StringTypeReferenceNode,
"UUID string (e.g., '12345678-1234-5678-1234-567812345678')"
)
if py_type is decimal.Decimal:
return Annotated(StringTypeReferenceNode, "Decimal number string (e.g., '12.50')")
if py_type is bytes:
return Annotated(StringTypeReferenceNode, "Base64 encoded bytes or UTF-8 string")

if isinstance(py_type, Annotatedish):
return convert_to_type_node(py_type.__origin__)

# TODO: consider handling bare 'tuple' (and list, etc.)
# https://docs.python.org/3/library/typing.html#annotating-tuples
# Using plain tuple as an annotation is equivalent to using tuple[Any, ...]:
Expand Down