import { z } from 'zod'; import { validateWithWarnings } from '../lib/validator.js'; import { formatValidation } from '../utils/format.js'; import { successResponse, errorResponse } from '../lib/tool-response.js'; import type { ToolResponse } from '../lib/tool-response.js'; export const validateToolName = 'validate-spec'; export const validateToolDescription = 'Validate an OpenAPI/Swagger specification against the schema. Reports errors and warnings.'; export const validateToolSchema = { path: z.string().describe('Path to the OpenAPI/Swagger spec file (YAML or JSON)'), }; export async function validateToolHandler({ path }: { path: string }): Promise { try { const result = await validateWithWarnings(path); const text = formatValidation(result); return successResponse(text, { ...result }); } catch (err) { return errorResponse((err as Error).message, 'validating spec'); } }