openapi-diff.ts 925 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* eslint-env node */
  2. /* eslint import/no-unresolved:0 */
  3. import yaml from 'js-yaml';
  4. import jsonDiff from 'json-diff';
  5. import fs from 'node:fs';
  6. import https from 'node:https';
  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();