Created
February 8, 2026 10:01
-
-
Save shakhzodkudratov/6ba8663a70125600d3636f456284858e to your computer and use it in GitHub Desktop.
fetch openapi schema from encrypted source
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { execSync } from 'node:child_process'; | |
| import fs from 'node:fs'; | |
| import path from 'node:path'; | |
| const url = process.env.OPENAPI_URL?.toString() ?? ''; | |
| const username = process.env.OPENAPI_USERNAME?.toString() ?? ''; | |
| const password = process.env.OPENAPI_PASSWORD?.toString() ?? ''; | |
| const projectRoot = execSync('git rev-parse --show-toplevel', { | |
| encoding: 'utf-8', | |
| }).trim(); | |
| const main = async () => { | |
| const raw = await fetch(url, { | |
| headers: { | |
| Authorization: | |
| 'Basic ' + Buffer.from(username + ':' + password).toString('base64'), | |
| }, | |
| }); | |
| const blob = await raw.blob(); | |
| const buffer = Buffer.from(await blob.arrayBuffer()); | |
| fs.writeFileSync( | |
| path.join(projectRoot, './scheme.json'), | |
| buffer, | |
| 'utf-8' | |
| ); | |
| }; | |
| main().catch(console.error); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "scripts": { | |
| "fetch-scheme": "dotenv -- tsx ./fetch.ts", | |
| "codegen": "openapi-typescript ./scheme.json -o ./api.d.ts", | |
| "generate": "npm run fetch-scheme && npm run codegen" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment