Chore/lint api defs (#4334)

* chore: update property names in redocly config.

* chore(api): lint the bundle output for openapi spec errors, set Cloud version, rename variable.

- Runs openapi-cli lint after generating the bundle output. This detects errors before pushing to openapi repo only to have the CI OATS validation fail. Only report the first 2 errors so we're not inundated with non-critical warnings.
- Renames INFLUXDB_VERSION to INFLUXDB_PLATFORM for clarity.
- Add a Cloud version to make the spec legal.
pull/4316/head^2
Jason Stirnaman 2022-08-12 11:48:21 -05:00 committed by GitHub
parent 5470549e3d
commit e64a59b4d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 8 deletions

View File

@ -103,7 +103,7 @@ function postProcess() {
# npm_config_yes=true npx overrides the prompt # npm_config_yes=true npx overrides the prompt
# and (vs. npx --yes) is compatible with npm@6 and npm@7. # and (vs. npx --yes) is compatible with npm@6 and npm@7.
specPath=$1 specPath=$1
version="$2" platform="$2"
apiVersion="$3" apiVersion="$3"
openapiCLI=" @redocly/cli" openapiCLI=" @redocly/cli"
@ -111,12 +111,18 @@ function postProcess() {
npx --version npx --version
# Use Redoc's openapi-cli to regenerate the spec with custom decorations. # Use Redoc's openapi-cli to regenerate the spec with custom decorations.
# If you want to lint the source contract (before bundling),
# pass `--lint` to the `bundle` command.
INFLUXDB_API_VERSION=$apiVersion \ INFLUXDB_API_VERSION=$apiVersion \
INFLUXDB_VERSION=$version \ INFLUXDB_PLATFORM=$platform \
npm_config_yes=true \ npm_config_yes=true \
npx $openapiCLI bundle $specPath \ npx $openapiCLI bundle $specPath \
--config=./.redocly.yaml \ -o $specPath \
-o $specPath --config=./.redocly.yaml
# Lint the bundle output.
npx $openapiCLI lint $specPath \
--max-problems 2
} }
function updateCloud { function updateCloud {

View File

@ -5,3 +5,4 @@ description: |
This documentation is generated from the This documentation is generated from the
[InfluxDB OpenAPI specification](https://raw.githubusercontent.com/influxdata/openapi/master/contracts/ref/cloud.yml). [InfluxDB OpenAPI specification](https://raw.githubusercontent.com/influxdata/openapi/master/contracts/ref/cloud.yml).
version: Cloud 2.x

View File

@ -2,7 +2,7 @@ const path = require('path');
const { toJSON } = require('../plugins/helpers/content-helper'); const { toJSON } = require('../plugins/helpers/content-helper');
function getVersion(filename) { function getVersion(filename) {
return path.join(__dirname, process.env.INFLUXDB_VERSION, return path.join(__dirname, process.env.INFLUXDB_PLATFORM,
(process.env.INFLUXDB_API_VERSION || ''), (process.env.INFLUXDB_API_VERSION || ''),
filename); filename);
} }

View File

@ -6,7 +6,7 @@ function replaceDocsUrl(field) {
* [^]* matches line breaks. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#using_regular_expression_on_multiple_lines * [^]* matches line breaks. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#using_regular_expression_on_multiple_lines
*/ */
const shortcode = /\{\{%([^]|\s)*?INFLUXDB_DOCS_URL([^]|\s)*?%\}\}/g const shortcode = /\{\{%([^]|\s)*?INFLUXDB_DOCS_URL([^]|\s)*?%\}\}/g
let replacement = `/influxdb/${process.env.INFLUXDB_VERSION}`; let replacement = `/influxdb/${process.env.INFLUXDB_PLATFORM}`;
return field.replaceAll(shortcode, replacement) return field.replaceAll(shortcode, replacement)
.replaceAll('https://docs.influxdata.com/influxdb/', '/influxdb/'); .replaceAll('https://docs.influxdata.com/influxdb/', '/influxdb/');
} }

View File

@ -11,10 +11,9 @@ function SetInfo() {
leave(info, ctx) { leave(info, ctx) {
if(data) { if(data) {
if(data.hasOwnProperty('title')) { if(data.hasOwnProperty('title')) {
info.title = data.title; info.title = data.title;
} }
if(data.hasOwnProperty('version')) { if(data.hasOwnProperty('version')) {
info.version = data.version; info.version = data.version;
} }
if(data.hasOwnProperty('description')) { if(data.hasOwnProperty('description')) {