Skip to content

Commit 2deb827

Browse files
Marc-Andre GirouxJamesMGreene
Marc-Andre Giroux
andauthoredApr 26, 2021
Accept glob patterns for source files in openapi-check script (#18965)
Co-authored-by: James M. Greene <JamesMGreene@github.com>
1 parent bedc4d1 commit 2deb827

File tree

4 files changed

+28686
-68
lines changed

4 files changed

+28686
-68
lines changed
 

‎docker-compose.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ services:
44
build:
55
context: .
66
dockerfile: Dockerfile.openapi_decorator
7-
image: 'openapi_decorator:${BUILD_SHA}'
7+
image: 'openapi_decorator'

‎package-lock.json

+28,669-60
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
"eslint-plugin-node": "^11.1.0",
132132
"eslint-plugin-promise": "^4.2.1",
133133
"event-to-promise": "^0.8.0",
134+
"glob": "^7.1.6",
134135
"graphql": "^14.5.8",
135136
"heroku-client": "^3.1.0",
136137
"http-status-code": "^2.1.0",

‎script/rest/openapi-check.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
22

3+
const glob = require('glob')
34
const program = require('commander')
45
const getOperations = require('./utils/get-operations')
56

@@ -11,29 +12,36 @@ const getOperations = require('./utils/get-operations')
1112

1213
program
1314
.description('Generate dereferenced OpenAPI and decorated schema files.')
14-
.requiredOption('-f, --files [files...]', 'A list of OpenAPI description files to check')
15+
.requiredOption('-f, --files [files...]', 'A list of OpenAPI description files to check. Can parse literal glob patterns.')
1516
.parse(process.argv)
1617

17-
const files = program.files
18+
const filenames = program.files
1819

19-
check(files)
20+
const filesToCheck = filenames.flatMap(filename => glob.sync(filename))
21+
22+
if (filesToCheck.length) {
23+
check(filesToCheck)
24+
} else {
25+
console.log('No files to verify.')
26+
process.exit(1)
27+
}
2028

2129
async function check (files) {
2230
console.log('Verifying OpenAPI files are valid with decorator')
2331

24-
const schemas = files.map(filename => require(filename))
32+
const documents = files.map(filename => [filename, require(filename)])
2533

26-
for (const schema of schemas) {
34+
for (const [filename, schema] of documents) {
2735
try {
2836
// munge OpenAPI definitions object in an array of operations objects
2937
const operations = await getOperations(schema)
3038
// process each operation, asynchronously rendering markdown and stuff
3139
await Promise.all(operations.map(operation => operation.process()))
3240

33-
console.log('Successfully could decorate OpenAPI operations!')
41+
console.log(`Successfully could decorate OpenAPI operations for document ${filename}`)
3442
} catch (error) {
3543
console.error(error)
36-
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.')
44+
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.`)
3745
process.exit(1)
3846
}
3947
}

0 commit comments

Comments
 (0)
Please sign in to comment.