зеркало из https://github.com/github/docs.git
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:
Родитель
bedc4d1401
Коммит
2deb8275da
|
@ -4,4 +4,4 @@ services:
|
|||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.openapi_decorator
|
||||
image: 'openapi_decorator:${BUILD_SHA}'
|
||||
image: 'openapi_decorator'
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче