Skip to content
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
1 change: 1 addition & 0 deletions newsfragments/3605.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Type target-manager request defaults as database dictionaries instead of arbitrary mappings.
1 change: 1 addition & 0 deletions newsfragments/3606.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Type parsed Target Manager request bodies using recursive JSON values.
19 changes: 14 additions & 5 deletions src/mock_vws/_flask_server/target_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import copy
import datetime
import json
from collections.abc import Callable, Mapping, Sequence
from collections.abc import Callable, Sequence
from enum import Enum, StrEnum, auto
from http import HTTPMethod, HTTPStatus
from typing import Annotated, NotRequired, TypedDict, TypeIs, assert_never
Expand All @@ -22,9 +22,18 @@
)
from pydantic_settings import BaseSettings

from mock_vws.database import CloudDatabase, VuMarkDatabase
from mock_vws.database import (
CloudDatabase,
CloudDatabaseDict,
VuMarkDatabase,
VuMarkDatabaseDict,
)
from mock_vws.database_type import DatabaseType
from mock_vws.model_target import ModelTargetDataset, OAuth2ClientCredential
from mock_vws.model_target import (
JSONValue,
ModelTargetDataset,
OAuth2ClientCredential,
)
from mock_vws.request_rate_limits import RequestRateLimit, RequestRateLimits
from mock_vws.states import States
from mock_vws.target import ImageTarget, VuMarkTarget
Expand Down Expand Up @@ -103,7 +112,7 @@ def validate(value: object) -> T:


@beartype
def _is_json_object(value: object, /) -> TypeIs[dict[str, object]]:
def _is_json_object(value: object, /) -> TypeIs[dict[str, JSONValue]]:
"""Whether a value parsed from JSON is an object.

JSON object keys are always strings.
Expand Down Expand Up @@ -329,7 +338,7 @@ def _validate_request_body[T: BaseModel](
*,
model: type[T],
data: bytes,
defaults: Mapping[str, object],
defaults: CloudDatabaseDict | VuMarkDatabaseDict,
) -> T:
"""Parse a request body as a JSON object and validate it as a model.

Expand Down
Loading