openapi-diff.ts 941 B

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