openapi-diff.ts 956 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* eslint-env node */
  2. /* eslint import/no-nodejs-modules:0 */
  3. /* eslint import/no-unresolved:0 */
  4. import fs from 'fs';
  5. import https from 'https';
  6. import yaml from 'js-yaml';
  7. import jsonDiff from 'json-diff';
  8. async function main() {
  9. const openApiData = await new Promise((resolve, reject) =>
  10. https.get(
  11. `https://raw.githubusercontent.com/getsentry/sentry-api-schema/main/openapi-derefed.json`,
  12. res => {
  13. res.setEncoding('utf8');
  14. let rawData = '';
  15. res.on('data', chunk => (rawData += chunk));
  16. res.on('end', () => {
  17. try {
  18. resolve(JSON.parse(rawData));
  19. } catch (e) {
  20. reject(e.message);
  21. }
  22. });
  23. }
  24. )
  25. );
  26. const readFile = fs.readFileSync('tests/apidocs/openapi-derefed.json', 'utf8');
  27. const target = yaml.safeLoad(readFile);
  28. // eslint-disable-next-line no-console
  29. console.log(jsonDiff.diffString(openApiData, target));
  30. }
  31. main();