|
1 | 1 | # @nestm/standard-schema |
2 | 2 |
|
| 3 | +## 0.1.0-alpha.8 |
| 4 | + |
| 5 | +### Minor Changes |
| 6 | + |
| 7 | +- 0c84e98: The plugin's `@StandardSchemaResponse` rewrite now carries a response status. |
| 8 | + |
| 9 | + The rewrite added in the previous release emitted `ApiStandardSchemaResponse(Source)` with no |
| 10 | + options, so `@nestjs/swagger` filed the schema under the `default` response key. Most client |
| 11 | + generators map `default` to the _error_ type, which left every success response untyped — the |
| 12 | + schemas were present but not usable for codegen. |
| 13 | + |
| 14 | + The status is derived exactly as the inference path derives it: `@HttpCode` wins, otherwise |
| 15 | + `@Post` is 201 and every other verb is 200. |
| 16 | + |
| 17 | + **The rewrite backs off rather than guessing.** It leaves `@StandardSchemaResponse` untouched |
| 18 | + when: |
| 19 | + |
| 20 | + - the method takes a raw `@Res()`/`@Response()` parameter — the handler owns the status, and no |
| 21 | + static analysis can see `res.status(...)`; |
| 22 | + - the route is `@Redirect()` — Nest discards `@HttpCode` there, so neither the decorator nor the |
| 23 | + verb predicts the status; |
| 24 | + - the status resolves to 204 — OpenAPI forbids a body on 204, and the inference path refuses this |
| 25 | + case twice; |
| 26 | + - the status is not statically resolvable, e.g. `@HttpCode(SOME_NUMBER)`; |
| 27 | + - any `@nestjs/swagger` response decorator is already on the method. |
| 28 | + |
| 29 | + Backing off is a _safe_ fallback, not a degraded one: with no response metadata at all, Swagger's |
| 30 | + own explorer emits the correct `200`/`201` key. It is the `default` entry that suppressed it. |
| 31 | + |
| 32 | + Two properties this preserves that a naive status would have broken: |
| 33 | + |
| 34 | + - **No new build failures.** Status resolution runs with `onAmbiguous: 'skip'` forced. The |
| 35 | + inference path may throw on an unresolvable status because it is volunteering metadata; the |
| 36 | + rewrite acts on code that already compiles, and those methods are invisible to the preflight |
| 37 | + pass, so a throw would escape mid-transform with a message telling the author to add the |
| 38 | + decorator they already have. |
| 39 | + - **No silently destroyed contracts.** Landing on a real status means sharing a response key with |
| 40 | + a hand-written `@ApiOkResponse`/`@ApiResponse`. That merge is destructive in a way decorator |
| 41 | + order cannot fix — `ResponseObjectFactory` short-circuits on `standardSchema` and omits `type`, |
| 42 | + so a hand-written `type: LegacyDto` would vanish with no diagnostic. |
| 43 | + |
| 44 | + `isArray` is deliberately not emitted: the rewrite does no return-type analysis, and the author's |
| 45 | + source may already be an array schema, which would be double-wrapped. |
| 46 | + |
| 47 | + A hand-written `@ApiStandardSchemaResponse(Source)` with no `{ status }` still lands on `default` |
| 48 | + — that is inherent to the decorator's own signature, and it is explicit user code where the option |
| 49 | + is available and now documented in the README. |
| 50 | + |
3 | 51 | ## 0.1.0-alpha.7 |
4 | 52 |
|
5 | 53 | ### Minor Changes |
|
0 commit comments