validate-schema.js 521 B

12345678910111213141516171819
  1. #!/usr/bin/node
  2. import SwaggerParser from "@apidevtools/swagger-parser";
  3. import chalk from "chalk";
  4. import { getCompiledSchema } from "./schema/index.js";
  5. const log = console.log;
  6. getCompiledSchema().then(async (swaggerJSON) => {
  7. try {
  8. const api = await SwaggerParser.validate(swaggerJSON);
  9. console.log("API name: %s, Version: %s", api.info.title, api.info.version);
  10. log(chalk.green("❯ Schema is valid"));
  11. } catch (e) {
  12. console.error(e);
  13. log(chalk.red("❯", e.message), "\n");
  14. process.exit(1);
  15. }
  16. });