@contractkit/plugin-typescript 0.31.1 → 0.32.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.
@@ -13,11 +13,11 @@ function compileContractSource(source: string) {
13
13
  return { root: contract, output, diag };
14
14
  }
15
15
 
16
- function compileOpSource(source: string, file = 'users.ck') {
16
+ function compileOpSource(source: string, file = 'users.ck', options?: Parameters<typeof generateOp>[1]) {
17
17
  const diag = new DiagnosticCollector();
18
18
  const ck = parseCk(source, file, diag);
19
19
  const { op } = decomposeCk(ck);
20
- const output = generateOp(op);
20
+ const output = generateOp(op, options);
21
21
  return { root: op, output, diag };
22
22
  }
23
23
 
@@ -103,6 +103,15 @@ describe('OP pipeline (source -> parse -> codegen)', () => {
103
103
  expect(output).toContain('ctx.status = 201');
104
104
  });
105
105
 
106
+ it('validates response bodies end to end when validateResponses is on', () => {
107
+ const { output, diag } = compileOpSource(SIMPLE_USERS_OP, 'users.ck', { validateResponses: true });
108
+ expect(diag.hasErrors()).toBe(false);
109
+ // GET returns array(User), POST returns User — both re-parsed against their own schema.
110
+ expect(output).toContain('ctx.body = await parseAndValidate(result, z.array(User), 500);');
111
+ expect(output).toContain('ctx.body = await parseAndValidate(result, User, 500);');
112
+ expect(output).toContain("import { parseAndValidate } from '@maroonedsoftware/zod';");
113
+ });
114
+
106
115
  it('compiles an operation with params, request, and response', () => {
107
116
  const { output, diag } = compileOpSource(PARAMETERIZED_OP);
108
117
  expect(diag.hasErrors()).toBe(false);