from app.ai.tool_generator import OpenAPIToolGenerator def test_generates_tools_from_openapi_spec(): spec = { "paths": { "/tasks": { "post": { "operationId": "create_task", "summary": "Create task", "requestBody": { "content": { "application/json": { "schema": {"$ref": "#/components/schemas/TaskCreate"} } } }, } } }, "components": { "schemas": { "TaskCreate": { "type": "object", "required": ["title"], "properties": {"title": {"type": "string"}}, } } }, } tools = OpenAPIToolGenerator(spec).generate() assert tools[0].name == "create_task" assert tools[0].required == ["title"] assert tools[0].path == "/tasks" def test_generates_path_params_for_patch_tools(): spec = { "paths": { "/reservations/{reservation_id}": { "patch": { "operationId": "update_reservation", "requestBody": { "content": { "application/json": { "schema": { "type": "object", "properties": {"status": {"type": "string"}}, } } } }, } } } } tools = OpenAPIToolGenerator(spec).generate() assert tools[0].path_params == ["reservation_id"] assert "reservation_id" in tools[0].schema["required"]