fix: resolve pyright bad-index errors in parser.py (#32507)
Some checks failed
autofix.ci / autofix (push) Has been cancelled
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Has been cancelled
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Has been cancelled
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Has been cancelled
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Has been cancelled
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Has been cancelled
Main CI Pipeline / Check Changed Files (push) Has been cancelled
Main CI Pipeline / API Tests (push) Has been cancelled
Main CI Pipeline / Web Tests (push) Has been cancelled
Main CI Pipeline / Style Check (push) Has been cancelled
Main CI Pipeline / VDB Tests (push) Has been cancelled
Main CI Pipeline / DB Migration Test (push) Has been cancelled

This commit is contained in:
Tyson Cung
2026-02-24 16:29:17 +08:00
committed by GitHub
parent 0eaae4f573
commit 84533cbfe0

View File

@@ -2,7 +2,7 @@ import re
from json import dumps as json_dumps from json import dumps as json_dumps
from json import loads as json_loads from json import loads as json_loads
from json.decoder import JSONDecodeError from json.decoder import JSONDecodeError
from typing import Any from typing import Any, TypedDict
import httpx import httpx
from flask import request from flask import request
@@ -14,6 +14,12 @@ from core.tools.entities.tool_entities import ApiProviderSchemaType, ToolParamet
from core.tools.errors import ToolApiSchemaError, ToolNotSupportedError, ToolProviderNotFoundError from core.tools.errors import ToolApiSchemaError, ToolNotSupportedError, ToolProviderNotFoundError
class _OpenAPIInterface(TypedDict):
path: str
method: str
operation: dict[str, Any]
class ApiBasedToolSchemaParser: class ApiBasedToolSchemaParser:
@staticmethod @staticmethod
def parse_openapi_to_tool_bundle( def parse_openapi_to_tool_bundle(
@@ -35,17 +41,17 @@ class ApiBasedToolSchemaParser:
server_url = matched_servers[0] if matched_servers else server_url server_url = matched_servers[0] if matched_servers else server_url
# list all interfaces # list all interfaces
interfaces = [] interfaces: list[_OpenAPIInterface] = []
for path, path_item in openapi["paths"].items(): for path, path_item in openapi["paths"].items():
methods = ["get", "post", "put", "delete", "patch", "head", "options", "trace"] methods = ["get", "post", "put", "delete", "patch", "head", "options", "trace"]
for method in methods: for method in methods:
if method in path_item: if method in path_item:
interfaces.append( interfaces.append(
{ _OpenAPIInterface(
"path": path, path=path,
"method": method, method=method,
"operation": path_item[method], operation=path_item[method],
} )
) )
# get all parameters # get all parameters