Skip to content

Commit

Permalink
feat: add beacon api schema
Browse files Browse the repository at this point in the history
  • Loading branch information
wemeetagain committed Sep 20, 2023
1 parent f77b774 commit 2b88f25
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/api/download-beacon-api-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable no-console */
import fs from "node:fs";
import path from "node:path";
import url from "node:url";

import {version} from "./src/schema/version.js";

// eslint-disable-next-line @typescript-eslint/naming-convention
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));

async function downloadBeaconApiSchema(): Promise<void> {
const url = `https://github.com/ethereum/beacon-APIs/releases/download/${version}/beacon-node-oapi.json`;
const filepath = path.join(__dirname, "./src/schema/beacon-node-oapi.json");
console.log(`Downloading oapi file from ${url}`);
let openApiStr = await fetch(url).then((res) => res.text());

// Parse before writting to ensure it's proper JSON
try {
openApiStr = JSON.stringify(JSON.parse(openApiStr));
} catch (e) {
console.log(openApiStr);
throw e;
}

fs.writeFileSync(filepath, openApiStr);
}

await downloadBeaconApiSchema();
1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"check-build": "node -e \"(async function() { await import('./lib/index.js') })()\"",
"check-types": "tsc",
"coverage": "codecov -F lodestar-api",
"download-beacon-api-schema": "node --loader ts-node/esm download-beacon-api-schema.ts",
"lint": "eslint --color --ext .ts src/ test/",
"lint:fix": "yarn run lint --fix",
"pretest": "yarn run check-types",
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/schema/beacon-node-oapi.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions packages/api/src/schema/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import schemaJson from "./beacon-node-oapi.json" assert {type: "json"};
import {version} from "./version.js";

export const schema = schemaJson;
export const version = version;
6 changes: 6 additions & 0 deletions packages/api/src/schema/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* This is the currently-targeted version of the Beacon-API
*
* https://github.com/ethereum/beacon-apis
*/
export const version = "v2.3.0";

0 comments on commit 2b88f25

Please sign in to comment.