You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeScript DSL for authoring OpenAPI 3.1+ specs. Uses [TypeBox](https://github.com/sinclairzx81/typebox) for JSON Schema with full type inference — you write TypeScript, not YAML.
Named schemas automatically hoist to `components.schemas` as `$ref`s. Groups inherit tags and security. Macros let you compose reusable route/group patterns.
30
30
31
-
## Install
31
+
## Quick start
32
+
33
+
### 1. Install
32
34
33
35
```sh
34
36
npm install @spec-spac/spac @sinclair/typebox
35
37
```
36
38
39
+
### 2. Define your API
40
+
41
+
Create `api.ts`:
42
+
43
+
```ts
44
+
import { Api, named } from'@spec-spac/spac'
45
+
import { Type } from'@sinclair/typebox'
46
+
47
+
const User =named('User', Type.Object({
48
+
id: Type.String(),
49
+
name: Type.String(),
50
+
email: Type.String({ format: 'email' }),
51
+
}))
52
+
53
+
const api =newApi('3.1', 'My API', { version: '1.0.0' })
That's it — `openapi.json` is a valid OpenAPI 3.1 document with `User` hoisted to `components.schemas`.
72
+
37
73
## Packages
38
74
39
-
| Package |Path|Description|
75
+
| Package |Install|What it does|
40
76
|---|---|---|
41
-
|[`@spec-spac/spac`](packages/spac)| Core library | Define routes, groups, schemas, and emit OpenAPI 3.1 JSON/YAML with source maps |
42
-
|[`@spec-spac/from-openapi`](packages/from-openapi)| Code generator | Parse an existing OpenAPI spec and emit idiomatic spac TypeScript |
43
-
|[`@spec-spac/from-openapi-biome`](packages/from-openapi/plugins/biome)| Formatter | Biome formatter adapter for from-openapi |
44
-
|[`@spec-spac/from-openapi-prettier`](packages/from-openapi/plugins/prettier)| Formatter | Prettier formatter adapter for from-openapi |
45
-
|[`spac-playground`](packages/playground)| App | Split-pane CodeMirror viewer — SPAC source on the left, OpenAPI YAML on the right |
46
-
|[`spac-vscode`](packages/spac-vscode)| Extension | VS Code extension for live OpenAPI preview |
77
+
|[`@spec-spac/spac`](packages/spac)|`npm i @spec-spac/spac`| Core library — define routes, groups, schemas, emit OpenAPI 3.1 JSON/YAML with source maps |
78
+
|[`@spec-spac/from-openapi`](packages/from-openapi)|`npm i -g @spec-spac/from-openapi`| CLI + library — reverse-generate spac TypeScript from an existing OpenAPI spec |
79
+
|[`@spec-spac/from-openapi-biome`](packages/from-openapi/plugins/biome)|`npm i @spec-spac/from-openapi-biome`| Biome formatter plugin for the code generator |
80
+
|[`@spec-spac/from-openapi-prettier`](packages/from-openapi/plugins/prettier)|`npm i @spec-spac/from-openapi-prettier`| Prettier formatter plugin for the code generator |
47
81
48
-
## Quick start
82
+
## `spac-from-openapi` CLI
83
+
84
+
Already have an OpenAPI spec? Generate spac TypeScript from it:
The DSL builds an AST of `RouteNode` and `GroupNode` objects. `emitOpenApi()` walks the tree, flattens routes with inherited group metadata, resolves TypeBox schemas (hoisting named schemas to `components.schemas` as `$ref`s), and produces a spec-compliant OpenAPI 3.1 document.
150
-
151
219
## Contributing
152
220
153
221
See [INDEX.md](INDEX.md) for the full repo layout, build instructions, and the examples branch workflow.
0 commit comments