Add an openapi-check ci check and dockerize it (#18652)
This commit is contained in:
committed by
GitHub
parent
66dab1fb8d
commit
1635048d0f
19
Dockerfile.openapi_decorator
Normal file
19
Dockerfile.openapi_decorator
Normal file
@@ -0,0 +1,19 @@
|
||||
FROM node:14-alpine
|
||||
|
||||
RUN apk add --no-cache git python make g++
|
||||
|
||||
WORKDIR /openapi-check
|
||||
|
||||
RUN chown node:node /openapi-check -R
|
||||
|
||||
USER node
|
||||
|
||||
COPY --chown=node:node package.json /openapi-check
|
||||
COPY --chown=node:node package-lock.json /openapi-check
|
||||
ADD --chown=node:node script /openapi-check/script
|
||||
ADD --chown=node:node lib /openapi-check/lib
|
||||
ADD --chown=node:node content /openapi-check/content
|
||||
|
||||
RUN npm ci -D
|
||||
|
||||
ENTRYPOINT ["node", "/openapi-check/script/rest/openapi-check.js"]
|
||||
7
docker-compose.yaml
Normal file
7
docker-compose.yaml
Normal file
@@ -0,0 +1,7 @@
|
||||
version: '3.6'
|
||||
services:
|
||||
webapp:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.openapi_decorator
|
||||
image: 'openapi_decorator:${BUILD_SHA}'
|
||||
40
script/rest/openapi-check.js
Executable file
40
script/rest/openapi-check.js
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const program = require('commander')
|
||||
const getOperations = require('./utils/get-operations')
|
||||
|
||||
// [start-readme]
|
||||
//
|
||||
// Run this script to check if OpenAPI files can be decorated successfully.
|
||||
//
|
||||
// [end-readme]
|
||||
|
||||
program
|
||||
.description('Generate dereferenced OpenAPI and decorated schema files.')
|
||||
.requiredOption('-f, --files [files...]', 'A list of OpenAPI description files to check')
|
||||
.parse(process.argv)
|
||||
|
||||
const files = program.files
|
||||
|
||||
check(files)
|
||||
|
||||
async function check (files) {
|
||||
console.log('Verifying OpenAPI files are valid with decorator')
|
||||
|
||||
const schemas = files.map(filename => require(filename))
|
||||
|
||||
for (const schema of schemas) {
|
||||
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!')
|
||||
} 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.')
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user