Skip to content

Commit

Permalink
Fix no URL validation for ModelSchema URLFields
Browse files Browse the repository at this point in the history
  • Loading branch information
lapinvert committed Aug 5, 2024
1 parent eecb05f commit 64f5b59
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions ninja/orm/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from typing import Any, Callable, Dict, List, Tuple, Type, TypeVar, Union, no_type_check
from uuid import UUID

from django.db.models import ManyToManyField
from django.db.models import ManyToManyField, URLField
from django.db.models.fields import Field as DjangoField
from pydantic import IPvAnyAddress
from pydantic import AnyUrl, IPvAnyAddress
from pydantic.fields import FieldInfo
from pydantic_core import PydanticUndefined, core_schema

Expand Down Expand Up @@ -69,6 +69,7 @@ def validate(cls, value: Any, _: Any) -> Any:
"SmallIntegerField": int,
"TextField": str,
"TimeField": datetime.time,
"URLField": AnyUrl,
"UUIDField": UUID,
# postgres fields:
"ArrayField": List,
Expand Down Expand Up @@ -148,6 +149,9 @@ def get_schema_field(
max_length = field_options.get("max_length")

internal_type = field.get_internal_type()
if isinstance(field, URLField):
internal_type = 'URLField'

python_type = TYPES[internal_type]

if field.primary_key or blank or null or optional:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_orm_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class Meta:
"smallintegerfield": {"type": "integer", "title": "Smallintegerfield"},
"textfield": {"type": "string", "title": "Textfield"},
"timefield": {"type": "string", "format": "time", "title": "Timefield"},
"urlfield": {"type": "string", "title": "Urlfield"},
"urlfield": {'format': 'uri', 'minLength': 1, 'title': 'Urlfield', 'type': 'string'},
"uuidfield": {"type": "string", "format": "uuid", "title": "Uuidfield"},
"arrayfield": {"type": "array", "items": {}, "title": "Arrayfield"},
"cicharfield": {"type": "string", "title": "Cicharfield"},
Expand Down

0 comments on commit 64f5b59

Please sign in to comment.