validate-schema.js 526 B

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