@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.26 kB
JavaScript
import { defineCommand, showUsage } from "citty";
import consola from "consola";
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) {
				consola.error(`Import of '@kubb/oas' is required to do validation`);
			}
			const { parse } = mod;
			try {
				await (await parse(args.input)).valdiate();
				consola.success("Validation success");
			} catch (e) {
				consola.fail("Validation failed");
				consola.log(e?.message);
				process.exit(1);
			}
		}
	}
});
var validate_default = command;
//#endregion
export { validate_default as default };
//# sourceMappingURL=validate-8i6chavn.js.map