generate-openapi.ts 561 B

12345678910111213141516
  1. import { OpenApi } from "effect/unstable/httpapi"
  2. import { fileURLToPath } from "url"
  3. import { ClientApi } from "../src/client.js"
  4. const document = JSON.stringify(OpenApi.fromApi(ClientApi), null, 2) + "\n"
  5. const target = fileURLToPath(new URL("../openapi.json", import.meta.url))
  6. if (process.argv.includes("--check")) {
  7. if ((await Bun.file(target).text()) !== document) {
  8. console.error("Generated OpenAPI document is stale. Run `bun run generate` from packages/protocol.")
  9. process.exit(1)
  10. }
  11. process.exit(0)
  12. }
  13. await Bun.write(target, document)