@me1a/tool-open-api-builder
v0.3.3
Published
Generic OpenAPI REST SDK builder (TypeScript + Rust, openapi-typescript + progenitor)
Maintainers
Readme
@me1a/tool-open-api-builder
OpenAPI REST verify, sync-spec, protobuf-backed SDK build, and check (TypeScript + Rust).
Pipeline: cached OpenAPI → normalize → emit .proto + lock files → buf lint / buf generate → TypeScript (protobuf-es schema types + openapi-fetch paths/client) and Rust (prost + progenitor HTTP client).
HTTP wire format stays JSON. Proto fields use json_name when OpenAPI keys differ from snake_case. parseJsonBody / serializeJsonBody rewrite string enums between spec wire values (active) and protobuf JSON names. Bodies use protobuf message types; paths stay typed from OpenAPI (paths.ts). Build stages under .build-staging/ and promotes atomically — never touches extensions/.
Consumer packages should gitignore .build-staging/, .cache/, and local buf cache under .cache/xdg-cache/.
Commands
open-api-builder verify --root path/to/packages/open-api
open-api-builder verify --root path/to/packages/open-api --online
open-api-builder sync-spec --root path/to/packages/open-api
open-api-builder build --root path/to/packages/open-api
open-api-builder build --root path/to/packages/open-api --only admin-core
open-api-builder build --root path/to/packages/open-api --fetch # sync-spec then build
open-api-builder check --root path/to/packages/open-api
open-api-builder check --root path/to/packages/open-api --git-dirty
open-api-builder init --root path/to/packages/open-apiRequires Node 26+, cargo, and network for buf generate (remote plugins) unless OPEN_API_BUF_LOCAL_PLUGINS=1.
Consumer config
// open-api.config.ts
import { defineConfig } from "@me1a/tool-open-api-builder";
export default defineConfig({
packageRoot: import.meta.dirname,
services: [
{
id: "auth",
name: "Auth API",
specUrl: "https://example.test/openapi/schemas/auth.schema.json",
auth: { preset: "none" },
},
],
});Peer dependencies in consumer packages: @bufbuild/protobuf, openapi-fetch.
Layout (per service)
Unified with AsyncAPI builder: docs/specs/sdk-pipeline.md (Layout & CLI).
| Path | Role |
|------|------|
| specs/<id>.openapi.json | Cached spec (from sync-spec) |
| specs/<id>.proto.lock.json | Stable proto field numbers |
| proto/<pkg>/ | Generated .proto |
| src/sdk/<id>/generated/ | *_pb.ts, paths.ts, client.ts (always regenerated) |
| src/sdk/<id>/extensions/ | Optional overrides (init scaffolds) |
| rust/sdk/<crate>/ | Rust crate (prost + progenitor) |
verify / build / check print resolved paths. Override any default path in defineConfig if needed.
Toolchain matrix
| Tool | Pin (src/toolchain.ts) |
|------|--------------------------|
| buf | 1.47.2 |
| protoc-gen-es | 2.13.0 |
| prost plugin (buf) | v0.5.0 |
| openapi-typescript | ^7.6.1 |
| progenitor / openapiv3 | 0.8 / 2.0 |
Set OPEN_API_BUF_LOCAL_PLUGINS=1 to use protoc-gen-es / protoc-gen-prost from node_modules/.bin.
OPEN_API_BUF_BREAKING_AGAINST overrides the buf breaking baseline (e.g. .git#subdir=proto). In CI (CI=true) breaking failures fail the build; locally they warn.
Rust: prost schema types live in pb; progenitor HTTP types stay in the generated client module — convert at the boundary when you need both.
Library API
import {
buildOpenApi,
verifyOpenApi,
checkOpenApi,
syncOpenApiSpecs,
} from "@me1a/tool-open-api-builder";Develop
git config core.hooksPath .githooks
yarn install
yarn build
yarn testIntegration tests call buf and cargo. By default they skip buf generate (reuse committed *_pb.ts / prost stubs); set OPEN_API_INTEGRATION_BUF=1 to exercise the full remote plugin path. Set OPEN_API_SKIP_CARGO_CHECK=1 to skip cargo check without Rust.
Release
yarn release:minor # layout change: 0.1 → 0.2+