Skip to content

Commit caf70d3

Browse files
committed
try adding a convert step
1 parent deb5f9c commit caf70d3

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

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-api.json
4+
output: ./out/annotations-api.yaml
55
data-pipelines:
66
root: ./src/data-pipelines.openapi.yaml
7-
output: ./out/data-pipelines-api.json
7+
output: ./out/data-pipelines-api.yaml
88
export:
99
root: ./src/export.openapi.yaml
10-
output: ./out/event-export-api.json
10+
output: ./out/event-export-api.yaml
1111
gdpr:
1212
root: ./src/gdpr.openapi.yaml
13-
output: ./out/gdpr-api-2.json
13+
output: ./out/gdpr-api-2.yaml
1414
identity:
1515
root: ./src/identity.openapi.yaml
16-
output: ./out/identity-api.json
16+
output: ./out/identity-api.yaml
1717
ingestion:
1818
root: ./src/ingestion.openapi.yaml
19-
output: ./out/ingestion-api.json
19+
output: ./out/ingestion-api.yaml
2020
lexicon-schemas:
2121
root: ./src/lexicon-schemas.openapi.yaml
22-
output: ./out/lexicon-schemas-api.json
22+
output: ./out/lexicon-schemas-api.yaml
2323
query:
2424
root: ./src/query.openapi.yaml
25-
output: ./out/query-api.json
25+
output: ./out/query-api.yaml
2626
service-accounts:
2727
root: ./src/service-accounts.openapi.yaml
28-
output: ./out/service-accounts-api.json
28+
output: ./out/service-accounts-api.yaml
2929
warehouse-connectors:
3030
root: ./src/warehouse-connectors.openapi.yaml
31-
output: ./out/warehouse-connectors-api.json
31+
output: ./out/warehouse-connectors-api.yaml
3232

3333
extends:
3434
- recommended

openapi/publish.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ const env = { ...process.env, DEBUG: "rdme*" };
88
const execFile = util.promisify(require("node:child_process").execFile);
99

1010
const README_API_KEY = process.env.README_API_KEY;
11+
const README_VERSION = process.env.README_VERSION;
1112
if (!README_API_KEY) {
1213
console.error(`README_API_KEY not set`);
1314
process.exit(1);
1415
}
15-
const README_VERSION = process.env.README_VERSION;
1616
if (!README_VERSION) {
1717
console.error(`README_VERSION not set`);
1818
process.exit(1);
@@ -29,6 +29,21 @@ async function execAndLog(cmd, args) {
2929
}
3030
}
3131

32+
function getSlugFromJson(file) {
33+
const splitFile = file.split(`.json`);
34+
return splitFile[0];
35+
}
36+
37+
function getSlugFromYaml(file) {
38+
const splitFile = file.split(`.yaml`);
39+
return splitFile[0];
40+
}
41+
42+
function convertSlugToJson(file) {
43+
const slug = getSlugFromYaml(file);
44+
return `${slug}.json`;
45+
}
46+
3247
async function updateSpecs() {
3348
// fetch IDs of openapi specs via readme API
3449
const res = await fetch(
@@ -45,7 +60,7 @@ async function updateSpecs() {
4560
const outBase = path.resolve(__dirname, `out`);
4661
const filenames = fs
4762
.readdirSync(outBase)
48-
.filter((fn) => fn.endsWith(`.json`));
63+
.filter((fn) => fn.endsWith(`.yaml`));
4964

5065
if (!remoteSpecMetas) {
5166
console.error(`!!! No remote specs found, please double check the API`);
@@ -57,7 +72,7 @@ async function updateSpecs() {
5772
const fullPath = path.join(outBase, specFile);
5873
const yamlStr = fs.readFileSync(fullPath, "utf8");
5974
const spec = YAML.parse(yamlStr);
60-
const specMeta = remoteSpecMetas.data.find((m) => m.filename === specFile);
75+
const specMeta = remoteSpecMetas.data.find((m) => getSlugFromJson(m.filename) === getSlugFromYaml(specFile));
6176
if (!specMeta) {
6277
console.log(`!!! No spec found for "${spec.info.title}". Please upload it as found in the developer.mixpanel.com runbook.`);
6378
continue;
@@ -66,8 +81,21 @@ async function updateSpecs() {
6681
// validate and publish spec
6782
console.log(`Updating ${spec.info.title} (${specFile}`);
6883
await execAndLog('npx', ['rdme', 'openapi:validate', fullPath]);
84+
// this converts the file to json, since it does this step directly in readme anyway
85+
await execAndLog(
86+
'npx', ['rdme', 'openapi', 'convert', fullPath, `--out=openapi/out/${convertSlugToJson(specFile)}`], {env}
87+
);
88+
// publish the json version
6989
await execAndLog(
70-
'npx', ['rdme', 'openapi', 'upload', fullPath, `--key=${README_API_KEY}`, `--slug=${specFile}`], {env}
90+
'npx', [
91+
'rdme',
92+
'openapi',
93+
'upload',
94+
`${convertSlugToJson(fullPath)}`,
95+
`--key=${README_API_KEY}`,
96+
`--slug=${convertSlugToJson(specFile)}`,
97+
`--confirm-overwrite`
98+
], {env}
7199
);
72100
}
73101
}

0 commit comments

Comments
 (0)