Skip to content

Commit d0bae62

Browse files
Add test coverage for flatten_schema
The flatten_schema utility landed in #451 without its test, which was left behind in the downstream repo it was developed in. Port it over so the utility has coverage. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 5a84ddc commit d0bae62

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

tests/rpc.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
pick,
2929
)
3030
from reactivated.rpc.forms import get_form_schema
31+
from reactivated.rpc.utils import flatten_schema
3132

3233

3334
def unique_email() -> str:
@@ -842,6 +843,32 @@ def test_schema_generation_with_extra_fields(settings: Any, tmp_path: Any) -> No
842843
sys.path.remove(str(schema_dir))
843844

844845

846+
class _Color(enum.StrEnum):
847+
RED = "RED"
848+
GREEN = "GREEN"
849+
850+
851+
class _FlattenTarget(Pick):
852+
action: Literal["CREATE"]
853+
color: _Color
854+
items: list[Pick]
855+
856+
857+
def test_flatten_schema() -> None:
858+
schema = _FlattenTarget.model_json_schema()
859+
assert "$defs" in schema
860+
861+
result = flatten_schema(schema)
862+
serialized = json.dumps(result)
863+
864+
assert "$defs" not in result
865+
assert "$ref" not in serialized
866+
assert '"title"' not in serialized
867+
assert '"format"' not in serialized
868+
assert result["properties"]["action"]["const"] == "CREATE"
869+
assert result["properties"]["color"]["enum"] == ["RED", "GREEN"]
870+
871+
845872
def test_type_to_str_pick_holder() -> None:
846873
assert _type_to_str(MyPick) == f"{MyPick.get_name()}_output" # type: ignore[attr-defined]
847874

0 commit comments

Comments
 (0)