Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

openapi-check.js 1.3 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  1. #!/usr/bin/env node
  2. const program = require('commander')
  3. const getOperations = require('./utils/get-operations')
  4. // [start-readme]
  5. //
  6. // Run this script to check if OpenAPI files can be decorated successfully.
  7. //
  8. // [end-readme]
  9. program
  10. .description('Generate dereferenced OpenAPI and decorated schema files.')
  11. .requiredOption('-f, --files [files...]', 'A list of OpenAPI description files to check')
  12. .parse(process.argv)
  13. const files = program.files
  14. check(files)
  15. async function check (files) {
  16. console.log('Verifying OpenAPI files are valid with decorator')
  17. const schemas = files.map(filename => require(filename))
  18. for (const schema of schemas) {
  19. try {
  20. // munge OpenAPI definitions object in an array of operations objects
  21. const operations = await getOperations(schema)
  22. // process each operation, asynchronously rendering markdown and stuff
  23. await Promise.all(operations.map(operation => operation.process()))
  24. console.log('Successfully could decorate OpenAPI operations!')
  25. } catch (error) {
  26. console.error(error)
  27. console.log('🐛 Whoops! It looks like the decorator script wasn\'t able to parse the dereferenced schema. A recent change may not yet be supported by the decorator. Please reach out in the #docs-engineering slack channel for help.')
  28. process.exit(1)
  29. }
  30. }
  31. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...