@workos/oagen-emitters 0.8.2 → 0.9.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.
@@ -103,7 +103,7 @@ describe('kotlin/resources', () => {
103
103
  ],
104
104
  };
105
105
  const files = generateResources(services, { ...ctxFor(services), spec: spec as ApiSpec });
106
- const ssoFile = files.find((file) => file.path.endsWith('/Sso.kt'));
106
+ const ssoFile = files.find((file) => file.path.endsWith('/SSO.kt'));
107
107
  expect(ssoFile).toBeDefined();
108
108
  expect(ssoFile!.content).toContain('fun getProfileAndToken(');
109
109
  expect(ssoFile!.content).toContain('code: String');
@@ -236,4 +236,97 @@ describe('kotlin/resources', () => {
236
236
  expect(sortOrder!.content).toContain('enum class SortOrder');
237
237
  expect(aliases.length).toBeLessThanOrEqual(1);
238
238
  });
239
+
240
+ it('emits a coroutine-friendly suspend overload alongside every blocking method', () => {
241
+ const services: Service[] = [
242
+ {
243
+ name: 'Users',
244
+ operations: [
245
+ {
246
+ name: 'getUser',
247
+ httpMethod: 'get',
248
+ path: '/users/{id}',
249
+ pathParams: [{ name: 'id', type: { kind: 'primitive', type: 'string' }, required: true }],
250
+ queryParams: [],
251
+ headerParams: [],
252
+ response: { kind: 'primitive', type: 'unknown' },
253
+ errors: [],
254
+ injectIdempotencyKey: false,
255
+ },
256
+ ],
257
+ },
258
+ ];
259
+ const files = generateResources(services, ctxFor(services));
260
+ const file = files.find((f) => f.path.endsWith('/Users.kt'))!;
261
+ expect(file.content).toContain('import kotlinx.coroutines.Dispatchers');
262
+ expect(file.content).toContain('import kotlinx.coroutines.withContext');
263
+ expect(file.content).toContain('@JvmName("getSuspend")');
264
+ expect(file.content).toMatch(/suspend fun getSuspend\([\s\S]*?withContext\(Dispatchers\.IO\)/);
265
+ });
266
+
267
+ it('emits Java-friendly per-variant overloads for sealed-class parameter groups', () => {
268
+ const services: Service[] = [
269
+ {
270
+ name: 'Authorization',
271
+ operations: [
272
+ {
273
+ name: 'check',
274
+ httpMethod: 'post',
275
+ path: '/authorization/check',
276
+ pathParams: [],
277
+ queryParams: [],
278
+ headerParams: [],
279
+ requestBody: { kind: 'model', name: 'CheckRequest' },
280
+ response: { kind: 'primitive', type: 'unknown' },
281
+ errors: [],
282
+ injectIdempotencyKey: false,
283
+ parameterGroups: [
284
+ {
285
+ name: 'resource_target',
286
+ optional: false,
287
+ variants: [
288
+ {
289
+ name: 'ById',
290
+ parameters: [{ name: 'resource_id', type: { kind: 'primitive', type: 'string' }, required: true }],
291
+ },
292
+ {
293
+ name: 'ByExternalId',
294
+ parameters: [
295
+ { name: 'resource_external_id', type: { kind: 'primitive', type: 'string' }, required: true },
296
+ { name: 'resource_type_slug', type: { kind: 'primitive', type: 'string' }, required: true },
297
+ ],
298
+ },
299
+ ],
300
+ },
301
+ ],
302
+ },
303
+ ],
304
+ },
305
+ ];
306
+ const spec = {
307
+ ...baseSpec,
308
+ services,
309
+ models: [
310
+ ...baseSpec.models,
311
+ {
312
+ name: 'CheckRequest',
313
+ fields: [],
314
+ },
315
+ ],
316
+ };
317
+ const files = generateResources(services, { ...ctxFor(services), spec: spec as ApiSpec });
318
+ const file = files.find((f) => f.path.endsWith('/Authorization.kt'))!;
319
+ // The canonical method still takes the sealed class.
320
+ expect(file.content).toMatch(/fun check\([\s\S]*?resourceTarget: ResourceTarget[\s\S]*?\)/);
321
+ // Java-friendly ById overload — keeps the base method name and takes the
322
+ // flat resource_id field.
323
+ expect(file.content).toMatch(/fun check\([\s\S]*?resourceId: String[\s\S]*?\) = check\(/);
324
+ // Java-friendly ByExternalId overload — uses the variant suffix.
325
+ expect(file.content).toMatch(/fun checkByExternalId\([\s\S]*?resourceExternalId: String/);
326
+ expect(file.content).toContain('ResourceTarget.ById(resourceId = resourceId)');
327
+ expect(file.content).toContain('Java-friendly overload');
328
+ // The sealed class itself carries Kotlin + Java construction examples.
329
+ expect(file.content).toContain('Usage from Kotlin:');
330
+ expect(file.content).toContain('Usage from Java:');
331
+ });
239
332
  });