Skip to content

Commit f6c56d3

Browse files
authored
Merge pull request #24 from nestm-dev/changeset-release/main
chore: release @nestm/standard-schema (alpha)
2 parents bfce9b8 + d37232a commit f6c56d3

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

‎.changeset/pre.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"fix-alpha-publish",
1212
"infer-native-responses",
1313
"initial-release",
14+
"rewrite-response-status",
1415
"share-swagger-array-markers",
1516
"swagger-native-metadata"
1617
]

‎CHANGELOG.md‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,53 @@
11
# @nestm/standard-schema
22

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+
351
## 0.1.0-alpha.7
452

553
### Minor Changes

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nestm/standard-schema",
3-
"version": "0.1.0-alpha.7",
3+
"version": "0.1.0-alpha.8",
44
"description": "DTO ergonomics for NestJS 12's native Standard Schema validation and serialization.",
55
"license": "MIT",
66
"author": "Kauan Guesser",

0 commit comments

Comments
 (0)