Skip to content
Merged

Dev #92

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 core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "utcp"
version = "1.1.2"
version = "1.1.3"
authors = [
{ name = "UTCP Contributors" },
]
Expand Down
2 changes: 2 additions & 0 deletions core/src/utcp/data/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class JsonSchema(BaseModel):
default: Optional schema default value.
format: Optional schema format.
additionalProperties: Optional schema additional properties.
examples: Optional list of example values for the schema.
"""
schema_: Optional[str] = Field(None, alias="$schema")
id_: Optional[str] = Field(None, alias="$id")
Expand All @@ -50,6 +51,7 @@ class JsonSchema(BaseModel):
enum: Optional[List[JsonType]] = None
const: Optional[JsonType] = None
default: Optional[JsonType] = None
examples: Optional[List[JsonType]] = None
format: Optional[str] = None
additionalProperties: Optional[Union[bool, "JsonSchema"]] = None
pattern: Optional[str] = None
Expand Down
Empty file added core/tests/data/__init__.py
Empty file.
38 changes: 38 additions & 0 deletions core/tests/data/test_tool_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Tests for the JsonSchema model, including the `examples` field."""

from utcp.data.tool import JsonSchema, JsonSchemaSerializer


def test_jsonschema_examples_field_is_typed():
"""`examples` is a declared field, not just an extra attribute."""
assert "examples" in JsonSchema.model_fields

schema = JsonSchema(type="string", examples=["user123", "user456"])
assert schema.examples == ["user123", "user456"]


def test_jsonschema_examples_default_none():
"""`examples` defaults to None when absent."""
schema = JsonSchema(type="string")
assert schema.examples is None


def test_jsonschema_examples_roundtrip():
"""`examples` survives serialize -> validate roundtrip."""
serializer = JsonSchemaSerializer()
schema = JsonSchema(
type="object",
examples=[{"id": "user123", "name": "John Doe"}],
)

as_dict = serializer.to_dict(schema)
assert as_dict["examples"] == [{"id": "user123", "name": "John Doe"}]

restored = serializer.validate_dict(as_dict)
assert restored.examples == schema.examples


def test_jsonschema_examples_allows_mixed_json_types():
"""`examples` accepts any JSON value (string, bool, number, object)."""
schema = JsonSchema(examples=["a", True, 1, 1.5, None, {"k": "v"}, [1, 2]])
assert schema.examples == ["a", True, 1, 1.5, None, {"k": "v"}, [1, 2]]
3 changes: 2 additions & 1 deletion plugins/communication_protocols/gql/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "utcp-gql"
version = "1.1.0"
version = "1.1.4"
authors = [
{ name = "UTCP Contributors" },
]
Expand All @@ -14,6 +14,7 @@ requires-python = ">=3.10"
dependencies = [
"pydantic>=2.0",
"gql>=3.0",
"aiohttp>=3.8",
"utcp>=1.1"
]
classifiers = [
Expand Down
Loading
Loading