Skip to content

Commit dd2b07c

Browse files
committed
chore(api-ref): Uplift API reference docs:
- Adapts code from @jstirnaman's demo site to generate Hugo pages from OpenAPI paths in the InfluxDB spec files. - Uses Rapidoc to render the OpenAPI path in a page--effectively treating each endpoint as a standalone API for faster loading. - Run yarn install and then Executing: api-docs/getswagger.sh cloud-v2 -B No URL was provided. I'll rebuild from the existing spec /Users/ja/Documents/github/docs-v2/api-docs/cloud/v2/ref.yml 10.8.2 Generating OpenAPI path files in static/openapi/influxdb-cloud-v2/paths.... Generating OpenAPI article data in data/article-data/influxdb/cloud-v2... Executing: HUGO_DATAPAGES_DATA_PATH=data/article-data/influxdb/cloud-v2 HUGO_DATAPAGES_ELEMENT=articles HUGO_DATAPAGES_TYPE=api HUGO_DATAPAGES_CONTENT_PATH=content/influxdb/cloud/api/v2 node hugo-data-to-pages/hugo.js clean --force Removing data-generated files... Removed folder: ./content/influxdb/cloud/api/v2/api-v2-authorizations Removed folder: ./content/influxdb/cloud/api/v2/api-v2-buckets Removed folder: ./content/influxdb/cloud/api/v2/api-v2-checks Removed folder: ./content/influxdb/cloud/api/v2/api-v2-dashboards Removed folder: ./content/influxdb/cloud/api/v2/api-v2-dbrps Removed folder: ./content/influxdb/cloud/api/v2/api-v2-delete Removed folder: ./content/influxdb/cloud/api/v2/api-v2-flags Removed folder: ./content/influxdb/cloud/api/v2/api-v2-labels Removed folder: ./content/influxdb/cloud/api/v2/api-v2-maps Removed folder: ./content/influxdb/cloud/api/v2/api-v2-me Removed folder: ./content/influxdb/cloud/api/v2/api-v2-notificationEndpoints Removed folder: ./content/influxdb/cloud/api/v2/api-v2-notificationRules Removed folder: ./content/influxdb/cloud/api/v2/api-v2-orgs Removed folder: ./content/influxdb/cloud/api/v2/api-v2-query Removed folder: ./content/influxdb/cloud/api/v2/api-v2-resources Removed folder: ./content/influxdb/cloud/api/v2/api-v2-scripts Removed folder: ./content/influxdb/cloud/api/v2/api-v2-setup Removed folder: ./content/influxdb/cloud/api/v2/api-v2-signin Removed folder: ./content/influxdb/cloud/api/v2/api-v2-signout Removed folder: ./content/influxdb/cloud/api/v2/api-v2-stacks Removed folder: ./content/influxdb/cloud/api/v2/api-v2-tasks Removed folder: ./content/influxdb/cloud/api/v2/api-v2-telegraf Removed folder: ./content/influxdb/cloud/api/v2/api-v2-telegrafs Removed folder: ./content/influxdb/cloud/api/v2/api-v2-templates Removed folder: ./content/influxdb/cloud/api/v2/api-v2-users Removed folder: ./content/influxdb/cloud/api/v2/api-v2-variables Removed folder: ./content/influxdb/cloud/api/v2/api-v2-write Removed folder: ./content/influxdb/cloud/api/v2/api-v2 Removed folder: ./content/influxdb/cloud/api/v2/legacy-authorizations Removed folder: ./content/influxdb/cloud/api/v2/ping Removed folder: ./content/influxdb/cloud/api/v2/query Removed folder: ./content/influxdb/cloud/api/v2/write Done! Executing: HUGO_DATAPAGES_DATA_PATH=data/article-data/influxdb/cloud-v2 HUGO_DATAPAGES_ELEMENT=articles HUGO_DATAPAGES_TYPE=api HUGO_DATAPAGES_CONTENT_PATH=content/influxdb/cloud/api/v2 node hugo-data-to-pages/hugo.js generate Building data-generated files... Created file: ./content/influxdb/cloud/api/v2/api-v2-authorizations/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-buckets/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-checks/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-dashboards/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-dbrps/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-delete/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-flags/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-labels/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-maps/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-me/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-notificationEndpoints/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-notificationRules/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-orgs/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-query/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-resources/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-scripts/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-setup/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-signin/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-signout/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-stacks/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-tasks/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-telegraf/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-telegrafs/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-templates/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-users/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-variables/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2-write/index.md Created file: ./content/influxdb/cloud/api/v2/api-v2/index.md Created file: ./content/influxdb/cloud/api/v2/legacy-authorizations/index.md Created file: ./content/influxdb/cloud/api/v2/ping/index.md Created file: ./content/influxdb/cloud/api/v2/query/index.md Created file: ./content/influxdb/cloud/api/v2/write/index.md Done! Executing: api-docs/getswagger.sh oss-v2 -B No URL was provided. I'll rebuild from the existing spec /Users/ja/Documents/github/docs-v2/api-docs/v2/ref.yml 10.8.2 Generating OpenAPI path files in static/openapi/influxdb-oss-v2/paths.... Generating OpenAPI article data in data/article-data/influxdb/oss-v2... Executing: HUGO_DATAPAGES_DATA_PATH=data/article-data/influxdb/oss-v2 HUGO_DATAPAGES_ELEMENT=articles HUGO_DATAPAGES_TYPE=api HUGO_DATAPAGES_CONTENT_PATH=content/influxdb/v2/api/v2 node hugo-data-to-pages/hugo.js clean --force Removing data-generated files... Removed folder: ./content/influxdb/v2/api/v2/api-v2-authorizations Removed folder: ./content/influxdb/v2/api/v2/api-v2-backup Removed folder: ./content/influxdb/v2/api/v2/api-v2-buckets Removed folder: ./content/influxdb/v2/api/v2/api-v2-checks Removed folder: ./content/influxdb/v2/api/v2/api-v2-config Removed folder: ./content/influxdb/v2/api/v2/api-v2-dashboards Removed folder: ./content/influxdb/v2/api/v2/api-v2-dbrps Removed folder: ./content/influxdb/v2/api/v2/api-v2-delete Removed folder: ./content/influxdb/v2/api/v2/api-v2-flags Removed folder: ./content/influxdb/v2/api/v2/api-v2-labels Removed folder: ./content/influxdb/v2/api/v2/api-v2-maps Removed folder: ./content/influxdb/v2/api/v2/api-v2-me Removed folder: ./content/influxdb/v2/api/v2/api-v2-notificationEndpoints Removed folder: ./content/influxdb/v2/api/v2/api-v2-notificationRules Removed folder: ./content/influxdb/v2/api/v2/api-v2-orgs Removed folder: ./content/influxdb/v2/api/v2/api-v2-query Removed folder: ./content/influxdb/v2/api/v2/api-v2-remotes Removed folder: ./content/influxdb/v2/api/v2/api-v2-replications Removed folder: ./content/influxdb/v2/api/v2/api-v2-resources Removed folder: ./content/influxdb/v2/api/v2/api-v2-restore Removed folder: ./content/influxdb/v2/api/v2/api-v2-scrapers Removed folder: ./content/influxdb/v2/api/v2/api-v2-setup Removed folder: ./content/influxdb/v2/api/v2/api-v2-signin Removed folder: ./content/influxdb/v2/api/v2/api-v2-signout Removed folder: ./content/influxdb/v2/api/v2/api-v2-sources Removed folder: ./content/influxdb/v2/api/v2/api-v2-stacks Removed folder: ./content/influxdb/v2/api/v2/api-v2-tasks Removed folder: ./content/influxdb/v2/api/v2/api-v2-telegraf Removed folder: ./content/influxdb/v2/api/v2/api-v2-telegrafs Removed folder: ./content/influxdb/v2/api/v2/api-v2-templates Removed folder: ./content/influxdb/v2/api/v2/api-v2-users Removed folder: ./content/influxdb/v2/api/v2/api-v2-variables Removed folder: ./content/influxdb/v2/api/v2/api-v2-write Removed folder: ./content/influxdb/v2/api/v2/api-v2 Removed folder: ./content/influxdb/v2/api/v2/debug-pprof-all Removed folder: ./content/influxdb/v2/api/v2/debug-pprof-allocs Removed folder: ./content/influxdb/v2/api/v2/debug-pprof-block Removed folder: ./content/influxdb/v2/api/v2/debug-pprof-cmdline Removed folder: ./content/influxdb/v2/api/v2/debug-pprof-goroutine Removed folder: ./content/influxdb/v2/api/v2/debug-pprof-heap Removed folder: ./content/influxdb/v2/api/v2/debug-pprof-mutex Removed folder: ./content/influxdb/v2/api/v2/debug-pprof-profile Removed folder: ./content/influxdb/v2/api/v2/debug-pprof-threadcreate Removed folder: ./content/influxdb/v2/api/v2/debug-pprof-trace Removed folder: ./content/influxdb/v2/api/v2/health Removed folder: ./content/influxdb/v2/api/v2/legacy-authorizations Removed folder: ./content/influxdb/v2/api/v2/metrics Removed folder: ./content/influxdb/v2/api/v2/ping Removed folder: ./content/influxdb/v2/api/v2/query Removed folder: ./content/influxdb/v2/api/v2/ready Removed folder: ./content/influxdb/v2/api/v2/write Done! Executing: HUGO_DATAPAGES_DATA_PATH=data/article-data/influxdb/oss-v2 HUGO_DATAPAGES_ELEMENT=articles HUGO_DATAPAGES_TYPE=api HUGO_DATAPAGES_CONTENT_PATH=content/influxdb/v2/api/v2 node hugo-data-to-pages/hugo.js generate Building data-generated files... Created file: ./content/influxdb/v2/api/v2/api-v2-authorizations/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-backup/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-buckets/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-checks/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-config/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-dashboards/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-dbrps/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-delete/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-flags/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-labels/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-maps/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-me/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-notificationEndpoints/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-notificationRules/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-orgs/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-query/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-remotes/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-replications/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-resources/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-restore/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-scrapers/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-setup/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-signin/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-signout/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-sources/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-stacks/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-tasks/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-telegraf/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-telegrafs/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-templates/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-users/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-variables/index.md Created file: ./content/influxdb/v2/api/v2/api-v2-write/index.md Created file: ./content/influxdb/v2/api/v2/api-v2/index.md Created file: ./content/influxdb/v2/api/v2/debug-pprof-all/index.md Created file: ./content/influxdb/v2/api/v2/debug-pprof-allocs/index.md Created file: ./content/influxdb/v2/api/v2/debug-pprof-block/index.md Created file: ./content/influxdb/v2/api/v2/debug-pprof-cmdline/index.md Created file: ./content/influxdb/v2/api/v2/debug-pprof-goroutine/index.md Created file: ./content/influxdb/v2/api/v2/debug-pprof-heap/index.md Created file: ./content/influxdb/v2/api/v2/debug-pprof-mutex/index.md Created file: ./content/influxdb/v2/api/v2/debug-pprof-profile/index.md Created file: ./content/influxdb/v2/api/v2/debug-pprof-threadcreate/index.md Created file: ./content/influxdb/v2/api/v2/debug-pprof-trace/index.md Created file: ./content/influxdb/v2/api/v2/health/index.md Created file: ./content/influxdb/v2/api/v2/legacy-authorizations/index.md Created file: ./content/influxdb/v2/api/v2/metrics/index.md Created file: ./content/influxdb/v2/api/v2/ping/index.md Created file: ./content/influxdb/v2/api/v2/query/index.md Created file: ./content/influxdb/v2/api/v2/ready/index.md Created file: ./content/influxdb/v2/api/v2/write/index.md Done! to generate the paths, metadata, and pages.
1 parent 4045a6c commit dd2b07c

File tree

19 files changed

+1924
-63
lines changed

19 files changed

+1924
-63
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ node_modules
1010
.hugo_build.lock
1111
/content/influxdb/*/api/**/*.html
1212
/api-docs/redoc-static.html*
13+
/content/influxdb/*/api/**
14+
/static/openapi
1315
.vscode/*
1416
.idea
1517
**/config.toml

api-docs/cloud/v2/ref.yml

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ info:
1212
url: https://opensource.org/licenses/MIT
1313
summary: The InfluxDB v2 HTTP API provides a programmatic interface for all interactions with InfluxDB v2.
1414
servers:
15-
- url: https://{baseurl}
16-
description: InfluxDB Cloud API URL
17-
variables:
18-
baseurl:
19-
enum:
20-
- us-east-1-1.aws.cloud2.influxdata.com
21-
default: us-east-1-1.aws.cloud2.influxdata.com
22-
description: InfluxDB Cloud URL
15+
- url: /
2316
security:
2417
- TokenAuthentication: []
2518
tags:
@@ -14600,9 +14593,9 @@ components:
1460014593
properties:
1460114594
results:
1460214595
description: |
14603-
A resultset object that contains the `statement_id` and the `series` array.
14596+
A resultset object that contains the `statement_id` and the `series` array.
1460414597

14605-
Except for `statement_id`, all properties are optional and omitted if empty. If a property is not present, it is assumed to be `null`.
14598+
Except for `statement_id`, all properties are optional and omitted if empty. If a property is not present, it is assumed to be `null`.
1460614599
items:
1460714600
properties:
1460814601
error:
@@ -14651,12 +14644,12 @@ components:
1465114644
type: integer
1465214645
type: object
1465314646
oneOf:
14654-
- required:
14655-
- statement_id
14656-
- error
14657-
- required:
14658-
- statement_id
14659-
- series
14647+
- required:
14648+
- statement_id
14649+
- error
14650+
- required:
14651+
- statement_id
14652+
- series
1466014653
type: array
1466114654
type: object
1466214655
IntegerLiteral:

api-docs/getswagger.sh

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121
# sh ./getswagger.sh -c <product> -o <version> -B
2222
#
2323
# Examples:
24-
# sh ./getswagger.sh cloud-serverless
24+
# sh ./getswagger.sh cloud-serverless-v2
2525
# sh ./getswagger.sh clustered -B
26-
# sh ./getswagger.sh cloud
27-
# sh ./getswagger.sh -c v2 -o v2.0 -b file:///Users/johnsmith/github/openapi
26+
# sh ./getswagger.sh cloud-v2
27+
# sh ./getswagger.sh -c oss-v2 -b file:///Users/johnsmith/github/openapi
28+
29+
DOCS_ROOT=$(git rev-parse --show-toplevel)
30+
API_DOCS_ROOT=$DOCS_ROOT/api-docs
2831

2932
versionDirs=($(ls -d */))
3033
latestOSS=${versionDirs[${#versionDirs[@]}-1]}
@@ -62,7 +65,7 @@ function showHelp {
6265
subcommand=$1
6366

6467
case "$subcommand" in
65-
cloud-dedicated-v2|cloud-dedicated-management|cloud-serverless-v2|clustered-v2|cloud-v2|v2|v1-compat|all)
68+
cloud-dedicated-v2|cloud-dedicated-management|cloud-serverless-v2|clustered-v2|cloud-v2|oss-v2|v2|v1-compat|all)
6669
product=$1
6770
shift
6871

@@ -117,7 +120,6 @@ function postProcess() {
117120
api="$3"
118121

119122
openapiCLI=" @redocly/cli"
120-
currentPath=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
121123

122124
# TODO: Move some of this into the plugin:
123125

@@ -131,101 +133,112 @@ function postProcess() {
131133
npx --version
132134
INFLUXDB_PRODUCT=$(dirname "$configPath") \
133135
INFLUXDB_API_NAME=$(echo "$api" | sed 's/@.*//g;') \
134-
API_DOCS_ROOT_PATH=$currentPath \
136+
API_DOCS_ROOT_PATH=$API_DOCS_ROOT \
135137
npm_config_yes=true \
136138
npx $openapiCLI bundle $specPath \
137139
-o $specPath \
138140
--config=$configPath
139141
}
140142

141-
function updateCloudV2 {
142-
outFile="cloud/v2/ref.yml"
143+
function updateOSS {
144+
outFile="$API_DOCS_ROOT/v2/ref.yml"
145+
if [[ -z "$baseUrlOSS" ]];
146+
then
147+
echo "No URL was provided. I'll rebuild from the existing spec $outFile"
148+
else
149+
curl $UPDATE_OPTIONS ${baseUrlOSS}/contracts/ref/oss.yml -o $outFile
150+
fi
151+
postProcess $outFile "$API_DOCS_ROOT/v2/.config.yml" '@2'
152+
}
153+
154+
function updateCloudV2 {
155+
outFile="$API_DOCS_ROOT/cloud/v2/ref.yml"
143156
if [[ -z "$baseUrl" ]];
144157
then
145-
echo "Using existing $outFile"
158+
echo "No URL was provided. I'll rebuild from the existing spec $outFile"
146159
else
147160
curl $UPDATE_OPTIONS ${baseUrl}/contracts/ref/cloud.yml -o $outFile
148161
fi
149-
postProcess $outFile 'cloud/.config.yml' v2@2
162+
postProcess $outFile "$API_DOCS_ROOT/cloud/.config.yml" v2@2
150163
}
151164

152165
function updateCloudDedicatedManagement {
153-
outFile="cloud-dedicated/management/openapi.yml"
166+
outFile="$API_DOCS_ROOT/cloud-dedicated/management/openapi.yml"
154167
if [[ -z "$baseUrl" ]];
155168
then
156-
echo "Using existing $outFile"
169+
echo "No URL was provided. I'll rebuild from the existing spec $outFile"
157170
else
158171
curl $UPDATE_OPTIONS https://raw.githubusercontent.com/influxdata/granite/ab7ee2aceacfae7f415d15ffbcf8c9d0f6f3e015/openapi.yaml -o $outFile
159172
fi
160-
postProcess $outFile 'cloud-dedicated/.config.yml' management@0
173+
postProcess $outFile "$API_DOCS_ROOT/cloud-dedicated/.config.yml" management@0
161174
}
162175

163176
function updateCloudDedicatedV2 {
164-
outFile="cloud-dedicated/v2/ref.yml"
177+
outFile="$API_DOCS_ROOT/cloud-dedicated/v2/ref.yml"
165178
if [[ -z "$baseUrl" ]];
166179
then
167-
echo "Using existing $outFile"
180+
echo "No URL was provided. I'll rebuild from the existing spec $outFile"
168181
else
169182
curl $UPDATE_OPTIONS ${baseUrl}/contracts/ref/cloud.yml -o $outFile
170183
fi
171-
postProcess $outFile 'cloud-dedicated/.config.yml' v2@2
184+
postProcess $outFile "$API_DOCS_ROOT/cloud-dedicated/.config.yml" v2@2
172185
}
173186

174187
function updateClusteredV2 {
175-
outFile="clustered/v2/ref.yml"
188+
outFile="$API_DOCS_ROOT/clustered/v2/ref.yml"
176189
if [[ -z "$baseUrl" ]];
177190
then
178-
echo "Using existing $outFile"
191+
echo "No URL was provided. I'll rebuild from the existing spec $outFile"
179192
else
180193
curl $UPDATE_OPTIONS ${baseUrl}/contracts/ref/cloud.yml -o $outFile
181194
fi
182-
postProcess $outFile 'clustered/.config.yml' v2@2
195+
postProcess $outFile "$API_DOCS_ROOT/clustered/.config.yml" v2@2
183196
}
184197

185198
function updateCloudServerlessV2 {
186-
outFile="cloud-serverless/v2/ref.yml"
199+
outFile="$API_DOCS_ROOT/cloud-serverless/v2/ref.yml"
187200
if [[ -z "$baseUrl" ]];
188201
then
189-
echo "Using existing $outFile"
202+
echo "No URL was provided. I'll rebuild from the existing spec $outFile"
190203
else
191204
curl $UPDATE_OPTIONS ${baseUrl}/contracts/ref/cloud.yml -o $outFile
192205
fi
193-
postProcess $outFile 'cloud-serverless/.config.yml' v2@2
206+
postProcess $outFile "$API_DOCS_ROOT/cloud-serverless/.config.yml" v2@2
194207
}
195208

196209
function updateOSSV2 {
197-
outFile="v2/ref.yml"
210+
outFile="$API_DOCS_ROOT/v2/ref.yml"
198211
if [[ -z "$baseUrlOSS" ]];
199212
then
200-
echo "Using existing $outFile"
213+
echo "No URL was provided. I'll rebuild from the existing spec $outFile"
201214
else
202215
curl $UPDATE_OPTIONS ${baseUrlOSS}/contracts/ref/oss.yml -o $outFile
203216
fi
204-
postProcess $outFile 'v2/.config.yml' '@2'
217+
postProcess $outFile "$API_DOCS_ROOT/v2/.config.yml" '@2'
205218
}
206219

207-
function updateV1Compat {
208-
outFile="cloud/v1-compatibility/swaggerV1Compat.yml"
220+
function updateV1Compat {
221+
outFile="$API_DOCS_ROOT/cloud/v1-compatibility/swaggerV1Compat.yml"
209222
if [[ -z "$baseUrl" ]];
210223
then
211-
echo "Using existing $outFile"
224+
echo "No URL was provided. I'll rebuild from the existing spec $outFile"
212225
else
213226
curl $UPDATE_OPTIONS ${baseUrl}/contracts/swaggerV1Compat.yml -o $outFile
214227
fi
215-
postProcess $outFile 'cloud/.config.yml' 'v1-compatibility'
228+
postProcess $outFile "$API_DOCS_ROOT/cloud/.config.yml" 'v1-compatibility'
216229

217-
outFile="v2/v1-compatibility/swaggerV1Compat.yml"
230+
outFile="$API_DOCS_ROOT/v2/v1-compatibility/swaggerV1Compat.yml"
218231
cp cloud/v1-compatibility/swaggerV1Compat.yml $outFile
219-
postProcess $outFile 'v2/.config.yml' 'v1-compatibility'
232+
postProcess $outFile "$API_DOCS_ROOT/v2/.config.yml" 'v1-compatibility'
220233

221-
outFile="cloud-dedicated/v1-compatibility/swaggerV1Compat.yml"
222-
postProcess $outFile 'cloud-dedicated/.config.yml' 'v1-compatibility'
234+
outFile="$API_DOCS_ROOT/cloud-dedicated/v1-compatibility/swaggerV1Compat.yml"
235+
postProcess $outFile "$API_DOCS_ROOT/cloud-dedicated/.config.yml" 'v1-compatibility'
223236

224-
outFile="cloud-serverless/v1-compatibility/swaggerV1Compat.yml"
225-
postProcess $outFile 'cloud-serverless/.config.yml' 'v1-compatibility'
237+
outFile="$API_DOCS_ROOT/cloud-serverless/v1-compatibility/swaggerV1Compat.yml"
238+
postProcess $outFile "$API_DOCS_ROOT/cloud-serverless/.config.yml" 'v1-compatibility'
226239

227-
outFile="clustered/v1-compatibility/swaggerV1Compat.yml"
228-
postProcess $outFile 'clustered/.config.yml' 'v1-compatibility'
240+
outFile="$API_DOCS_ROOT/clustered/v1-compatibility/swaggerV1Compat.yml"
241+
postProcess $outFile "$API_DOCS_ROOT/clustered/.config.yml" 'v1-compatibility'
229242
}
230243

231244
UPDATE_OPTIONS="--fail"
@@ -252,6 +265,9 @@ then
252265
elif [ "$product" = "clustered-v2" ];
253266
then
254267
updateClusteredV2
268+
elif [ "$product" = "oss-v2" ];
269+
then
270+
updateOSSV2
255271
elif [ "$product" = "v2" ];
256272
then
257273
updateOSSV2

api-docs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"description": "InfluxDB API documentation",
66
"license": "MIT",
77
"dependencies": {
8-
"js-yaml": "^4.1.0"
8+
"js-yaml": "^4.1.0",
9+
"hugo-data-to-pages": "file:../hugo-data-to-pages/hugo.js"
910
}
1011
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
const { execSync } = require('child_process');
2+
const path = require('path');
3+
const fs = require('fs');
4+
const openapiPathsToHugo = require('./openapi-paths-to-hugo-data/index.js');
5+
6+
// Calculate the relative paths
7+
const DOCS_ROOT = '.';
8+
const API_DOCS_ROOT = 'api-docs';
9+
10+
// Function to execute shell commands
11+
const execCommand = (command) => {
12+
try {
13+
console.log(`Executing: ${command}`);
14+
execSync(command, { stdio: 'inherit' });
15+
} catch (error) {
16+
console.error(`Error executing command: ${command}`);
17+
process.exit(1);
18+
}
19+
};
20+
21+
22+
23+
// Function to generate data from OpenAPI
24+
function generateDataFromOpenAPI(specFile, dataOutPath, articleOutPath) {
25+
if (!fs.existsSync(dataOutPath)) {
26+
fs.mkdirSync(dataOutPath, { recursive: true });
27+
}
28+
29+
openapiPathsToHugo.generateHugoData({
30+
dataOutPath,
31+
articleOutPath,
32+
specFile
33+
});
34+
};
35+
36+
// Example usage of generateDataFromOpenAPI function
37+
// generateDataFromOpenAPI('path/to/openapi-file.yml', 'path/to/paths-output-folder', 'path/to/metadata-output-folder');
38+
39+
function generatePagesFromArticleData(articlesPath, contentPath) {
40+
execCommand(
41+
`HUGO_DATAPAGES_DATA_PATH=${articlesPath} \
42+
HUGO_DATAPAGES_ELEMENT=articles \
43+
HUGO_DATAPAGES_TYPE=api \
44+
HUGO_DATAPAGES_CONTENT_PATH=${contentPath} \
45+
node ${path.join(DOCS_ROOT, '/hugo-data-to-pages/hugo.js')} clean --force`
46+
)
47+
execCommand(
48+
`HUGO_DATAPAGES_DATA_PATH=${articlesPath} \
49+
HUGO_DATAPAGES_ELEMENT=articles \
50+
HUGO_DATAPAGES_TYPE=api \
51+
HUGO_DATAPAGES_CONTENT_PATH=${contentPath} \
52+
node ${path.join(DOCS_ROOT, '/hugo-data-to-pages/hugo.js')} generate`
53+
)
54+
}
55+
56+
const api_reference_paths = {
57+
'cloud-v2': {
58+
spec_file: path.join(API_DOCS_ROOT, '/cloud/v2/ref.yml'),
59+
pages_dir: path.join(DOCS_ROOT, '/content/influxdb/cloud/api/v2'),
60+
},
61+
'oss-v2': {
62+
spec_file: path.join(API_DOCS_ROOT, '/v2/ref.yml'),
63+
pages_dir: path.join(DOCS_ROOT, '/content/influxdb/v2/api/v2'),
64+
}
65+
}
66+
67+
Object.keys(api_reference_paths).forEach((key) => {
68+
const api = api_reference_paths[key];
69+
const staticPath = path.join(DOCS_ROOT, '/static/openapi');
70+
const staticSpecPath = path.join(staticPath, `/influxdb-${key}.yml`);
71+
const staticPathsPath = path.join(staticPath, `/influxdb-${key}/paths`);
72+
const articlesPath = path.join(DOCS_ROOT, `/data/article-data/influxdb/${key}`);
73+
// Execute the getswagger.sh script
74+
execCommand(`${path.join(API_DOCS_ROOT, 'getswagger.sh')} ${key} -B`);
75+
// Copy the generated OpenAPI spec to the static folder
76+
fs.copyFileSync(api.spec_file, staticSpecPath);
77+
generateDataFromOpenAPI(api.spec_file, staticPathsPath, articlesPath);
78+
generatePagesFromArticleData(articlesPath, api.pages_dir);
79+
});
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const path = require('path');
2+
const argparse = require('argparse');
3+
const openapiPathsToHugo = require('./index.js');
4+
5+
const cli = new argparse.ArgumentParser({
6+
prog: 'openapi-docs',
7+
add_help: true
8+
});
9+
10+
cli.add_argument('--hugo', {
11+
help: 'Generate Hugo data from OpenAPI paths',
12+
dest: 'generateHugoData'
13+
});
14+
15+
cli.add_argument('-d', '--data-output', {
16+
help: 'Filepath where generated OpenAPI data output will be written.',
17+
dest: 'dataOutPath'
18+
});
19+
20+
cli.add_argument('-o', '--article-data-output', {
21+
help: 'Filepath where generated article metadata output will be written.',
22+
dest: 'articleOutPath'
23+
});
24+
25+
cli.add_argument('-pre', '--path-prefix', {
26+
help: 'A path to use as the prefix for the path property in each generated article.',
27+
dest: 'pathPrefix'
28+
});
29+
30+
cli.add_argument('file', {
31+
help: 'File to read, utf-8 encoded without BOM',
32+
nargs: '?',
33+
default: '-'
34+
});
35+
36+
37+
////////////////////////////////////////////////////////////////////////////////
38+
39+
40+
var options = cli.parse_args();
41+
42+
43+
/* Usage examples
44+
*
45+
node ./openapi-paths-to-hugo-data/index.js \
46+
./data/influxdb/cloud/openapi.yaml \
47+
-d ./data/influxdb/cloud/path-apis \
48+
-o ./data/article-data/influxdb/cloud
49+
50+
node ./openapi-paths-to-hugo-data/index.js \
51+
./data/influxdb/oss/openapi.yaml \
52+
-d ./data/influxdb/oss/path-apis \
53+
-o ./data/article-data/influxdb/oss
54+
*
55+
*/
56+
57+
////////////////////////////////////////////////////////////////////////////////
58+
59+
60+
if (options.generateHugoData) {
61+
openapiPathsToHugo.generateHugoData(options);
62+
}

0 commit comments

Comments
 (0)