# retoor from typing import Optional from pydantic import BaseModel from devplacepy.docs_api._shared import field from devplacepy.docs_examples import _is_optional, schema_example def test_field_nullable_parameter(): f = field("bio", "query", "string", False, "", "User biography", nullable=True) assert f["nullable"] is True f2 = field("username", "path", "string", True, "alice", "Target username") assert f2["nullable"] is False def test_is_optional_optional_type(): assert _is_optional(Optional[str]) is True assert _is_optional(Optional[int]) is True assert _is_optional(Optional[list[str]]) is True def test_is_optional_non_optional(): assert _is_optional(str) is False assert _is_optional(int) is False assert _is_optional(list[str]) is False assert _is_optional(dict) is False def test_schema_example_nullable_fields(): class NullableModel(BaseModel): name: str bio: Optional[str] = None age: int score: Optional[int] = None tags: Optional[list[str]] = None result = schema_example(NullableModel) assert result["name"] == "string" assert result["age"] == 0 assert result["bio"] is None assert result["score"] is None assert result["tags"] is None def test_schema_example_non_nullable_fields_unaffected(): class StrictModel(BaseModel): x: str y: int z: bool result = schema_example(StrictModel) assert result["x"] == "string" assert result["y"] == 0 assert result["z"] is False