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:
Marc-Andre Giroux 2021-04-26 17:56:12 -04:00 коммит произвёл GitHub
Родитель bedc4d1401
Коммит 2deb8275da
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 28686 добавлений и 68 удалений

Просмотреть файл

@ -4,4 +4,4 @@ services:
build:
context: .
dockerfile: Dockerfile.openapi_decorator
image: 'openapi_decorator:${BUILD_SHA}'
image: 'openapi_decorator'

28729
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -131,6 +131,7 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"event-to-promise": "^0.8.0",
"glob": "^7.1.6",
"graphql": "^14.5.8",
"heroku-client": "^3.1.0",
"http-status-code": "^2.1.0",

Просмотреть файл

@ -1,5 +1,6 @@
#!/usr/bin/env node
const glob = require('glob')
const program = require('commander')
const getOperations = require('./utils/get-operations')
@ -11,29 +12,36 @@ const getOperations = require('./utils/get-operations')
program
.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)
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) {
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 {
// munge OpenAPI definitions object in an array of operations objects
const operations = await getOperations(schema)
// process each operation, asynchronously rendering markdown and stuff
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) {
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)
}
}