Skip to content

Commit

Permalink
chore: typing
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Dec 13, 2024
1 parent dae8e4f commit 9f2deb7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/llmling/tools/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
if TYPE_CHECKING:
from collections.abc import Callable

from jsonschema_path.typing import Schema


logger = get_logger(__name__)
T = TypeVar("T")
Expand Down Expand Up @@ -50,11 +52,11 @@ def __init__(
self.base_url = base_url
self.headers = headers or {}
self._client = httpx.AsyncClient(base_url=self.base_url, headers=self.headers)
self._spec: dict[str, Any] = {}
self._spec: Schema = {}
self._schemas: dict[str, Any] = {}
self._operations: dict[str, Any] = {}

def _store_spec(self, spec_data: dict[str, Any]) -> None:
def _store_spec(self, spec_data: Schema) -> None:
"""Helper to store and parse spec data."""
self._spec = spec_data
self._schemas = self._spec.get("components", {}).get("schemas", {})
Expand All @@ -70,7 +72,7 @@ def _ensure_loaded(self) -> None:
spec_data = self._load_spec()
self._store_spec(spec_data)

def _load_spec(self) -> dict[str, Any]:
def _load_spec(self) -> Schema:
"""Load OpenAPI specification."""
try:
if self.spec_url.startswith(("http://", "https://")):
Expand Down
7 changes: 6 additions & 1 deletion tests/test_openapi_toolsets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import json
from typing import TYPE_CHECKING

from openapi_spec_validator import validate
from openapi_spec_validator.exceptions import OpenAPISpecValidatorError
Expand All @@ -9,8 +10,12 @@
from llmling.tools.openapi import OpenAPITools


if TYPE_CHECKING:
from jsonschema_path.typing import Schema


BASE_URL = "https://api.example.com"
PETSTORE_SPEC = {
PETSTORE_SPEC: Schema = {
"openapi": "3.0.0",
"info": {"title": "Pet Store API", "version": "1.0.0"},
"paths": {
Expand Down

0 comments on commit 9f2deb7

Please sign in to comment.