|
| 1 | +/** |
| 2 | + * Base parser interface and shared types for API specification parsing. |
| 3 | + */ |
| 4 | + |
| 5 | +/** |
| 6 | + * Tool definition extracted from API specification |
| 7 | + */ |
| 8 | +export interface OCPTool { |
| 9 | + name: string; |
| 10 | + description: string; |
| 11 | + method: string; |
| 12 | + path: string; |
| 13 | + parameters: Record<string, any>; |
| 14 | + response_schema?: Record<string, any>; |
| 15 | + operation_id?: string; |
| 16 | + tags?: string[]; |
| 17 | +} |
| 18 | + |
| 19 | +/** |
| 20 | + * Complete API specification with tools |
| 21 | + */ |
| 22 | +export interface OCPAPISpec { |
| 23 | + base_url: string; |
| 24 | + title: string; |
| 25 | + version: string; |
| 26 | + description: string; |
| 27 | + tools: OCPTool[]; |
| 28 | + raw_spec: Record<string, any>; |
| 29 | + name?: string; |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Abstract base class for API specification parsers. |
| 34 | + * |
| 35 | + * Implement this interface to add support for new API specification formats |
| 36 | + * (e.g., Postman Collections, GraphQL schemas, Google Discovery format). |
| 37 | + */ |
| 38 | +export abstract class APISpecParser { |
| 39 | + /** |
| 40 | + * Determine if this parser can handle the given spec data. |
| 41 | + * |
| 42 | + * @param specData - The raw specification data |
| 43 | + * @returns True if this parser can parse the spec |
| 44 | + */ |
| 45 | + abstract canParse(specData: Record<string, any>): boolean; |
| 46 | + |
| 47 | + /** |
| 48 | + * Parse the specification and extract tools. |
| 49 | + * |
| 50 | + * @param specData - The raw specification data |
| 51 | + * @param baseUrlOverride - Optional base URL override |
| 52 | + * @param includeResources - Optional resource filter |
| 53 | + * @param pathPrefix - Optional path prefix for filtering |
| 54 | + * @returns Parsed API specification with tools |
| 55 | + */ |
| 56 | + abstract parse( |
| 57 | + specData: Record<string, any>, |
| 58 | + baseUrlOverride?: string, |
| 59 | + includeResources?: string[], |
| 60 | + pathPrefix?: string |
| 61 | + ): OCPAPISpec; |
| 62 | + |
| 63 | + /** |
| 64 | + * Get the human-readable name of this parser's format. |
| 65 | + * |
| 66 | + * @returns Format name (e.g., "OpenAPI", "Postman Collection") |
| 67 | + */ |
| 68 | + abstract getFormatName(): string; |
| 69 | +} |
0 commit comments