openapi-diff.ts 926 B

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