@workos/oagen-emitters 0.2.1 → 0.3.0

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 (103) hide show
  1. package/.husky/pre-commit +1 -0
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +8 -0
  4. package/README.md +129 -0
  5. package/dist/index.d.mts +10 -1
  6. package/dist/index.d.mts.map +1 -1
  7. package/dist/index.mjs +11893 -3226
  8. package/dist/index.mjs.map +1 -1
  9. package/docs/sdk-architecture/go.md +338 -0
  10. package/docs/sdk-architecture/php.md +315 -0
  11. package/docs/sdk-architecture/python.md +511 -0
  12. package/oagen.config.ts +298 -2
  13. package/package.json +9 -5
  14. package/scripts/generate-php.js +13 -0
  15. package/scripts/git-push-with-published-oagen.sh +21 -0
  16. package/smoke/sdk-go.ts +116 -42
  17. package/smoke/sdk-php.ts +28 -26
  18. package/smoke/sdk-python.ts +5 -2
  19. package/src/go/client.ts +141 -0
  20. package/src/go/enums.ts +196 -0
  21. package/src/go/fixtures.ts +212 -0
  22. package/src/go/index.ts +81 -0
  23. package/src/go/manifest.ts +36 -0
  24. package/src/go/models.ts +254 -0
  25. package/src/go/naming.ts +191 -0
  26. package/src/go/resources.ts +827 -0
  27. package/src/go/tests.ts +751 -0
  28. package/src/go/type-map.ts +82 -0
  29. package/src/go/wrappers.ts +261 -0
  30. package/src/index.ts +3 -0
  31. package/src/node/client.ts +78 -115
  32. package/src/node/enums.ts +9 -0
  33. package/src/node/errors.ts +37 -232
  34. package/src/node/field-plan.ts +726 -0
  35. package/src/node/fixtures.ts +9 -1
  36. package/src/node/index.ts +2 -9
  37. package/src/node/models.ts +178 -21
  38. package/src/node/naming.ts +49 -111
  39. package/src/node/resources.ts +374 -364
  40. package/src/node/sdk-errors.ts +41 -0
  41. package/src/node/tests.ts +32 -12
  42. package/src/node/type-map.ts +4 -2
  43. package/src/node/utils.ts +13 -71
  44. package/src/node/wrappers.ts +151 -0
  45. package/src/php/client.ts +171 -0
  46. package/src/php/enums.ts +67 -0
  47. package/src/php/errors.ts +9 -0
  48. package/src/php/fixtures.ts +181 -0
  49. package/src/php/index.ts +96 -0
  50. package/src/php/manifest.ts +36 -0
  51. package/src/php/models.ts +310 -0
  52. package/src/php/naming.ts +298 -0
  53. package/src/php/resources.ts +561 -0
  54. package/src/php/tests.ts +533 -0
  55. package/src/php/type-map.ts +90 -0
  56. package/src/php/utils.ts +18 -0
  57. package/src/php/wrappers.ts +151 -0
  58. package/src/python/client.ts +337 -0
  59. package/src/python/enums.ts +313 -0
  60. package/src/python/fixtures.ts +196 -0
  61. package/src/python/index.ts +95 -0
  62. package/src/python/manifest.ts +38 -0
  63. package/src/python/models.ts +688 -0
  64. package/src/python/naming.ts +209 -0
  65. package/src/python/resources.ts +1322 -0
  66. package/src/python/tests.ts +1335 -0
  67. package/src/python/type-map.ts +93 -0
  68. package/src/python/wrappers.ts +191 -0
  69. package/src/shared/model-utils.ts +255 -0
  70. package/src/shared/naming-utils.ts +107 -0
  71. package/src/shared/non-spec-services.ts +54 -0
  72. package/src/shared/resolved-ops.ts +109 -0
  73. package/src/shared/wrapper-utils.ts +59 -0
  74. package/test/go/client.test.ts +92 -0
  75. package/test/go/enums.test.ts +132 -0
  76. package/test/go/errors.test.ts +9 -0
  77. package/test/go/models.test.ts +265 -0
  78. package/test/go/resources.test.ts +408 -0
  79. package/test/go/tests.test.ts +143 -0
  80. package/test/node/client.test.ts +18 -12
  81. package/test/node/enums.test.ts +2 -0
  82. package/test/node/errors.test.ts +2 -41
  83. package/test/node/models.test.ts +2 -0
  84. package/test/node/naming.test.ts +23 -0
  85. package/test/node/resources.test.ts +99 -69
  86. package/test/node/serializers.test.ts +3 -1
  87. package/test/node/type-map.test.ts +11 -0
  88. package/test/php/client.test.ts +94 -0
  89. package/test/php/enums.test.ts +173 -0
  90. package/test/php/errors.test.ts +9 -0
  91. package/test/php/models.test.ts +497 -0
  92. package/test/php/resources.test.ts +644 -0
  93. package/test/php/tests.test.ts +118 -0
  94. package/test/python/client.test.ts +200 -0
  95. package/test/python/enums.test.ts +228 -0
  96. package/test/python/errors.test.ts +16 -0
  97. package/test/python/manifest.test.ts +74 -0
  98. package/test/python/models.test.ts +716 -0
  99. package/test/python/resources.test.ts +617 -0
  100. package/test/python/tests.test.ts +202 -0
  101. package/src/node/common.ts +0 -273
  102. package/src/node/config.ts +0 -71
  103. package/src/node/serializers.ts +0 -746
package/.husky/pre-commit CHANGED
@@ -1,2 +1,3 @@
1
1
  npm run lint
2
2
  npm run format
3
+ npm run format:md
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "0.2.1"
2
+ ".": "0.3.0"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.0](https://github.com/workos/oagen-emitters/compare/v0.2.1...v0.3.0) (2026-04-09)
4
+
5
+
6
+ ### Features
7
+
8
+ * Improve PHP and Python emitter generation ([#30](https://github.com/workos/oagen-emitters/issues/30)) ([9f4aa98](https://github.com/workos/oagen-emitters/commit/9f4aa981a35e125a6e9316bb91b666eaf0e2d2bd))
9
+ * oagen-emitter updates to handle Golang ([#33](https://github.com/workos/oagen-emitters/issues/33)) ([bf8b872](https://github.com/workos/oagen-emitters/commit/bf8b872a93f20c77f64e6cec9657adfd24d14871))
10
+
3
11
  ## [0.2.1](https://github.com/workos/oagen-emitters/compare/v0.2.0...v0.2.1) (2026-03-26)
4
12
 
5
13
 
package/README.md CHANGED
@@ -16,6 +16,51 @@ npm test # run emitter unit tests
16
16
  npm run typecheck # verify types
17
17
  ```
18
18
 
19
+ ### Using a local `oagen` checkout
20
+
21
+ This repo depends on a published `@workos/oagen` by default.
22
+
23
+ If you are actively changing the sibling checkout at `../oagen`, you can switch this repo to a local linked copy:
24
+
25
+ ```bash
26
+ npm run oagen:use:local
27
+ ```
28
+
29
+ That script:
30
+
31
+ 1. builds `../oagen`
32
+ 2. links it into this repo with `npm link`
33
+
34
+ `@workos/oagen` exports from `dist/`, so rebuild the local repo after changes:
35
+
36
+ ```bash
37
+ npm run oagen:build:local
38
+ ```
39
+
40
+ To go back to the published package from npm:
41
+
42
+ ```bash
43
+ npm run oagen:use:published
44
+ ```
45
+
46
+ Git does not provide a standard `post-push` hook, so the reliable way to push with the published package and then restore the local link is the wrapper script:
47
+
48
+ ```bash
49
+ npm run git:push -- <git push args>
50
+ ```
51
+
52
+ Example:
53
+
54
+ ```bash
55
+ npm run git:push -- origin HEAD
56
+ ```
57
+
58
+ That command:
59
+
60
+ 1. switches to the published `@workos/oagen`
61
+ 2. runs `git push ...`
62
+ 3. restores the local `../oagen` link on exit, even if the push fails
63
+
19
64
  ## Workflows
20
65
 
21
66
  ### Setting up a new language
@@ -111,6 +156,90 @@ Runs compat verification (checks that generated types preserve the live SDK's pu
111
156
 
112
157
  **When to run:** After any generation to verify correctness, or in CI.
113
158
 
159
+ ## SDK Behavior
160
+
161
+ Emitters read runtime policy (retry, errors, telemetry, pagination, etc.) from `ctx.spec.sdk` rather than hardcoding values. The `ApiSpec.sdk` field is always populated with defaults from `defaultSdkBehavior()`.
162
+
163
+ ```ts
164
+ function generateHttpClient(ctx: EmitterContext) {
165
+ const sdk = ctx.spec.sdk;
166
+ const retryCodes = sdk.retry.retryableStatusCodes; // [429, 500, 502, 503, 504]
167
+ const timeout = sdk.timeout.defaultTimeoutSeconds; // 60
168
+ }
169
+ ```
170
+
171
+ Per-language overrides go in the SDK's `oagen.config.ts`:
172
+
173
+ ```ts
174
+ // Example: Python SDK overrides
175
+ export default {
176
+ sdkBehavior: {
177
+ retry: { backoff: { initialDelay: 0.5, maxDelay: 8.0 } },
178
+ timeout: {
179
+ defaultTimeoutSeconds: 30,
180
+ timeoutEnvVar: "WORKOS_REQUEST_TIMEOUT",
181
+ },
182
+ },
183
+ };
184
+ ```
185
+
186
+ See `@workos/oagen`'s `src/ir/sdk-behavior.ts` for all interfaces and default values.
187
+
188
+ ## Operation Hints
189
+
190
+ `oagen.config.ts` defines `operationHints` and `mountRules` that control how operations are named and organized across all SDKs.
191
+
192
+ ### Adding a hint for a new operation
193
+
194
+ When the spec adds a new endpoint and the algorithm-derived name is wrong, add an entry to `operationHints`:
195
+
196
+ ```ts
197
+ const operationHints: Record<string, OperationHint> = {
198
+ // Override derived name
199
+ "GET /sso/authorize": { name: "get_authorization_url" },
200
+
201
+ // Remount to a different service
202
+ "GET /organizations/{id}/audit_logs_retention": { mountOn: "AuditLogs" },
203
+ };
204
+ ```
205
+
206
+ ### Adding a union split
207
+
208
+ For endpoints that accept a discriminated union body (multiple request shapes), use `split`:
209
+
210
+ ```ts
211
+ 'POST /user_management/authenticate': {
212
+ split: [
213
+ {
214
+ name: 'authenticate_with_password',
215
+ targetVariant: 'PasswordSessionAuthenticateRequest',
216
+ defaults: { grant_type: 'password' },
217
+ inferFromClient: ['client_id', 'client_secret'],
218
+ exposedParams: ['email', 'password', 'invitation_token'],
219
+ },
220
+ // ... more variants
221
+ ],
222
+ },
223
+ ```
224
+
225
+ ### Mount rules
226
+
227
+ Instead of adding `mountOn` to every operation individually, use `mountRules` for service-level remounting:
228
+
229
+ ```ts
230
+ const mountRules: Record<string, string> = {
231
+ Connections: "SSO", // All Connections ops → SSO namespace
232
+ DirectoryGroups: "DirectorySync",
233
+ UserManagementUsers: "UserManagement",
234
+ };
235
+ ```
236
+
237
+ ### Reviewing operations
238
+
239
+ ```bash
240
+ npx oagen resolve --spec ../openapi-spec/spec/open-api-spec.yaml --format table
241
+ ```
242
+
114
243
  ## Adding a new language
115
244
 
116
245
  Use the oagen skills:
package/dist/index.d.mts CHANGED
@@ -3,5 +3,14 @@ import { Emitter } from "@workos/oagen";
3
3
  //#region src/node/index.d.ts
4
4
  declare const nodeEmitter: Emitter;
5
5
  //#endregion
6
- export { nodeEmitter };
6
+ //#region src/python/index.d.ts
7
+ declare const pythonEmitter: Emitter;
8
+ //#endregion
9
+ //#region src/php/index.d.ts
10
+ declare const phpEmitter: Emitter;
11
+ //#endregion
12
+ //#region src/go/index.d.ts
13
+ declare const goEmitter: Emitter;
14
+ //#endregion
15
+ export { goEmitter, nodeEmitter, phpEmitter, pythonEmitter };
7
16
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/node/index.ts"],"mappings":";;;cAkCa,WAAA,EAAa,OAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/node/index.ts","../src/python/index.ts","../src/php/index.ts","../src/go/index.ts"],"mappings":";;;cA+Ba,WAAA,EAAa,OAAA;;;cCFb,aAAA,EAAe,OAAA;;;cCOf,UAAA,EAAY,OAAA;;;cCPZ,SAAA,EAAW,OAAA"}