Files
romm/backend/tests/utils/test_openapi.py
Georges-Antoine Assi 808239db37 refactor(streaming): generate the remaining streaming API types from the backend
The launch socket payloads, the 409 busy detail and the card-import answer
were hand-written in services/api/streaming.ts and could drift from the
backend models they mirror.

- Publish Socket.IO payload models into the OpenAPI components
  (utils/openapi.py), starting with the three streaming launch events.
- Raise the busy 409 from a ContainerBusyDetail model and declare it on
  the game and desktop claim routes.
- Derive MemoryCardImport from ClaimStreamingSessionRequest, and type the
  list and control calls with their generated response models.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 20:57:36 -04:00

52 lines
1016 B
Python

from fastapi import FastAPI
from pydantic import BaseModel
from utils.openapi import publish_socket_payloads
class _Inner(BaseModel):
value: int
class _Payload(BaseModel):
name: str
inner: _Inner
class _Route(BaseModel):
ok: bool
def _app() -> FastAPI:
app = FastAPI()
@app.get("/route")
def route() -> _Route:
return _Route(ok=True)
publish_socket_payloads(app, [_Payload])
return app
def test_payload_and_its_nested_models_join_route_schemas():
schemas = _app().openapi()["components"]["schemas"]
assert "_Route" in schemas
assert schemas["_Payload"]["properties"]["inner"] == {
"$ref": "#/components/schemas/_Inner"
}
assert "_Inner" in schemas
def test_schema_is_built_once():
app = _app()
assert app.openapi() is app.openapi()
def test_app_without_routes_still_gets_the_payloads():
app = FastAPI()
publish_socket_payloads(app, [_Payload])
assert "_Payload" in app.openapi()["components"]["schemas"]