Skip to content

Commit 1635048

Browse files
author
Marc-Andre Giroux
authored
Add an openapi-check ci check and dockerize it (github#18652)
1 parent 66dab1f commit 1635048

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

Dockerfile.openapi_decorator

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM node:14-alpine
2+
3+
RUN apk add --no-cache git python make g++
4+
5+
WORKDIR /openapi-check
6+
7+
RUN chown node:node /openapi-check -R
8+
9+
USER node
10+
11+
COPY --chown=node:node package.json /openapi-check
12+
COPY --chown=node:node package-lock.json /openapi-check
13+
ADD --chown=node:node script /openapi-check/script
14+
ADD --chown=node:node lib /openapi-check/lib
15+
ADD --chown=node:node content /openapi-check/content
16+
17+
RUN npm ci -D
18+
19+
ENTRYPOINT ["node", "/openapi-check/script/rest/openapi-check.js"]

docker-compose.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: '3.6'
2+
services:
3+
webapp:
4+
build:
5+
context: .
6+
dockerfile: Dockerfile.openapi_decorator
7+
image: 'openapi_decorator:${BUILD_SHA}'

script/rest/openapi-check.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env node
2+
3+
const program = require('commander')
4+
const getOperations = require('./utils/get-operations')
5+
6+
// [start-readme]
7+
//
8+
// Run this script to check if OpenAPI files can be decorated successfully.
9+
//
10+
// [end-readme]
11+
12+
program
13+
.description('Generate dereferenced OpenAPI and decorated schema files.')
14+
.requiredOption('-f, --files [files...]', 'A list of OpenAPI description files to check')
15+
.parse(process.argv)
16+
17+
const files = program.files
18+
19+
check(files)
20+
21+
async function check (files) {
22+
console.log('Verifying OpenAPI files are valid with decorator')
23+
24+
const schemas = files.map(filename => require(filename))
25+
26+
for (const schema of schemas) {
27+
try {
28+
// munge OpenAPI definitions object in an array of operations objects
29+
const operations = await getOperations(schema)
30+
// process each operation, asynchronously rendering markdown and stuff
31+
await Promise.all(operations.map(operation => operation.process()))
32+
33+
console.log('Successfully could decorate OpenAPI operations!')
34+
} catch (error) {
35+
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.')
37+
process.exit(1)
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)