diff --git a/Dockerfile.openapi_decorator b/Dockerfile.openapi_decorator new file mode 100644 index 0000000000..a0e5a0c2e0 --- /dev/null +++ b/Dockerfile.openapi_decorator @@ -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"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000000..d95ee9b205 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,7 @@ +version: '3.6' +services: + webapp: + build: + context: . + dockerfile: Dockerfile.openapi_decorator + image: 'openapi_decorator:${BUILD_SHA}' diff --git a/script/rest/openapi-check.js b/script/rest/openapi-check.js new file mode 100755 index 0000000000..3d31a0ddc2 --- /dev/null +++ b/script/rest/openapi-check.js @@ -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) + } + } +}