@workos/oagen 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/.claude-plugin/plugin.json +12 -0
  2. package/LICENSE.txt +21 -0
  3. package/README.md +197 -0
  4. package/dist/chunk-CIX5NOBF.js +263 -0
  5. package/dist/chunk-IJ5E5AE7.js +1040 -0
  6. package/dist/chunk-P5XUDUGY.js +1748 -0
  7. package/dist/cli/index.js +5603 -0
  8. package/dist/compat/index.d.ts +195 -0
  9. package/dist/compat/index.js +4453 -0
  10. package/dist/index.d.ts +300 -0
  11. package/dist/index.js +1733 -0
  12. package/dist/scripts/smoke/baseline.js +1751 -0
  13. package/dist/scripts/smoke/sdk-test.js +93 -0
  14. package/dist/smoke.js +1963 -0
  15. package/dist/types-B5t9O9Wm.d.ts +367 -0
  16. package/dist/verify/index.d.ts +76 -0
  17. package/dist/verify/index.js +336 -0
  18. package/docs/advanced/index.md +11 -0
  19. package/docs/advanced/oagen-ignore.md +144 -0
  20. package/docs/agents/architecture.md +53 -0
  21. package/docs/agents/emitters.md +69 -0
  22. package/docs/agents/testing.md +60 -0
  23. package/docs/architecture/dependency-layers.md +75 -0
  24. package/docs/architecture/emitter-contract.md +160 -0
  25. package/docs/architecture/extractor-contract.md +227 -0
  26. package/docs/architecture/ir-types.md +275 -0
  27. package/docs/architecture/non-additive-changes.md +76 -0
  28. package/docs/architecture/pipeline.md +110 -0
  29. package/docs/architecture/workflows.md +215 -0
  30. package/docs/cli.md +156 -0
  31. package/docs/contributor/index.md +10 -0
  32. package/docs/contributor/public-api.md +59 -0
  33. package/docs/contributor/versioning.md +48 -0
  34. package/docs/core/index.md +12 -0
  35. package/docs/core/minimal-emitter.md +134 -0
  36. package/docs/core/quickstart.md +142 -0
  37. package/docs/diagrams/generate-sdk-workflow.md +50 -0
  38. package/docs/index.md +40 -0
  39. package/examples/reference-emitter/README.md +41 -0
  40. package/examples/reference-emitter/oagen.config.ts +7 -0
  41. package/examples/reference-emitter/spec/github-subset.yml +400 -0
  42. package/examples/reference-emitter/src/emitter.ts +52 -0
  43. package/examples/reference-emitter/src/generators/client.ts +37 -0
  44. package/examples/reference-emitter/src/generators/config.ts +19 -0
  45. package/examples/reference-emitter/src/generators/enums.ts +16 -0
  46. package/examples/reference-emitter/src/generators/errors.ts +39 -0
  47. package/examples/reference-emitter/src/generators/models.ts +29 -0
  48. package/examples/reference-emitter/src/generators/resources.ts +60 -0
  49. package/examples/reference-emitter/src/generators/tests.ts +7 -0
  50. package/examples/reference-emitter/src/index.ts +1 -0
  51. package/examples/reference-emitter/src/naming.ts +21 -0
  52. package/examples/reference-emitter/src/type-mapper.ts +39 -0
  53. package/examples/reference-emitter/tsconfig.json +19 -0
  54. package/package.json +102 -0
  55. package/skills/generate-emitter/SKILL.md +393 -0
  56. package/skills/generate-emitter/references/common-pitfalls.md +23 -0
  57. package/skills/generate-emitter/references/generator-guide.md +201 -0
  58. package/skills/generate-emitter/references/project-scaffold.md +138 -0
  59. package/skills/generate-extractor/SKILL.md +200 -0
  60. package/skills/generate-sdk/SKILL.md +155 -0
  61. package/skills/generate-smoke-test/SKILL.md +185 -0
  62. package/skills/integrate/SKILL.md +108 -0
  63. package/skills/verify-compat/SKILL.md +151 -0
  64. package/skills/verify-smoke-test/SKILL.md +176 -0
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "oagen",
3
+ "version": "0.0.1",
4
+ "description": "Skills for building language emitters, extractors, and smoke tests for the oagen OpenAPI SDK generator",
5
+ "author": {
6
+ "name": "WorkOS",
7
+ "url": "https://github.com/workos"
8
+ },
9
+ "repository": "https://github.com/workos/oagen",
10
+ "license": "MIT",
11
+ "keywords": ["openapi", "sdk", "codegen", "emitter"]
12
+ }
package/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 WorkOS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,197 @@
1
+ # oagen
2
+
3
+ oagen is a framework for building custom SDK generators from OpenAPI 3.x specifications.
4
+
5
+ Its core job is narrow:
6
+
7
+ - parse an OpenAPI spec into a typed intermediate representation (IR)
8
+ - let language emitters turn that IR into files
9
+ - regenerate the SDK when the spec changes
10
+
11
+ More advanced workflows, such as preserving the public API of an existing SDK during a migration to generation, is also supported.
12
+
13
+ ## Who This Is For
14
+
15
+ oagen is a fit if you:
16
+
17
+ - need more control than off-the-shelf generators give you
18
+ - want to build or maintain a custom emitter for one or more languages
19
+ - care about generated output being idiomatic for a specific SDK style
20
+
21
+ oagen is probably not a fit if you:
22
+
23
+ - just want a turnkey SDK generator with batteries included
24
+ - do not want to maintain emitter code
25
+ - do not need a reusable IR or generation framework
26
+
27
+ ## Core Concept
28
+
29
+ oagen has a small core:
30
+
31
+ - **Parser**: OpenAPI 3.x -> `ApiSpec` IR
32
+ - **Emitter runtime**: `ApiSpec` -> `GeneratedFile[]`
33
+ - **Diffing**: compare spec versions and map changes to generated output
34
+
35
+ Advanced features such as API-surface extraction, compatibility overlays, smoke verification, and live-SDK integration are available, but they are optional. You can ignore them until you need them.
36
+
37
+ ## Quickstart
38
+
39
+ Install the package:
40
+
41
+ ```bash
42
+ npm install @workos/oagen
43
+ ```
44
+
45
+ Inspect a spec:
46
+
47
+ ```bash
48
+ oagen parse --spec openapi.yml
49
+ ```
50
+
51
+ Create an emitter project:
52
+
53
+ ```bash
54
+ oagen init --lang ruby --project ./my-emitter
55
+ cd ./my-emitter
56
+ ```
57
+
58
+ Generate files with your emitter:
59
+
60
+ ```bash
61
+ npm run sdk:generate -- --spec ../openapi.yml --namespace MyService
62
+ ```
63
+
64
+ For the shortest end-to-end setup, see [Minimal Quickstart](docs/core/quickstart.md).
65
+
66
+ ## The Core API
67
+
68
+ The default `@workos/oagen` entrypoint is intentionally focused on the framework core:
69
+
70
+ ```ts
71
+ import {
72
+ diffSpecs,
73
+ generate,
74
+ generateFiles,
75
+ generateIncremental,
76
+ getEmitter,
77
+ mapChangesToFiles,
78
+ parseSpec,
79
+ planOperation,
80
+ registerEmitter,
81
+ toCamelCase,
82
+ toPascalCase,
83
+ toSnakeCase,
84
+ } from "@workos/oagen";
85
+ import type {
86
+ ApiSpec,
87
+ Emitter,
88
+ EmitterContext,
89
+ GeneratedFile,
90
+ Model,
91
+ Enum,
92
+ Service,
93
+ OperationPlan,
94
+ } from "@workos/oagen";
95
+ ```
96
+
97
+ Advanced compat and verification APIs are available through explicit subpaths:
98
+
99
+ ```ts
100
+ import {
101
+ buildOverlayLookup,
102
+ patchOverlay,
103
+ registerExtractor,
104
+ } from "@workos/oagen/compat";
105
+ import { runCompatCheck, runOverlayRetryLoop } from "@workos/oagen/verify";
106
+ ```
107
+
108
+ ## Building an Emitter
109
+
110
+ Emitters are pure functions over the IR. They receive typed IR nodes and return `GeneratedFile[]`.
111
+
112
+ ```ts
113
+ import type { Emitter } from "@workos/oagen";
114
+
115
+ const myEmitter: Emitter = {
116
+ language: "go",
117
+ generateModels: (models, ctx) => [
118
+ /* ... */
119
+ ],
120
+ generateEnums: (enums, ctx) => [
121
+ /* ... */
122
+ ],
123
+ generateResources: (services, ctx) => [
124
+ /* ... */
125
+ ],
126
+ generateClient: (spec, ctx) => [
127
+ /* ... */
128
+ ],
129
+ generateErrors: () => [],
130
+ generateConfig: () => [],
131
+ generateTests: () => [],
132
+ fileHeader: () => "// Auto-generated by oagen. Do not edit.",
133
+ };
134
+ ```
135
+
136
+ Start with:
137
+
138
+ - [Reference Emitter](examples/reference-emitter/) — a working TypeScript emitter with tests against a GitHub-flavored fixture spec
139
+ - [Minimal Quickstart](docs/core/quickstart.md)
140
+ - [Emitter Contract](docs/architecture/emitter-contract.md)
141
+ - [IR Type System Reference](docs/architecture/ir-types.md)
142
+
143
+ ## Commands
144
+
145
+ | Command | Purpose |
146
+ | ---------------- | --------------------------------------------------- |
147
+ | `oagen parse` | Parse a spec and print IR JSON |
148
+ | `oagen init` | Scaffold an emitter project |
149
+ | `oagen generate` | Run a registered emitter |
150
+ | `oagen diff` | Review spec changes or incrementally regenerate |
151
+ | `oagen extract` | Advanced: extract an SDK API surface for compat use |
152
+ | `oagen verify` | Advanced: smoke-test output and run compat checks |
153
+
154
+ See [CLI Reference](docs/cli.md).
155
+
156
+ ## Documentation
157
+
158
+ - [Docs Overview](docs/index.md)
159
+ - [Core Docs](docs/core/index.md)
160
+ - [Advanced Docs](docs/advanced/index.md)
161
+ - [Contributor Docs](docs/contributor/index.md)
162
+ - [Public API Policy](docs/contributor/public-api.md)
163
+ - [Versioning and Migration](docs/contributor/versioning.md)
164
+
165
+ ## Advanced Workflows
166
+
167
+ oagen also includes tooling for a more opinionated migration workflow:
168
+
169
+ - extract the public API of an existing SDK
170
+ - generate a replacement while preserving names and exports
171
+ - verify the generated SDK against smoke tests and compatibility checks
172
+ - integrate generated files into a live SDK tree
173
+
174
+ Those workflows are documented separately because they are not required to use the core framework:
175
+
176
+ - [Workflows](docs/architecture/workflows.md)
177
+ - [Extractor Contract](docs/architecture/extractor-contract.md)
178
+ - [CLI Reference](docs/cli.md)
179
+
180
+ ## AI / Plugin Tooling
181
+
182
+ This repo ships with Claude Code plugin assets and skills for scaffold-and-verify workflows. The framework is usable without any agent tooling.
183
+
184
+ If you need them, start here:
185
+
186
+ - [Agent Docs](docs/agents/architecture.md)
187
+ - [Emitter Agent Docs](docs/agents/emitters.md)
188
+ - [Testing Agent Docs](docs/agents/testing.md)
189
+
190
+ ## Development
191
+
192
+ ```bash
193
+ npm install
194
+ npm run build
195
+ npm test
196
+ npm run typecheck
197
+ ```
@@ -0,0 +1,263 @@
1
+ // src/ir/types.ts
2
+ function assertNever(x) {
3
+ const kind = x.kind;
4
+ const err = new Error(
5
+ `Unexpected TypeRef kind: ${kind}
6
+ Hint: If you added a new TypeRef variant, handle it in every switch/case that calls assertNever.`
7
+ );
8
+ err.name = "InternalError";
9
+ throw err;
10
+ }
11
+ function walkTypeRef(ref, visitor) {
12
+ switch (ref.kind) {
13
+ case "model":
14
+ visitor.model?.(ref);
15
+ break;
16
+ case "enum":
17
+ visitor.enum?.(ref);
18
+ break;
19
+ case "array":
20
+ walkTypeRef(ref.items, visitor);
21
+ break;
22
+ case "nullable":
23
+ walkTypeRef(ref.inner, visitor);
24
+ break;
25
+ case "union":
26
+ for (const v of ref.variants) walkTypeRef(v, visitor);
27
+ break;
28
+ case "map":
29
+ if (ref.keyType) walkTypeRef(ref.keyType, visitor);
30
+ walkTypeRef(ref.valueType, visitor);
31
+ break;
32
+ case "literal":
33
+ visitor.literal?.(ref);
34
+ break;
35
+ case "primitive":
36
+ visitor.primitive?.(ref);
37
+ break;
38
+ default:
39
+ assertNever(ref);
40
+ }
41
+ }
42
+ function mapTypeRef(ref, mapper) {
43
+ switch (ref.kind) {
44
+ case "primitive":
45
+ return mapper.primitive(ref);
46
+ case "array":
47
+ return mapper.array(ref, mapTypeRef(ref.items, mapper));
48
+ case "model":
49
+ return mapper.model(ref);
50
+ case "enum":
51
+ return mapper.enum(ref);
52
+ case "union":
53
+ return mapper.union(
54
+ ref,
55
+ ref.variants.map((v) => mapTypeRef(v, mapper))
56
+ );
57
+ case "nullable":
58
+ return mapper.nullable(ref, mapTypeRef(ref.inner, mapper));
59
+ case "literal":
60
+ return mapper.literal(ref);
61
+ case "map":
62
+ return mapper.map(
63
+ ref,
64
+ mapTypeRef(ref.valueType, mapper),
65
+ ref.keyType ? mapTypeRef(ref.keyType, mapper) : void 0
66
+ );
67
+ default:
68
+ return assertNever(ref);
69
+ }
70
+ }
71
+
72
+ // src/errors.ts
73
+ var OagenError = class extends Error {
74
+ hint;
75
+ constructor(message, hint) {
76
+ const fullMessage = hint ? `${message}
77
+ Hint: ${hint}` : message;
78
+ super(fullMessage);
79
+ this.name = "OagenError";
80
+ this.hint = hint;
81
+ }
82
+ };
83
+ var CommandError = class extends OagenError {
84
+ exitCode;
85
+ constructor(message, hint, exitCode) {
86
+ super(message, hint);
87
+ this.name = "CommandError";
88
+ this.exitCode = exitCode;
89
+ }
90
+ };
91
+ var SpecParseError = class extends OagenError {
92
+ constructor(message, hint) {
93
+ super(message, hint);
94
+ this.name = "SpecParseError";
95
+ }
96
+ };
97
+ var ConfigError = class extends OagenError {
98
+ constructor(message, hint) {
99
+ super(message, hint);
100
+ this.name = "ConfigError";
101
+ }
102
+ };
103
+ var ConfigLoadError = class extends ConfigError {
104
+ constructor(message, hint) {
105
+ super(message, hint);
106
+ this.name = "ConfigLoadError";
107
+ }
108
+ };
109
+ var ConfigVersionMismatchError = class extends ConfigError {
110
+ constructor(message, hint) {
111
+ super(message, hint);
112
+ this.name = "ConfigVersionMismatchError";
113
+ }
114
+ };
115
+ var ExtractorError = class extends OagenError {
116
+ constructor(message, hint) {
117
+ super(message, hint);
118
+ this.name = "ExtractorError";
119
+ }
120
+ };
121
+ var RegistryError = class extends OagenError {
122
+ constructor(message, hint) {
123
+ super(message, hint);
124
+ this.name = "RegistryError";
125
+ }
126
+ };
127
+ var InternalError = class extends OagenError {
128
+ constructor(message, hint) {
129
+ super(message, hint);
130
+ this.name = "InternalError";
131
+ }
132
+ };
133
+
134
+ // src/utils/naming.ts
135
+ function splitWords(s) {
136
+ if (!s) return [];
137
+ return s.replace(/[^a-zA-Z0-9_\-\s.]/g, "_").replace(/([a-z])([A-Z])/g, "$1\0$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1\0$2").replace(/([a-zA-Z])(\d)/g, "$1\0$2").replace(/(\d)([a-zA-Z])/g, "$1\0$2").split(/[\0_\-\s.]+/).filter((w) => w.length > 0);
138
+ }
139
+ var ACRONYM_SET = /* @__PURE__ */ new Set(["SSO", "FGA", "SAML", "SCIM", "JWT", "HMAC"]);
140
+ function toPascalCase(s, acronyms) {
141
+ const merged = acronyms ? /* @__PURE__ */ new Set([...ACRONYM_SET, ...acronyms]) : ACRONYM_SET;
142
+ return splitWords(s).map((w) => {
143
+ const upper = w.toUpperCase();
144
+ if (merged.has(upper)) return upper;
145
+ if (upper === "OAUTH") return "OAuth";
146
+ return w.charAt(0).toUpperCase() + w.slice(1).toLowerCase();
147
+ }).join("");
148
+ }
149
+ function toCamelCase(s, acronyms) {
150
+ const merged = acronyms ? /* @__PURE__ */ new Set([...ACRONYM_SET, ...acronyms]) : ACRONYM_SET;
151
+ const words = splitWords(s);
152
+ if (words.length === 0) return "";
153
+ return words.map((w, i) => {
154
+ if (i === 0) return w.toLowerCase();
155
+ const upper = w.toUpperCase();
156
+ if (merged.has(upper)) return upper;
157
+ if (upper === "OAUTH") return "OAuth";
158
+ return w.charAt(0).toUpperCase() + w.slice(1).toLowerCase();
159
+ }).join("");
160
+ }
161
+ function toSnakeCase(s) {
162
+ return splitWords(s).map((w) => w.toLowerCase()).join("_");
163
+ }
164
+ function toKebabCase(s) {
165
+ return splitWords(s).map((w) => w.toLowerCase()).join("-");
166
+ }
167
+ function toUpperSnakeCase(s) {
168
+ return splitWords(s).map((w) => w.toUpperCase()).join("_");
169
+ }
170
+ var BACKEND_SUFFIXES = ["Dto", "DTO", "Controller"];
171
+ function stripBackendSuffixes(name) {
172
+ for (const suffix of BACKEND_SUFFIXES) {
173
+ if (name.endsWith(suffix) && name.length > suffix.length) {
174
+ return name.slice(0, -suffix.length);
175
+ }
176
+ }
177
+ return name;
178
+ }
179
+ function stripBackendPrefixes(name) {
180
+ return name.replace(/Userland/g, "").replace(/Controller/g, "");
181
+ }
182
+ function stripListItemMarkers(name) {
183
+ return name.replace(/ListItem/g, "").replace(/ByExternalId/g, "").replace(/ByResourceId/g, "").replace(/ForResource/g, "");
184
+ }
185
+ var SINGULAR_SAFE_LIST = /* @__PURE__ */ new Set([
186
+ "Status",
187
+ "Address",
188
+ "Access",
189
+ "Process",
190
+ "Progress",
191
+ "Success",
192
+ "Radius",
193
+ "Canvas",
194
+ "Alias",
195
+ "Basis",
196
+ "Bus"
197
+ ]);
198
+ function singularize(word) {
199
+ if (SINGULAR_SAFE_LIST.has(word)) return word;
200
+ if (word.endsWith("ies") && word.length > 4) {
201
+ return word.slice(0, -3) + "y";
202
+ }
203
+ if (word.endsWith("ses") && word.length > 4) {
204
+ return word.slice(0, -2);
205
+ }
206
+ if (word.endsWith("s") && !word.endsWith("ss") && word.length > 4) {
207
+ return word.slice(0, -1);
208
+ }
209
+ return word;
210
+ }
211
+ function normalizeJsExtension(text) {
212
+ return text.replace(/\.js(['"])/g, "$1");
213
+ }
214
+ function cleanSchemaName(name) {
215
+ let result = stripBackendPrefixes(stripBackendSuffixes(name));
216
+ result = stripListItemMarkers(result);
217
+ const match = result.match(/^([A-Z][a-z]*)/);
218
+ if (match) {
219
+ const leadWord = match[1];
220
+ const singular = singularize(leadWord);
221
+ if (singular !== leadWord) {
222
+ result = singular + result.slice(leadWord.length);
223
+ }
224
+ }
225
+ return result;
226
+ }
227
+
228
+ // src/utils/tree-sitter.ts
229
+ var TS_SAFE_CHUNK = 32767;
230
+ function safeParse(parser, source) {
231
+ if (source.length < TS_SAFE_CHUNK) {
232
+ return parser.parse(source);
233
+ }
234
+ return parser.parse((offset) => source.slice(offset, offset + TS_SAFE_CHUNK));
235
+ }
236
+
237
+ export {
238
+ assertNever,
239
+ walkTypeRef,
240
+ mapTypeRef,
241
+ OagenError,
242
+ CommandError,
243
+ SpecParseError,
244
+ ConfigError,
245
+ ConfigLoadError,
246
+ ConfigVersionMismatchError,
247
+ ExtractorError,
248
+ RegistryError,
249
+ InternalError,
250
+ splitWords,
251
+ ACRONYM_SET,
252
+ toPascalCase,
253
+ toCamelCase,
254
+ toSnakeCase,
255
+ toKebabCase,
256
+ toUpperSnakeCase,
257
+ stripBackendPrefixes,
258
+ stripListItemMarkers,
259
+ singularize,
260
+ normalizeJsExtension,
261
+ cleanSchemaName,
262
+ safeParse
263
+ };