@sumrco/cli 0.3.8 → 0.4.2
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.
- package/ARTIFACT-MANIFEST.json +18 -0
- package/README.md +12 -0
- package/THIRD_PARTY_NOTICES.md +1119 -0
- package/ai/modules/kontract/resources/api-generation-standards.rf.md +18 -5
- package/ai/modules/kontract/resources/authoring/configuration.rf.md +568 -12
- package/ai/modules/kontract/resources/authoring/schema-reuse.rf.md +25 -4
- package/ai/modules/kontract/resources/authoring/scope-and-splitting.rf.md +8 -6
- package/ai/modules/kontract/resources/authoring/spec-layout.rf.md +4 -0
- package/ai/modules/kontract/resources/generated-output.rf.md +712 -44
- package/ai/modules/kontract/resources/nestjs-eslint.rf.md +153 -0
- package/ai/modules/kontract/resources/openapi-sdk-generator-research.rf.md +177 -0
- package/ai/modules/kontract/resources/overview.md +70 -8
- package/ai/modules/kontract/resources/performance.rf.md +11 -2
- package/ai/modules/kontract/sumr.module.yaml +15 -14
- package/ai/modules/mission/resources/flow-config.rf.md +2 -2
- package/ai/modules/mission/resources/overview.md +42 -35
- package/ai/modules/mission/resources/stage-closeout.rf.md +5 -5
- package/ai/modules/mission/resources/stage-delivery.rf.md +5 -5
- package/ai/modules/mission/resources/stage-intake.rf.md +2 -2
- package/ai/modules/mission/resources/stage-planning.rf.md +43 -4
- package/ai/modules/mission/resources/stage-pull-request.rf.md +2 -2
- package/ai/modules/mission/resources/stage-quality.rf.md +8 -8
- package/ai/modules/mission/resources/team-members/planner.tm.md +17 -5
- package/ai/modules/mission/resources/workflows/daily-triage.cmd.md +5 -1
- package/ai/modules/mission/resources/workflows/mission-cycle.cmd.md +7 -5
- package/ai/modules/mission/resources/workflows/planning-only.cmd.md +8 -3
- package/ai/modules/mission/sumr.module.yaml +20 -16
- package/ai/modules/playbook/resources/authoring/extraction.rf.md +28 -1
- package/ai/modules/playbook/resources/authoring/frontmatter.rf.md +7 -0
- package/ai/modules/playbook/resources/authoring/overview.md +33 -2
- package/ai/modules/playbook/resources/authoring/patterns.rf.md +21 -0
- package/ai/modules/playbook/resources/team-members/technical-writer.tm.md +5 -1
- package/ai/modules/playbook/sumr.module.yaml +13 -12
- package/ai/registry.json +3 -3
- package/bin/sumr +18 -3
- package/eslint/index.mjs +2 -0
- package/eslint/kontract/index.mjs +22 -0
- package/eslint/kontract/rules/typescript-nestjs/operation-contract.mjs +656 -0
- package/index.js +3060 -458
- package/package.json +26 -23
- package/sbom.cdx.json +5111 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
---
|
|
2
|
+
category: reference
|
|
3
|
+
name: nestjs-eslint
|
|
4
|
+
title: NestJS Operation Contract ESLint
|
|
5
|
+
description: "How a NestJS consumer enables the public Kontract ESLint plugin to keep controller routes bound to their exact generated operations."
|
|
6
|
+
label: NestJS ESLint
|
|
7
|
+
when: Enabling the Kontract ESLint plugin in a NestJS app, configuring the operation contract rule, or debugging controller drift reports
|
|
8
|
+
order: 25
|
|
9
|
+
tags: [kontract, nestjs, eslint, zod, contracts]
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# NestJS Operation Contract ESLint
|
|
13
|
+
|
|
14
|
+
Kontract ships one reusable, operation-aware ESLint rule through the bundled
|
|
15
|
+
SUMR CLI. The rule is development tooling: it reads the metadata embedded in
|
|
16
|
+
generated `http/operations.ts` files and reports controller drift in editors and
|
|
17
|
+
CI. It does not generate or copy rule source into an application.
|
|
18
|
+
|
|
19
|
+
## Install and configure
|
|
20
|
+
|
|
21
|
+
The application needs the public CLI package as a development dependency so
|
|
22
|
+
ESLint can resolve its exported subpath. The application continues to own its
|
|
23
|
+
ESLint parser and ESLint version.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
bun add -d @sumrco/cli eslint @typescript-eslint/parser
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Enable `operationContract: true` on the NestJS generator target, regenerate,
|
|
30
|
+
and add a flat-config entry:
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import tsParser from '@typescript-eslint/parser';
|
|
34
|
+
import { kontractPlugin } from '@sumrco/cli/eslint';
|
|
35
|
+
|
|
36
|
+
export default [
|
|
37
|
+
{
|
|
38
|
+
files: ['backend/src/modules/**/*.controller.ts'],
|
|
39
|
+
languageOptions: { parser: tsParser },
|
|
40
|
+
plugins: { kontract: kontractPlugin },
|
|
41
|
+
rules: {
|
|
42
|
+
'kontract/nestjs-operation-contract': 'error',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Editors that run the workspace ESLint extension show the same diagnostics as
|
|
49
|
+
CI. Run the repository's normal ESLint command in CI; the plugin does not add a
|
|
50
|
+
second CLI command.
|
|
51
|
+
|
|
52
|
+
## What the rule proves
|
|
53
|
+
|
|
54
|
+
For standard NestJS JSON routes (`Get`, `Post`, `Put`, `Patch`, and `Delete`),
|
|
55
|
+
the rule requires exactly one generated `@Operation(OP)` and verifies:
|
|
56
|
+
|
|
57
|
+
- the imported operation identity and literal method/path;
|
|
58
|
+
- the generated request body import;
|
|
59
|
+
- the operation-owned `ZodValidationPipe` or generated multipart body pipe,
|
|
60
|
+
including the exact mixed-field input type;
|
|
61
|
+
- named path/query/header/cookie parameter names and exact generated primitive,
|
|
62
|
+
optional, and array types, while enum component references retain their
|
|
63
|
+
generated enum identity instead of widening to a primitive;
|
|
64
|
+
- operation-owned aggregate parameter types paired with
|
|
65
|
+
`OperationParameterBagPipe(Operation, location)`;
|
|
66
|
+
- the generated handler response type import;
|
|
67
|
+
- an explicit `@HttpCode()` does not conflict with the operation status; and
|
|
68
|
+
- no second serializer decorator competes with the operation-owned response
|
|
69
|
+
DTO, status, or transport.
|
|
70
|
+
|
|
71
|
+
Generated JSON controllers deliberately use one contract decorator:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
@Operation(GetBook)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
For managed JSON operations, `Operation` invokes native `nestjs-zod`
|
|
78
|
+
`ZodResponse` metadata at runtime while its generated overload preserves the
|
|
79
|
+
exact compile-time handler return constraint. The rule rejects redundant
|
|
80
|
+
`@ZodResponse`, legacy `@ZodSerializerDto`, conflicting explicit status, and
|
|
81
|
+
library-mode `@Res()` because each can bypass or compete with that operation
|
|
82
|
+
binding. `@Res({ passthrough: true })` keeps Nest response handling and is not
|
|
83
|
+
the unsafe library mode.
|
|
84
|
+
|
|
85
|
+
An operation authored with `x-response-mode: passthrough` is the narrow
|
|
86
|
+
exception. It owns its status, headers, cookies, body, serialization, and
|
|
87
|
+
documented errors, so the rule allows full `@Res()` and a `void` handler while
|
|
88
|
+
still checking the exact generated operation identity and route. It continues
|
|
89
|
+
to reject competing Zod serializer decorators. No-content and non-JSON
|
|
90
|
+
transports likewise do not acquire a JSON serializer.
|
|
91
|
+
|
|
92
|
+
Aliased named imports and namespace imports are supported. If generated files
|
|
93
|
+
are imported through a TypeScript path alias, map that alias to its filesystem
|
|
94
|
+
root:
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
rules: {
|
|
98
|
+
'kontract/nestjs-operation-contract': ['error', {
|
|
99
|
+
aliases: [
|
|
100
|
+
{ prefix: '~contracts', path: 'backend/src/shared/models' },
|
|
101
|
+
],
|
|
102
|
+
}],
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The rule resolves generated `http/index.ts` directory barrels as well as direct
|
|
107
|
+
`http/operations` imports. Nest controller strings and canonical object
|
|
108
|
+
options are both supported:
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
@Controller({ path: 'addons', version: '1' })
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
For URI versioning, method `@Version()` overrides the controller option;
|
|
115
|
+
`VERSION_NEUTRAL` remains neutral; otherwise the operation's generated target
|
|
116
|
+
default applies. The route check still reports real method, path, parameter,
|
|
117
|
+
or version drift.
|
|
118
|
+
|
|
119
|
+
Non-standard route decorators require an explicit exemption rather than an
|
|
120
|
+
implicit bypass:
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
'kontract/nestjs-operation-contract': ['error', {
|
|
124
|
+
exemptDecorators: ['Sse'],
|
|
125
|
+
}]
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Use exemptions only after the controller's transport behavior is covered by
|
|
129
|
+
transport-specific tests.
|
|
130
|
+
|
|
131
|
+
## Limits and stale output
|
|
132
|
+
|
|
133
|
+
Kontract records operation-owned body DTOs, response schemas/types, named
|
|
134
|
+
path/query/header/cookie parameters, and the generated aggregate type for each
|
|
135
|
+
non-empty parameter group. The rule requires those generated identities; it
|
|
136
|
+
never accepts a local DTO mirror or infers a contract from a parameter name.
|
|
137
|
+
|
|
138
|
+
If the rule reports that generated operation metadata cannot be resolved, run:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
sumr kontract validate
|
|
142
|
+
sumr kontract generate
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Then confirm the controller imports the regenerated `operations.ts` output and
|
|
146
|
+
configure `aliases` when the import is not relative.
|
|
147
|
+
|
|
148
|
+
This rule complements, and does not replace:
|
|
149
|
+
|
|
150
|
+
- TypeScript compilation;
|
|
151
|
+
- `nestjs-zod` runtime serialization;
|
|
152
|
+
- API/controller integration tests; and
|
|
153
|
+
- end-to-end tests of status, headers, envelopes, errors, and transports.
|
|
@@ -26,6 +26,45 @@ template systems.
|
|
|
26
26
|
<https://openapi-generator.tech/docs/generators/typescript-nestjs/>
|
|
27
27
|
- API schema TypeScript `openapi-fetch`:
|
|
28
28
|
<https://openapi-ts.dev/openapi-fetch/>
|
|
29
|
+
- Orval:
|
|
30
|
+
<https://orval.dev/docs/guides/react-query/>
|
|
31
|
+
- Orval Zod and validated client composition:
|
|
32
|
+
<https://orval.dev/docs/guides/zod/>
|
|
33
|
+
<https://orval.dev/docs/guides/client-with-zod/>
|
|
34
|
+
- Orval v8 migration and MSW:
|
|
35
|
+
<https://orval.dev/docs/versions/v8/>
|
|
36
|
+
<https://orval.dev/docs/guides/msw/>
|
|
37
|
+
- Kubb:
|
|
38
|
+
<https://docs.kubb.dev/plugins/plugin-react-query/>
|
|
39
|
+
<https://docs.kubb.dev/plugins/plugin-zod/>
|
|
40
|
+
- Hey API OpenAPI TypeScript:
|
|
41
|
+
<https://heyapi.dev/docs/openapi/typescript/plugins/tanstack-query>
|
|
42
|
+
<https://heyapi.dev/docs/openapi/typescript/plugins/zod>
|
|
43
|
+
|
|
44
|
+
License verification uses the primary repositories:
|
|
45
|
+
|
|
46
|
+
- Orval: <https://github.com/orval-labs/orval>
|
|
47
|
+
- Kubb: <https://github.com/kubb-labs/kubb>
|
|
48
|
+
- Hey API OpenAPI TypeScript: <https://github.com/hey-api/openapi-ts>
|
|
49
|
+
|
|
50
|
+
## Ecosystem comparison
|
|
51
|
+
|
|
52
|
+
The compared Orval, Kubb, and Hey API local code generators are
|
|
53
|
+
free/open-source under the MIT license.
|
|
54
|
+
Hosted services or sponsorship offerings are separate from using the generator
|
|
55
|
+
locally.
|
|
56
|
+
|
|
57
|
+
| Tool | Framework-neutral output | Runtime validation | TanStack output |
|
|
58
|
+
|------|--------------------------|--------------------|-----------------|
|
|
59
|
+
| OpenAPI Generator | Fetch/Axios/Angular and many language SDK templates. | Varies by target; TypeScript types alone do not validate JSON. | Not the primary TypeScript architecture; consumers typically add their own integration. |
|
|
60
|
+
| `openapi-fetch` | Small path/method-aware fetch client inferred from generated paths. | No Zod validation by default; low runtime size is the product goal. | Used directly as a query function or through separate integrations. |
|
|
61
|
+
| Orval | Fetch/Axios clients, models, mocks, and configurable mutators. | Can emit Zod schemas; fetch can enable runtime response validation. | Query functions, query keys, `useQuery`, suspense/infinite query hooks, mutations, and cache helpers. |
|
|
62
|
+
| Kubb | Plugin-composed clients and TypeScript models. | Zod plugin emits schemas and can derive types. | Typed query keys and generated query, suspense, infinite-query, and mutation hooks over its client plugin. |
|
|
63
|
+
| Hey API | Plugin-composed SDK/client and TypeScript models. | Zod plugin emits validators; validation must be wired into the chosen client boundary. | Query-key, `queryOptions`, `infiniteQueryOptions`, and `mutationOptions` factories. |
|
|
64
|
+
|
|
65
|
+
The important design lesson is not to copy every framework surface into the
|
|
66
|
+
core SDK. Mature tools separate reusable schema/client artifacts from opt-in
|
|
67
|
+
framework adapters.
|
|
29
68
|
|
|
30
69
|
## SDK generation standards
|
|
31
70
|
|
|
@@ -47,6 +86,12 @@ template systems.
|
|
|
47
86
|
- Keep the fetch runtime small. `openapi-fetch` is a useful benchmark for a
|
|
48
87
|
low-runtime client; Kontract should avoid pulling in a heavy client runtime
|
|
49
88
|
unless a target explicitly asks for it.
|
|
89
|
+
- Treat binary as operation transport metadata rather than a JSON-schema
|
|
90
|
+
assertion. Current Orval, OpenAPI Generator, Kubb, and Hey API behavior
|
|
91
|
+
converges on browser `Blob` typing, but several targets fail to decode bytes
|
|
92
|
+
or preserve JSON errors. Kontract therefore selects `Response.blob()` /
|
|
93
|
+
`responseType: 'blob'` from Contract IR and independently decodes declared
|
|
94
|
+
JSON error bodies.
|
|
50
95
|
|
|
51
96
|
## Current product decisions
|
|
52
97
|
|
|
@@ -55,3 +100,135 @@ template systems.
|
|
|
55
100
|
the target into a standalone frontend package.
|
|
56
101
|
- `typescript-fetch`, `typescript-axios`, and `typescript-angular` remain
|
|
57
102
|
standalone SDK targets with their own generated models.
|
|
103
|
+
- `typescript-models` remains model-only, but may emit framework-neutral Zod
|
|
104
|
+
schemas beside the TypeScript models.
|
|
105
|
+
- All five base TypeScript targets accept opt-in `zod: true`. Input and output
|
|
106
|
+
schemas are directional so `readOnly` and `writeOnly` fields do not collapse
|
|
107
|
+
into one unsafe shape.
|
|
108
|
+
- `operationContract` remains NestJS-only. The frontend operation registry is
|
|
109
|
+
a separate artifact even though both consume the same normalized
|
|
110
|
+
operation intermediate representation (IR).
|
|
111
|
+
- Kontract core remains independent of TanStack Query. An optional adapter may
|
|
112
|
+
generate TanStack source for consumers that opt in.
|
|
113
|
+
- The public adapter identifier is `react-query-hooks`. Keys and options
|
|
114
|
+
factories are the reusable implementation primitive; direct hooks are the
|
|
115
|
+
default headline artifact but can be disabled independently.
|
|
116
|
+
- A schema-owned success `envelope` is shared Contract IR. Zod-enabled Fetch,
|
|
117
|
+
Axios, Angular, React Query, and the NestJS-composed SDK validate the full
|
|
118
|
+
wire response before returning its declared payload. Fixture validators keep
|
|
119
|
+
the wire envelope, and declared error responses are not projected.
|
|
120
|
+
- Binary success responses are returned as browser `Blob` by Fetch, Axios,
|
|
121
|
+
Angular, and React Query. Runtime validation checks the operation/status/media
|
|
122
|
+
boundary and `Blob` representation rather than applying `z.string()` to
|
|
123
|
+
bytes. JSON problem responses on the same operation retain generated error
|
|
124
|
+
validation and `HttpError` typing.
|
|
125
|
+
|
|
126
|
+
### React Query design comparison
|
|
127
|
+
|
|
128
|
+
Orval demonstrates the breadth expected by React Query users: generated query
|
|
129
|
+
functions/keys/hooks, mutations, suspense/infinite modes, per-operation
|
|
130
|
+
overrides, mutators, signals, mock output, and cache helpers. Kubb reinforces a
|
|
131
|
+
plugin-composed architecture where Zod/client/React Query are complementary.
|
|
132
|
+
Hey API provides the clearest reusable factory pattern:
|
|
133
|
+
`queryOptions`, `infiniteQueryOptions`, and `mutationOptions` can feed hooks,
|
|
134
|
+
SSR, prefetching, router loaders, and imperative cache APIs.
|
|
135
|
+
|
|
136
|
+
Kontract combines those lessons without copying application policy:
|
|
137
|
+
|
|
138
|
+
- deterministic `[service, 'operation', operationId, request]` keys plus
|
|
139
|
+
service/operation/tag/surface predicates;
|
|
140
|
+
- query, skippable query, suspense query, explicit infinite query, and mutation
|
|
141
|
+
factories;
|
|
142
|
+
- direct `useQuery`, `useSuspenseQuery`, `useInfiniteQuery`,
|
|
143
|
+
`useSuspenseInfiniteQuery`, and `useMutation` wrappers when enabled;
|
|
144
|
+
- `AbortSignal` forwarding from TanStack query functions into the generated
|
|
145
|
+
client;
|
|
146
|
+
- operation-owned validated success/error types;
|
|
147
|
+
- per-operation `hooks`, `options`, `suspense`, and explicit pagination
|
|
148
|
+
overrides;
|
|
149
|
+
- application-injected client/transport;
|
|
150
|
+
- consumer-owned `select`, SSR, retry, invalidation, and optimistic-update
|
|
151
|
+
policy.
|
|
152
|
+
|
|
153
|
+
Infinite output requires a configured query parameter and initial page value.
|
|
154
|
+
Kontract does not infer cursor/offset semantics from a property name. Disabled
|
|
155
|
+
required inputs use a `skipToken` factory path; optional operations keep a
|
|
156
|
+
stable empty request object. Tag/surface helpers support technical cache
|
|
157
|
+
selection but do not decide which product event invalidates which feature.
|
|
158
|
+
|
|
159
|
+
`@tanstack/react-query` is required only by the generated
|
|
160
|
+
`react-query-hooks` consumer package. It is not a Kontract runtime dependency.
|
|
161
|
+
Generated entry points keep `models`, `schemas`, `operations`, `fixtures`,
|
|
162
|
+
`query-keys`, and `react-query` separately importable for tree shaking.
|
|
163
|
+
|
|
164
|
+
## Multi-file schema quality gate
|
|
165
|
+
|
|
166
|
+
Standalone SDK targets must be validated with sanitized, repository-owned
|
|
167
|
+
multi-file fixtures. Local-component-only examples are not sufficient because
|
|
168
|
+
they do not exercise external reference ownership or bundled reference graphs.
|
|
169
|
+
|
|
170
|
+
The release gate verifies that:
|
|
171
|
+
|
|
172
|
+
- operation methods and request parameter interfaces remain stable;
|
|
173
|
+
- method, URL, path, query, and body serialization stay contract-correct;
|
|
174
|
+
- reusable response `$sets` reached through reference-only roots expand before
|
|
175
|
+
operation IR construction, including every declared success and error status;
|
|
176
|
+
- external response references resolve to the operation-owned collection or
|
|
177
|
+
model instead of degrading to a scalar or sibling type;
|
|
178
|
+
- opt-in Zod emits directional input/output schemas and selects the correct
|
|
179
|
+
status/content-type decoder;
|
|
180
|
+
- explicit envelope policy validates the selected wire component for every
|
|
181
|
+
JSON-compatible successful status that references it, rejects incompatible
|
|
182
|
+
media for that shared component, returns one declared success payload type,
|
|
183
|
+
preserves wire fixtures, and leaves typed error bodies intact;
|
|
184
|
+
- required nullable properties remain required unions with `null`;
|
|
185
|
+
- OpenAPI 3.0 scalar/enum `$ref` wrappers using one `allOf` part preserve
|
|
186
|
+
referenced identity and outer nullability across models, Zod, and operation
|
|
187
|
+
metadata;
|
|
188
|
+
- Fetch, Axios, and Angular targets expose validated success and typed failure
|
|
189
|
+
categories;
|
|
190
|
+
- binary success operations return `Blob` without text decoding, propagate that
|
|
191
|
+
type through React Query, retain zero-byte payloads, and still validate
|
|
192
|
+
declared JSON error bodies;
|
|
193
|
+
- operation security is present in the registry; explicit `security: []`
|
|
194
|
+
bypasses generated auth providers while inherited or declared requirements
|
|
195
|
+
invoke them with structured schemes/scopes across Fetch, Axios, and Angular;
|
|
196
|
+
- per-call cancellation, request options, authentication, and error hooks
|
|
197
|
+
remain available; and
|
|
198
|
+
- generated sources compile with unused-local detection enabled; and
|
|
199
|
+
- unchanged reruns skip deterministically.
|
|
200
|
+
|
|
201
|
+
Fixture names, operations, and domain properties must remain neutral. Private
|
|
202
|
+
schemas and application-specific source artifacts do not belong in packaged AI
|
|
203
|
+
guidance or release fixtures.
|
|
204
|
+
|
|
205
|
+
## Delivery sequence and retained scope
|
|
206
|
+
|
|
207
|
+
1. **Correctness first:** normalize and resolve every request/response reference
|
|
208
|
+
before any emitter runs. Add multi-file external-reference fixtures and
|
|
209
|
+
operation-to-model assertions.
|
|
210
|
+
2. **Runtime schemas:** allow a frontend Zod capability for standalone targets.
|
|
211
|
+
Generate schemas, input/output types, enum values, and operation response
|
|
212
|
+
maps from one IR rather than post-processing TypeScript text.
|
|
213
|
+
3. **Validated core client:** decode by operation, status, and content type;
|
|
214
|
+
return only parsed values; model HTTP, transport, and validation failures
|
|
215
|
+
explicitly; support cancellation and per-call transport options.
|
|
216
|
+
4. **Contract fixtures:** generate or validate MSW/fixture inputs from the same
|
|
217
|
+
runtime schemas so frontend mocks cannot silently drift.
|
|
218
|
+
5. **Optional framework adapter:** add a separate TanStack target or plugin that
|
|
219
|
+
emits deterministic keys plus `queryOptions`, `infiniteQueryOptions`, and
|
|
220
|
+
`mutationOptions`. Keep React hooks optional and keep TanStack out of the
|
|
221
|
+
core generator runtime.
|
|
222
|
+
|
|
223
|
+
Do not generate application view models, form state, labels, optimistic-update
|
|
224
|
+
business rules, or domain transformations. Those remain consumer-owned and
|
|
225
|
+
must accept validated generated models as input.
|
|
226
|
+
|
|
227
|
+
Current explicit limitation: recursive component graphs fail before emission
|
|
228
|
+
with a cycle diagnostic. Kontract does not emit an eager Zod import graph that
|
|
229
|
+
would fail at runtime; lazy schema support remains planned. There is no implicit
|
|
230
|
+
coercion, default application, timezone conversion, money conversion, or
|
|
231
|
+
undocumented envelope unwrapping. Explicit `envelope` decoding applies only
|
|
232
|
+
after validating the schema-owned wire response. Dates/date-times remain
|
|
233
|
+
validated wire strings. Unsupported schema features fail rather than degrade
|
|
234
|
+
to an assertion.
|
|
@@ -23,6 +23,7 @@ schemas.
|
|
|
23
23
|
- Regenerating contracts after a spec change.
|
|
24
24
|
- Validating specs before committing or in CI.
|
|
25
25
|
- Wiring generated contracts into a service or client.
|
|
26
|
+
- Wiring the public Kontract ESLint plugin into a NestJS consumer.
|
|
26
27
|
|
|
27
28
|
## Commands
|
|
28
29
|
|
|
@@ -72,7 +73,8 @@ Choose the protocol scenario first:
|
|
|
72
73
|
```text
|
|
73
74
|
schema/
|
|
74
75
|
recipes.api.yml → contracts/recipes/http/
|
|
75
|
-
recipes.async.yml → contracts/recipes/
|
|
76
|
+
recipes.async.yml → contracts/recipes/async/ (asyncapi-models)
|
|
77
|
+
→ contracts/recipes/nats/ (asyncapi-nats)
|
|
76
78
|
orders/
|
|
77
79
|
main.api.yml → contracts/orders/http/
|
|
78
80
|
public.api.yml → contracts/orders/http/
|
|
@@ -110,26 +112,81 @@ kontract:
|
|
|
110
112
|
generator:
|
|
111
113
|
type: typescript-nestjs
|
|
112
114
|
zod: true
|
|
115
|
+
dto: both
|
|
113
116
|
swagger: true
|
|
117
|
+
operationContract: true
|
|
118
|
+
foundation: true
|
|
119
|
+
controllers: true
|
|
120
|
+
errors: true
|
|
121
|
+
mappers: true
|
|
122
|
+
tests: true
|
|
123
|
+
bruno: true
|
|
124
|
+
framework: fastify
|
|
114
125
|
- name: frontend
|
|
115
126
|
output: frontend/src/shared/api
|
|
116
127
|
generator:
|
|
117
128
|
type: typescript-fetch
|
|
129
|
+
zod: true
|
|
130
|
+
- name: frontend-query
|
|
131
|
+
output: frontend/src/shared/query-api
|
|
132
|
+
generator:
|
|
133
|
+
type: react-query-hooks
|
|
134
|
+
zod: true
|
|
135
|
+
- name: realtime-contracts
|
|
136
|
+
output: frontend/src/shared/realtime
|
|
137
|
+
generator:
|
|
138
|
+
type: asyncapi-models
|
|
118
139
|
```
|
|
119
140
|
|
|
120
141
|
For server-contract targets:
|
|
121
142
|
|
|
122
|
-
- `zod: true` emits runtime validation
|
|
123
|
-
|
|
124
|
-
|
|
143
|
+
- `zod: true` emits framework-neutral runtime validation schemas and inferred
|
|
144
|
+
types under `http/zod/`.
|
|
145
|
+
- `dto: zod`, `dto: class-validator`, or `dto: both` selects the NestJS DTO
|
|
146
|
+
constructors emitted for the target. `dto: none` disables DTO constructors.
|
|
125
147
|
- `swagger: true` emits per-service `http/swagger.ts` operation metadata and one
|
|
126
148
|
shared `shared/http/decorators/api-doc.ts` helper.
|
|
127
149
|
- `sdk: true` emits a fetch-based `http/sdk/` client that reuses the same
|
|
128
150
|
`http/models/` and `http/enums/` generated for the target.
|
|
129
|
-
- `
|
|
130
|
-
|
|
151
|
+
- `operationContract: true` emits an exact operation-owned descriptor including
|
|
152
|
+
method/path, statuses, request/handler/wire schemas, parameters, errors,
|
|
153
|
+
transport, security, content types, and provenance.
|
|
154
|
+
- `foundation: true` emits the DI-preserving request/response/error/security
|
|
155
|
+
boundary and shared `configureApp()` used by production and tests.
|
|
156
|
+
- `controllers: true` emits thin transport adapters and an application-owned
|
|
157
|
+
port seam. Generated adapters never contain business logic.
|
|
158
|
+
- `framework: express` (the default) or `framework: fastify` selects the
|
|
159
|
+
generated HTTP adapter. Multipart operations are activated by the OpenAPI
|
|
160
|
+
`multipart/form-data` request itself; no separate multipart flag exists.
|
|
161
|
+
- `errors`, `mappers`, `tests`, and `bruno` opt into the corresponding error,
|
|
162
|
+
structural-projection, contract-test, and request-coverage artifacts.
|
|
163
|
+
- Deprecated Boolean `dtos` and Boolean `dto` values remain accepted for
|
|
164
|
+
existing projects and normalize to the equivalent explicit `dto` mode.
|
|
165
|
+
Prefer `dto: none`, `zod`, `class-validator`, or `both` in new config.
|
|
131
166
|
- Framework-neutral model interfaces are emitted under `http/models/`.
|
|
132
167
|
|
|
168
|
+
For TypeScript client/model targets:
|
|
169
|
+
|
|
170
|
+
- `zod: true` is opt-in for Fetch, Axios, Angular, models-only, NestJS, and
|
|
171
|
+
React Query output.
|
|
172
|
+
- Runtime-validated SDKs emit directional component schemas, a
|
|
173
|
+
framework-neutral operation registry, fixture validators, and typed
|
|
174
|
+
HTTP/transport/abort/contract failures.
|
|
175
|
+
- `react-query-hooks` emits the validated Fetch client plus deterministic
|
|
176
|
+
query keys, options factories, and configurable direct hooks. TanStack is a
|
|
177
|
+
dependency of the generated consumer, not Kontract core.
|
|
178
|
+
- Direct client methods remain usable without React Query.
|
|
179
|
+
|
|
180
|
+
For asynchronous targets:
|
|
181
|
+
|
|
182
|
+
- `asyncapi-models` emits transport-neutral Zod v4 schemas, TypeScript message
|
|
183
|
+
types, channel-address event constants, channel-message constants,
|
|
184
|
+
application-relative `send`/`receive` payload maps, a discriminated event
|
|
185
|
+
union, runtime parsers/failures, and fixture validators.
|
|
186
|
+
- Socket.IO/WebSocket/custom adapters consume that registry; Kontract does not
|
|
187
|
+
generate or depend on those transports for this target.
|
|
188
|
+
- `asyncapi-nats` adds NATS-specific subjects and client/server adapters.
|
|
189
|
+
|
|
133
190
|
If a consuming repo is missing API metadata output, first confirm the target has
|
|
134
191
|
`swagger: true`, and that the installed `SUMR Kontract module` version contains
|
|
135
192
|
the metadata helper.
|
|
@@ -139,9 +196,11 @@ the metadata helper.
|
|
|
139
196
|
| Category | Generator | Outputs |
|
|
140
197
|
|---|---|---|
|
|
141
198
|
| Server contracts | `typescript-nestjs` | Runtime validation contracts, DTOs, models, API metadata, optional SDK. |
|
|
199
|
+
| Messaging contracts | `asyncapi-models` | Transport-neutral message schemas/types, event registry, direction maps, parsers, and fixtures. |
|
|
142
200
|
| Messaging | `asyncapi-nats` | Message subjects, message schemas, client/server interfaces. |
|
|
143
201
|
| Client/SDK | `typescript-fetch` / `typescript-axios` / `typescript-angular` | Standalone TypeScript clients with bundled models. |
|
|
144
202
|
| Model | `typescript-models` | Framework-model-only output. |
|
|
203
|
+
| Framework adapter/SDK | `react-query-hooks` | Validated Fetch SDK plus TanStack keys/options and optional hooks. |
|
|
145
204
|
|
|
146
205
|
Roadmap and future generator ideas live in `docs/internal/generator-roadmap.md`; exported AI resources describe current supported behavior only.
|
|
147
206
|
|
|
@@ -160,8 +219,9 @@ Roadmap and future generator ideas live in `docs/internal/generator-roadmap.md`;
|
|
|
160
219
|
docs, Swagger, Scalar, generated SDKs, or AI answers. Review changed copy
|
|
161
220
|
against the repo's copywriter standard before generation.
|
|
162
221
|
- Design specs for reuse: shared parameters, scalar constraints, error responses,
|
|
163
|
-
response envelope fragments, pagination metadata,
|
|
164
|
-
and common config objects belong in shared components referenced
|
|
222
|
+
response envelope fragments, pagination metadata, repeated nested value
|
|
223
|
+
objects, and common config objects belong in shared components referenced
|
|
224
|
+
with `$ref`.
|
|
165
225
|
- Read `kontract.guidance.profile` before writing examples. Align path,
|
|
166
226
|
channel, component, and folder samples to the selected API, async, and schema
|
|
167
227
|
layout styles.
|
|
@@ -195,6 +255,8 @@ Roadmap and future generator ideas live in `docs/internal/generator-roadmap.md`;
|
|
|
195
255
|
inline schemas, SDK serialization, or strict TypeScript compatibility rules.
|
|
196
256
|
- See the API schema SDK generator research reference before changing SDK runtime
|
|
197
257
|
shape, target defaults, or model imports.
|
|
258
|
+
- See the NestJS operation contract ESLint reference before enabling
|
|
259
|
+
`operationContract` controller enforcement.
|
|
198
260
|
- Use scoped flags (`--source`, `--target`, `--specific`) before `--clean` in a
|
|
199
261
|
large consumer repo.
|
|
200
262
|
- Warm generation is manifest-driven. Kontract stores per-service manifests in
|
|
@@ -20,10 +20,19 @@ For each configured source/target/service/channel, Kontract writes a manifest un
|
|
|
20
20
|
.sumr-cache/kontract/bundles/<source>/<target>/manifests/<channel>/<service>/manifest.json
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
The manifest records the generator config hash, generator implementation hash,
|
|
23
|
+
The manifest records the generator config hash, generator implementation hash,
|
|
24
|
+
source dependency graph hash, exact output tree hash, generated files, Bun
|
|
25
|
+
version, and package version.
|
|
24
26
|
|
|
25
27
|
Warm generation skips a service before parsing/emitting only when all hashes still match. Manual generated-file edits or deletions invalidate the output tree hash and force regeneration.
|
|
26
28
|
|
|
29
|
+
SUMR-standard audience marker lines emitted from `x-kontract-audiences` and
|
|
30
|
+
`generator.audiences.marker: true` are ordinary generated content and are
|
|
31
|
+
included in the exact output hash. A consumer postprocessor that inserts,
|
|
32
|
+
removes, or changes markers invalidates the manifest and forces regeneration;
|
|
33
|
+
build-scope facts must come from the authored contract and generator
|
|
34
|
+
configuration instead.
|
|
35
|
+
|
|
27
36
|
## Clean generation
|
|
28
37
|
|
|
29
38
|
Use scoped clean when the cache or generated output may be stale:
|
|
@@ -62,7 +71,7 @@ KONTRACT_DISABLE_REDOCLY_CORE=1 sumr kontract generate
|
|
|
62
71
|
|
|
63
72
|
## Worker strategy
|
|
64
73
|
|
|
65
|
-
When concurrency is greater than one, Kontract uses a Bun worker pool for parse/extract/emit/write tasks. The main process still owns discovery, manifest validation, final
|
|
74
|
+
When concurrency is greater than one, Kontract uses a Bun worker pool for parse/extract/emit/write tasks. The main process still owns discovery, manifest validation, final generated entry points, final formatting, and summaries.
|
|
66
75
|
|
|
67
76
|
Emergency/debug fallbacks:
|
|
68
77
|
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
apiVersion: sumr.dev/v1
|
|
2
2
|
kind: CliModule
|
|
3
|
+
|
|
3
4
|
metadata:
|
|
4
|
-
name: kontract
|
|
5
|
-
package: "@sumrco/cli"
|
|
6
5
|
description: Generate and validate API contract artifacts
|
|
6
|
+
name: kontract
|
|
7
7
|
owners:
|
|
8
8
|
- team: "@sumr-org/kontract-team"
|
|
9
|
+
package: "@sumrco/cli"
|
|
9
10
|
tags:
|
|
10
11
|
- contracts
|
|
11
12
|
- openapi
|
|
12
13
|
- asyncapi
|
|
13
14
|
spec:
|
|
14
|
-
visibility: public
|
|
15
|
-
group: modules
|
|
16
|
-
targets:
|
|
17
|
-
contractVersion: ^1.0.0
|
|
18
|
-
bunVersion: ">=1.1.0"
|
|
19
15
|
commands:
|
|
20
16
|
- name: init
|
|
21
17
|
summary: Activate Kontract AI guidance for this workspace
|
|
@@ -30,16 +26,21 @@ spec:
|
|
|
30
26
|
summary: Validate API specifications
|
|
31
27
|
visibility: public
|
|
32
28
|
exports:
|
|
33
|
-
resources: []
|
|
34
|
-
binaries: []
|
|
35
29
|
aiResources:
|
|
36
|
-
module: kontract
|
|
37
|
-
roots:
|
|
38
|
-
- ./resources
|
|
39
30
|
activation:
|
|
40
|
-
mode: command
|
|
41
31
|
initCommand: kontract init
|
|
42
32
|
key: kontract
|
|
33
|
+
mode: command
|
|
34
|
+
module: kontract
|
|
35
|
+
roots:
|
|
36
|
+
- ./resources
|
|
37
|
+
binaries: []
|
|
38
|
+
resources: []
|
|
43
39
|
flags:
|
|
44
|
-
experimental: false
|
|
45
40
|
deprecated: null
|
|
41
|
+
experimental: false
|
|
42
|
+
group: modules
|
|
43
|
+
targets:
|
|
44
|
+
bunVersion: ">=1.1.0"
|
|
45
|
+
contractVersion: ^1.0.0
|
|
46
|
+
visibility: public
|
|
@@ -14,9 +14,9 @@ Mission flow is repo configuration in `sumr.yaml`; runtime state stays in `.sumr
|
|
|
14
14
|
```yaml
|
|
15
15
|
mission:
|
|
16
16
|
tracker:
|
|
17
|
-
provider:
|
|
17
|
+
provider: <work-provider>
|
|
18
18
|
git:
|
|
19
|
-
provider:
|
|
19
|
+
provider: <repository-provider>
|
|
20
20
|
prMode: ask
|
|
21
21
|
flow:
|
|
22
22
|
preset: standard-delivery
|