UNPKG

@kubb/cli

Version:

Command-line interface for Kubb, enabling easy generation of TypeScript, React-Query, Zod, and other code from OpenAPI specifications.

52 lines (50 loc) 1.27 kB
import { t as __name } from "./chunk-DKWOrOAv.js"; import { defineCommand, showUsage } from "citty"; import process from "node:process"; import { createJiti } from "jiti"; //#region src/commands/validate.ts const jiti = createJiti(import.meta.url, { sourceMaps: true }); const command = defineCommand({ meta: { name: "validate", description: "Validate a Swagger/OpenAPI file" }, args: { input: { type: "string", description: "Path to Swagger/OpenAPI file", alias: "i" }, help: { type: "boolean", description: "Show help", alias: "h", default: false } }, async run(commandContext) { const { args } = commandContext; if (args.help) return showUsage(command); if (args.input) { let mod; try { mod = await jiti.import("@kubb/oas", { default: true }); } catch (_e) { console.error(`Import of '@kubb/oas' is required to do validation`); process.exit(1); } const { parse } = mod; try { await (await parse(args.input)).validate(); console.log("✅ Validation success"); } catch (error) { console.error("❌ Validation failed"); console.log(error?.message); process.exit(1); } } } }); //#endregion export { command as default }; //# sourceMappingURL=validate-DOeZKiGx.js.map