fix(api): don't return list for runtime tools

Use Response object instead.

Enforce no GET endpoints return lists.

Signed-off-by: Ihar Hrachyshka <ihar.hrachyshka@gmail.com>
This commit is contained in:
Ihar Hrachyshka 2025-03-18 18:22:48 -04:00
parent b440a1dc42
commit 508381a81d
13 changed files with 167 additions and 105 deletions

View file

@ -2688,9 +2688,9 @@
"200": {
"description": "OK",
"content": {
"application/jsonl": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ToolDef"
"$ref": "#/components/schemas/ListToolDefsResponse"
}
}
}
@ -8328,6 +8328,22 @@
],
"title": "ListRoutesResponse"
},
"ListToolDefsResponse": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ToolDef"
}
}
},
"additionalProperties": false,
"required": [
"data"
],
"title": "ListToolDefsResponse"
},
"ListScoringFunctionsResponse": {
"type": "object",
"properties": {

View file

@ -1855,9 +1855,9 @@ paths:
'200':
description: OK
content:
application/jsonl:
application/json:
schema:
$ref: '#/components/schemas/ToolDef'
$ref: '#/components/schemas/ListToolDefsResponse'
'400':
$ref: '#/components/responses/BadRequest400'
'429':
@ -5732,6 +5732,17 @@ components:
required:
- data
title: ListRoutesResponse
ListToolDefsResponse:
type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/ToolDef'
additionalProperties: false
required:
- data
title: ListToolDefsResponse
ListScoringFunctionsResponse:
type: object
properties:

View file

@ -135,6 +135,17 @@ def _validate_api_method_return_type(method) -> str | None:
return "returns Optional type"
def _validate_api_method_doesnt_return_list(method) -> str | None:
hints = get_type_hints(method)
if 'return' not in hints:
return "has no return type annotation"
return_type = hints['return']
if get_origin(return_type) is list:
return "returns a list"
def _validate_api_delete_method_returns_none(method) -> str | None:
hints = get_type_hints(method)
@ -167,6 +178,7 @@ _VALIDATORS = {
"GET": [
_validate_api_method_return_type,
_validate_list_parameters_contain_data,
_validate_api_method_doesnt_return_list,
],
"DELETE": [
_validate_api_delete_method_returns_none,