Skip to content

Commit d4c898a

Browse files
authored
Fix openapi (#2124)
* modify workflows * update publish script * update to use json versions and rename outputs * modify test file * testing * add debugger * try without confirm overrite * try adding a convert step * use the full path instead for conversion * fix rdme version * remove conversion step * add branch back in * bring back to main branch only
1 parent e9ae29a commit d4c898a

File tree

5 files changed

+49
-33
lines changed

5 files changed

+49
-33
lines changed

.github/workflows/rdme-openapi.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
name: Publish OpenAPI specs to ReadMe
1+
name: Publish OpenAPI specs to ReadMe Production
22

33
on:
44
push:
55
branches: [ main ]
6+
paths:
7+
- 'openapi/**'
8+
- '.github/actions/**'
9+
- '.github/workflows/rdme-openapi.yml'
610

711
jobs:
812
rdme-openapi:
@@ -17,4 +21,4 @@ jobs:
1721
- run: npm run api:publish
1822
env:
1923
README_API_KEY: ${{ secrets.README_API_KEY }}
20-
README_VERSION: '3.26'
24+
README_VERSION: '3.27'

.github/workflows/rdme-staging.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
name: Generate ReadMe Staging 🦉
22

3-
on:
4-
# run this workflow on all PRs that have reference dirs changed
5-
pull_request:
6-
paths:
7-
- 'openapi/**'
8-
- 'reference/**'
9-
- '.github/actions/**'
10-
- '.github/workflows/rdme-staging.yml'
3+
# This is currently broken, fix this in a future PR
4+
# on:
5+
# # run this workflow on all PRs that have reference dirs changed
6+
# pull_request:
7+
# paths:
8+
# - 'openapi/**'
9+
# - 'reference/**'
10+
# - '.github/actions/**'
11+
# - '.github/workflows/rdme-staging.yml'
1112

1213
jobs:
1314
# ////////////////////////////////////////////////////////////////////////

openapi/openapi.config.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
apis:
22
annotations:
33
root: ./src/annotations.openapi.yaml
4-
output: ./out/annotations.openapi.yaml
4+
output: ./out/annotations-api.json
55
data-pipelines:
66
root: ./src/data-pipelines.openapi.yaml
7-
output: ./out/data-pipelines.openapi.yaml
7+
output: ./out/data-pipelines-api.json
88
export:
99
root: ./src/export.openapi.yaml
10-
output: ./out/export.openapi.yaml
10+
output: ./out/event-export-api.json
1111
gdpr:
1212
root: ./src/gdpr.openapi.yaml
13-
output: ./out/gdpr.openapi.yaml
13+
output: ./out/gdpr-api-2.json
1414
identity:
1515
root: ./src/identity.openapi.yaml
16-
output: ./out/identity.openapi.yaml
16+
output: ./out/identity-api.json
1717
ingestion:
1818
root: ./src/ingestion.openapi.yaml
19-
output: ./out/ingestion.openapi.yaml
19+
output: ./out/ingestion-api.json
2020
lexicon-schemas:
2121
root: ./src/lexicon-schemas.openapi.yaml
22-
output: ./out/lexicon-schemas.openapi.yaml
22+
output: ./out/lexicon-schemas-api.json
2323
query:
2424
root: ./src/query.openapi.yaml
25-
output: ./out/query.openapi.yaml
25+
output: ./out/query-api.json
2626
service-accounts:
2727
root: ./src/service-accounts.openapi.yaml
28-
output: ./out/service-accounts.openapi.yaml
28+
output: ./out/service-accounts-api.json
2929
warehouse-connectors:
3030
root: ./src/warehouse-connectors.openapi.yaml
31-
output: ./out/warehouse-connectors.openapi.yaml
31+
output: ./out/warehouse-connectors-api.json
3232

3333
extends:
3434
- recommended

openapi/publish.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const YAML = require("yaml");
77
const execFile = util.promisify(require("node:child_process").execFile);
88

99
const README_API_KEY = process.env.README_API_KEY;
10+
const README_VERSION = process.env.README_VERSION;
1011
if (!README_API_KEY) {
1112
console.error(`README_API_KEY not set`);
1213
process.exit(1);
1314
}
14-
const README_VERSION = process.env.README_VERSION;
1515
if (!README_VERSION) {
1616
console.error(`README_VERSION not set`);
1717
process.exit(1);
@@ -31,13 +31,10 @@ async function execAndLog(cmd, args) {
3131
async function updateSpecs() {
3232
// fetch IDs of openapi specs via readme API
3333
const res = await fetch(
34-
`https://dash.readme.com/api/v1/api-specification?perPage=10&page=1`,
34+
`https://api.readme.com/v2/branches/${README_VERSION}/apis`,
3535
{
3636
headers: {
37-
Authorization: `Basic ${Buffer.from(README_API_KEY).toString(
38-
"base64"
39-
)}`,
40-
"x-readme-version": README_VERSION,
37+
Authorization: `Bearer ${README_API_KEY}`,
4138
},
4239
}
4340
);
@@ -47,25 +44,39 @@ async function updateSpecs() {
4744
const outBase = path.resolve(__dirname, `out`);
4845
const filenames = fs
4946
.readdirSync(outBase)
50-
.filter((fn) => fn.endsWith(`.openapi.yaml`));
47+
.filter((fn) => fn.endsWith(`.json`));
48+
49+
if (!remoteSpecMetas) {
50+
console.error(`!!! No remote specs found, please double check the API`);
51+
process.exit(1);
52+
}
5153

5254
for (specFile of filenames) {
5355
// get ID of each spec by matching title between filename and metadata
5456
const fullPath = path.join(outBase, specFile);
5557
const yamlStr = fs.readFileSync(fullPath, "utf8");
5658
const spec = YAML.parse(yamlStr);
57-
const specMeta = remoteSpecMetas.find((m) => m.title === spec.info.title);
59+
const specMeta = remoteSpecMetas.data.find((m) => m.filename === specFile);
5860
if (!specMeta) {
5961
console.log(`!!! No spec found for "${spec.info.title}". Please upload it as found in the developer.mixpanel.com runbook.`);
6062
continue;
6163
}
62-
const specId = specMeta.id;
6364

6465
// validate and publish spec
65-
console.log(`Updating ${spec.info.title} (${specFile}, ID ${specId})`);
66-
await execAndLog('npx', ['rdme', 'openapi:validate', fullPath]);
66+
console.log(`Updating ${spec.info.title} (${specFile})`);
67+
await execAndLog('npx', ['[email protected]', 'openapi:validate', fullPath]);
68+
// publish the json version
6769
await execAndLog(
68-
'npx', ['rdme', 'openapi', fullPath, `--id=${specId}`, `--key=${README_API_KEY}`]
70+
'npx', [
71+
72+
'openapi',
73+
'upload',
74+
`${fullPath}`,
75+
`--key=${README_API_KEY}`,
76+
`--slug=${specFile}`,
77+
`--branch=${README_VERSION}`,
78+
`--confirm-overwrite`,
79+
],
6980
);
7081
}
7182
}

openapi/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44

55
npm run api:lint
66
npm run api:build
7-
for file in openapi/out/*.yaml; do
7+
for file in openapi/out/*.json; do
88
echo "✔ Validating $file"
99
npx rdme openapi:validate $file
1010
done

0 commit comments

Comments
 (0)