From ca28155f4ded447e2652128fd097cb91c9fe5548 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 1 Feb 2026 16:20:35 +0000 Subject: [PATCH] Initial upload with CI/CD workflow --- src/utils/search.py | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/utils/search.py diff --git a/src/utils/search.py b/src/utils/search.py new file mode 100644 index 0000000..5e3b8fb --- /dev/null +++ b/src/utils/search.py @@ -0,0 +1,66 @@ +from typing import List, Dict, Any +from ..core.parser import load_spec_file + + +def search_endpoints(spec_path: str, query: str, limit: int = 10) -> List[Dict[str, Any]]: + """Search for endpoints matching the query. + + Args: + spec_path: Path to the OpenAPI spec file + query: Search query string + limit: Maximum number of results to return + + Returns: + List of matching endpoints + """ + spec = load_spec_file(spec_path) + results = [] + query_lower = query.lower() + + for path, methods in spec.get('paths', {}).items(): + for method, details in methods.items(): + if method.lower() not in ['get', 'post', 'put', 'delete', 'patch', 'options', 'head']: + continue + + match_score = 0 + matches = [] + + path_match = query_lower in path.lower() + if path_match: + match_score += 10 + matches.append(f"Path: {path}") + + summary = details.get('summary', '') or '' + if query_lower in summary.lower(): + match_score += 5 + matches.append(f"Summary: {summary}") + + description = details.get('description', '') or '' + if query_lower in description.lower(): + match_score += 3 + matches.append(f"Description: {description[:100]}...") + + tags = details.get('tags', []) + for tag in tags: + if query_lower in tag.lower(): + match_score += 4 + matches.append(f"Tag: {tag}") + + operation_id = details.get('operationId', '') or '' + if query_lower in operation_id.lower(): + match_score += 2 + + if match_score > 0: + results.append({ + 'path': path, + 'method': method.upper(), + 'summary': details.get('summary'), + 'description': details.get('description'), + 'tags': tags, + 'operation_id': operation_id, + 'score': match_score, + 'matches': matches + }) + + results.sort(key=lambda x: x['score'], reverse=True) + return results[:limit]