This repository has moved to https://github.com/responsibleapi/responsible/tree/master/packages/ts.
TypeScript DSL that compiles to OpenAPI 3.1 documents.
- OpenAPI YAML is hard to refactor.
- Microservices should not share implementation models, but they do share
contract vocabulary:
Money,CurrencyCode, error shapes, pagination, and similar boundary types. $defsis valid OpenAPI 3.1, but it is not a reliable public model namespace for generated SDKs. Shared contract types should compile into each service document's localcomponents.schemaswith stable#/components/schemas/...refs.
npm install @responsibleapi/tsRequires Node 22.18.0+ for plain node api.ts workflows.
import { GET, object, responsibleAPI, resp, string } from "@responsibleapi/ts"
const api = responsibleAPI({
partialDoc: {
openapi: "3.1.0",
info: {
title: "Example API",
version: "1.0.0",
},
},
routes: {
"/hello": GET({
res: {
200: resp({
description: "OK",
body: object({
message: string(),
}),
}),
},
}),
},
})
console.log(JSON.stringify(api, null, 2))import { YAML } from "bun"
import { GET, object, responsibleAPI, resp, string } from "@responsibleapi/ts"
const api = responsibleAPI({
partialDoc: {
openapi: "3.1.0",
info: {
title: "Example API",
version: "1.0.0",
},
},
routes: {
"/hello": GET({
res: {
200: resp({
description: "OK",
body: object({
message: string(),
}),
}),
},
}),
},
})
console.log(YAML.stringify(api))Bun YAML docs: https://bun.com/docs/runtime/yaml
Use bun