Accept glob patterns for source files in openapi-check script (#18965)
Co-authored-by: James M. Greene <JamesMGreene@github.com>
This commit is contained in:
committed by
GitHub
parent
bedc4d1401
commit
2deb8275da
@@ -4,4 +4,4 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile.openapi_decorator
|
dockerfile: Dockerfile.openapi_decorator
|
||||||
image: 'openapi_decorator:${BUILD_SHA}'
|
image: 'openapi_decorator'
|
||||||
|
|||||||
28729
package-lock.json
generated
28729
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -131,6 +131,7 @@
|
|||||||
"eslint-plugin-node": "^11.1.0",
|
"eslint-plugin-node": "^11.1.0",
|
||||||
"eslint-plugin-promise": "^4.2.1",
|
"eslint-plugin-promise": "^4.2.1",
|
||||||
"event-to-promise": "^0.8.0",
|
"event-to-promise": "^0.8.0",
|
||||||
|
"glob": "^7.1.6",
|
||||||
"graphql": "^14.5.8",
|
"graphql": "^14.5.8",
|
||||||
"heroku-client": "^3.1.0",
|
"heroku-client": "^3.1.0",
|
||||||
"http-status-code": "^2.1.0",
|
"http-status-code": "^2.1.0",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
const glob = require('glob')
|
||||||
const program = require('commander')
|
const program = require('commander')
|
||||||
const getOperations = require('./utils/get-operations')
|
const getOperations = require('./utils/get-operations')
|
||||||
|
|
||||||
@@ -11,29 +12,36 @@ const getOperations = require('./utils/get-operations')
|
|||||||
|
|
||||||
program
|
program
|
||||||
.description('Generate dereferenced OpenAPI and decorated schema files.')
|
.description('Generate dereferenced OpenAPI and decorated schema files.')
|
||||||
.requiredOption('-f, --files [files...]', 'A list of OpenAPI description files to check')
|
.requiredOption('-f, --files [files...]', 'A list of OpenAPI description files to check. Can parse literal glob patterns.')
|
||||||
.parse(process.argv)
|
.parse(process.argv)
|
||||||
|
|
||||||
const files = program.files
|
const filenames = program.files
|
||||||
|
|
||||||
check(files)
|
const filesToCheck = filenames.flatMap(filename => glob.sync(filename))
|
||||||
|
|
||||||
|
if (filesToCheck.length) {
|
||||||
|
check(filesToCheck)
|
||||||
|
} else {
|
||||||
|
console.log('No files to verify.')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
async function check (files) {
|
async function check (files) {
|
||||||
console.log('Verifying OpenAPI files are valid with decorator')
|
console.log('Verifying OpenAPI files are valid with decorator')
|
||||||
|
|
||||||
const schemas = files.map(filename => require(filename))
|
const documents = files.map(filename => [filename, require(filename)])
|
||||||
|
|
||||||
for (const schema of schemas) {
|
for (const [filename, schema] of documents) {
|
||||||
try {
|
try {
|
||||||
// munge OpenAPI definitions object in an array of operations objects
|
// munge OpenAPI definitions object in an array of operations objects
|
||||||
const operations = await getOperations(schema)
|
const operations = await getOperations(schema)
|
||||||
// process each operation, asynchronously rendering markdown and stuff
|
// process each operation, asynchronously rendering markdown and stuff
|
||||||
await Promise.all(operations.map(operation => operation.process()))
|
await Promise.all(operations.map(operation => operation.process()))
|
||||||
|
|
||||||
console.log('Successfully could decorate OpenAPI operations!')
|
console.log(`Successfully could decorate OpenAPI operations for document ${filename}`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
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.')
|
console.log(`🐛 Whoops! It looks like the decorator script wasn't able to parse the dereferenced schema in file ${filename}. A recent change may not yet be supported by the decorator. Please reach out in the #docs-engineering slack channel for help.`)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user