zod-nest 3.5.0 → 3.7.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.
- package/README.md +2 -2
- package/dist/index.d.mts +36 -27
- package/dist/index.d.ts +36 -27
- package/dist/index.js +205 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +205 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ A short list of behavioural differences you'll hit on day one. Full migration ta
|
|
|
42
42
|
- **Multi-status `@ZodResponse`** — stack the decorator per status code. In `nestjs-zod`, multi-status required mixing `@ZodSerializerDto` with hand-rolled `@ApiResponse({ status: ... })` calls.
|
|
43
43
|
- **No internal `@HttpCode`** — `@ZodResponse` does **not** call `@HttpCode` under the hood. Status resolution precedence: `@ZodResponse({ status })` → `@HttpCode(...)` on the handler → method default (`POST → 201`, others → `200`). The caller controls `201` vs `200` vs `204` via standard NestJS decorators. `status` accepts numeric codes plus the OpenAPI 3.1 range keys (`'1XX'`…`'5XX'`) and `'default'` (sugar for the resolved method default).
|
|
44
44
|
- **I/O suffix only when needed** — `<Id>Output` is only emitted when the input and output JSON Schemas actually differ. `nestjs-zod` always emitted `_Output`.
|
|
45
|
-
- **OpenAPI 3.1 and 3.2** — no `3.0` fallback. Pick with `DocumentBuilder.setOpenAPIVersion('3.2.0')`; 3.2 is what makes `QUERY` and WebDAV routes conformant,
|
|
45
|
+
- **OpenAPI 3.1 and 3.2** — no `3.0` fallback. Pick with `DocumentBuilder.setOpenAPIVersion('3.2.0')`; 3.2 is what makes `QUERY` and WebDAV routes conformant, what lets a streamed response say `itemSchema` instead of overstating the whole body, what emits Response Object `summary`, and what collapses a named query DTO to `in: querystring`. `$ref`s emit to the final location; `cleanupOpenApiDoc` is unnecessary.
|
|
46
46
|
- **Validation-failure logging out of the box** — `nestjs-zod` has none.
|
|
47
47
|
- **Customizable serialization exception** — both `ZodValidationPipe` and `ZodSerializerInterceptor` accept a factory. `nestjs-zod` only customized the input side.
|
|
48
48
|
- **DTO discriminator** — `Symbol.for('zod-nest.dto')` (cross-realm safe), not `MyDto.isZodDto`.
|
|
@@ -186,7 +186,7 @@ The decorator set: `@ZodBody`, `@ZodQuery`, `@ZodHeaders`, `@ZodCookies`. All ar
|
|
|
186
186
|
|
|
187
187
|
See [`docs/recipes/intersection-with-union.md`](docs/recipes/intersection-with-union.md) for the full pattern.
|
|
188
188
|
|
|
189
|
-
Named query objects (both `@Query() dto` and `@ZodQuery`)
|
|
189
|
+
Named query objects (both `@Query() dto` and `@ZodQuery`) collapse to a single `in: querystring` parameter under OpenAPI 3.2 — the field 3.2 added for exactly this — and expand to one parameter per field under 3.1. Nothing changes on the wire either way. The deprecated `queryParamStyle` / `@ZodQuery({ ref })` flags override the default; see [`docs/swagger-integration.md → Query parameter style`](docs/swagger-integration.md#query-parameter-style).
|
|
190
190
|
|
|
191
191
|
### I/O suffix rules
|
|
192
192
|
|
package/dist/index.d.mts
CHANGED
|
@@ -300,10 +300,12 @@ type ResponseStatusWildcard = '1XX' | '2XX' | '3XX' | '4XX' | '5XX';
|
|
|
300
300
|
* Description payload accepted by `@ZodResponse(...)` and passed through to
|
|
301
301
|
* `applyZodNest`'s `@ApiResponse(...)` emitter. String form is shorthand for
|
|
302
302
|
* `{ description }`; the object form lets users declare OpenAPI response
|
|
303
|
-
* `headers` / `links` alongside the description.
|
|
303
|
+
* `summary` / `headers` / `links` alongside the description.
|
|
304
304
|
*/
|
|
305
305
|
type ZodResponseDescription = string | {
|
|
306
306
|
description: string;
|
|
307
|
+
/** 3.2-only. `applyZodNest` drops it, with a warning, when emitting 3.1. */
|
|
308
|
+
summary?: string;
|
|
307
309
|
headers?: Record<string, unknown>;
|
|
308
310
|
links?: Record<string, unknown>;
|
|
309
311
|
};
|
|
@@ -601,16 +603,19 @@ interface ZodQueryOptions {
|
|
|
601
603
|
/** Registry to register into. Defaults to `defaultRegistry`. */
|
|
602
604
|
readonly registry?: ZodNestRegistry;
|
|
603
605
|
/**
|
|
604
|
-
* Override how this query DTO is represented
|
|
605
|
-
*
|
|
606
|
+
* Override how this query DTO is represented, taking precedence over
|
|
607
|
+
* `applyZodNest`'s `queryParamStyle` and the target version:
|
|
606
608
|
*
|
|
607
|
-
* - `true` —
|
|
608
|
-
* `
|
|
609
|
+
* - `true` — collapse to one parameter carrying the whole schema
|
|
610
|
+
* (`in: 'querystring'` under 3.2, `style: 'form'` under 3.1).
|
|
609
611
|
* - `false` — one parameter per top-level property.
|
|
610
|
-
* - unset — follow
|
|
612
|
+
* - unset — follow `queryParamStyle`, then the version (3.2 collapses).
|
|
611
613
|
*
|
|
612
|
-
*
|
|
614
|
+
* Collapsing needs a named schema to reference: `ref: true` on an anonymous
|
|
613
615
|
* schema (no `.meta({ id })` and no `id` option) throws `ZodNestError`.
|
|
616
|
+
*
|
|
617
|
+
* @deprecated Removed in the next major, where 3.1 always expands and 3.2
|
|
618
|
+
* always collapses. Under 3.2 an explicit value warns.
|
|
614
619
|
*/
|
|
615
620
|
readonly ref?: boolean;
|
|
616
621
|
}
|
|
@@ -729,15 +734,14 @@ declare class ZodNestModule {
|
|
|
729
734
|
/**
|
|
730
735
|
* How a named `@Query()` / `@ZodQuery` DTO is represented in the OpenAPI doc:
|
|
731
736
|
*
|
|
732
|
-
* - `'expand'`
|
|
733
|
-
*
|
|
734
|
-
*
|
|
735
|
-
*
|
|
736
|
-
*
|
|
737
|
-
* document representation collapses to the shared component.
|
|
737
|
+
* - `'expand'` — one parameter per top-level property of the DTO schema.
|
|
738
|
+
* - `'ref'` — collapse to a single parameter carrying the whole schema.
|
|
739
|
+
*
|
|
740
|
+
* Query-only: path / header / cookie markers always expand, since collapsing
|
|
741
|
+
* an object into one parameter is a query serialization.
|
|
738
742
|
*
|
|
739
|
-
*
|
|
740
|
-
*
|
|
743
|
+
* @deprecated Removed in the next major. 3.2 collapses named query DTOs to
|
|
744
|
+
* `in: 'querystring'` by default, which is what this option approximated.
|
|
741
745
|
*/
|
|
742
746
|
type QueryParamStyle = 'expand' | 'ref';
|
|
743
747
|
|
|
@@ -757,17 +761,17 @@ interface ApplyZodNestOptions {
|
|
|
757
761
|
*/
|
|
758
762
|
strict?: boolean;
|
|
759
763
|
/**
|
|
760
|
-
*
|
|
761
|
-
*
|
|
764
|
+
* Overrides the version-derived default for named `@Query()` / `@ZodQuery`
|
|
765
|
+
* DTOs: `'expand'` for one parameter per property, `'ref'` to collapse to a
|
|
766
|
+
* single parameter carrying the whole schema.
|
|
762
767
|
*
|
|
763
|
-
*
|
|
764
|
-
* -
|
|
765
|
-
*
|
|
766
|
-
* format is unchanged; only the spec representation collapses to the
|
|
767
|
-
* shared component. Note: Swagger UI renders the two forms differently.
|
|
768
|
+
* Left unset, 3.2 collapses (as `in: 'querystring'`) and 3.1 expands.
|
|
769
|
+
* Query-only — path / header / cookie DTOs always expand — and a per-handler
|
|
770
|
+
* `@ZodQuery({ ref })` takes precedence.
|
|
768
771
|
*
|
|
769
|
-
*
|
|
770
|
-
*
|
|
772
|
+
* @deprecated Removed in the next major, where 3.1 always expands and 3.2
|
|
773
|
+
* always collapses. This option existed because 3.1 could not express a
|
|
774
|
+
* whole-query-string schema; 3.2's `querystring` can.
|
|
771
775
|
*/
|
|
772
776
|
queryParamStyle?: QueryParamStyle;
|
|
773
777
|
/**
|
|
@@ -793,9 +797,9 @@ interface ApplyZodNestOptions {
|
|
|
793
797
|
* keyed by the marker's `dtoId` (renaming as needed).
|
|
794
798
|
* - Every `@Query()` / `@Param()` / `@Headers()` / `@Cookie()` marker
|
|
795
799
|
* parameter is expanded into one parameter per top-level property of the
|
|
796
|
-
* DTO's schema (`expandParamMarkers`) — except `@Query()` DTOs under
|
|
797
|
-
*
|
|
798
|
-
*
|
|
800
|
+
* DTO's schema (`expandParamMarkers`) — except named `@Query()` DTOs under
|
|
801
|
+
* 3.2, which collapse to a single `in: 'querystring'` parameter, and their
|
|
802
|
+
* 3.1 equivalent under `queryParamStyle: 'ref'`. The synthetic
|
|
799
803
|
* `components.schemas.Object` that `@nestjs/swagger` materialises for the
|
|
800
804
|
* marker placeholder is pruned when it has no remaining referrers.
|
|
801
805
|
* - The I/O suffix truth table is applied — equal input/output bodies collapse
|
|
@@ -818,6 +822,11 @@ interface ApplyZodNestOptions {
|
|
|
818
822
|
* `additionalOperations`, the only place that version accepts them, and
|
|
819
823
|
* rewrites `schema` to `itemSchema` on sequential media types (SSE, NDJSON, …)
|
|
820
824
|
* so a streamed body documents one item rather than the whole sequence.
|
|
825
|
+
* - Response Object `summary` survives only under 3.2; emitting 3.1 drops each
|
|
826
|
+
* one with a warning naming the operation, since 3.1 forbids the field.
|
|
827
|
+
* - Under 3.2 a named query DTO collapses to `in: 'querystring'`, degrading to
|
|
828
|
+
* per-property expansion (with a warning) where that version's coexistence
|
|
829
|
+
* rules forbid it — a sibling `in: 'query'` parameter, or a second candidate.
|
|
821
830
|
*
|
|
822
831
|
* Composable with other doc-transform passes — apply other mutations before
|
|
823
832
|
* or after this function.
|
package/dist/index.d.ts
CHANGED
|
@@ -300,10 +300,12 @@ type ResponseStatusWildcard = '1XX' | '2XX' | '3XX' | '4XX' | '5XX';
|
|
|
300
300
|
* Description payload accepted by `@ZodResponse(...)` and passed through to
|
|
301
301
|
* `applyZodNest`'s `@ApiResponse(...)` emitter. String form is shorthand for
|
|
302
302
|
* `{ description }`; the object form lets users declare OpenAPI response
|
|
303
|
-
* `headers` / `links` alongside the description.
|
|
303
|
+
* `summary` / `headers` / `links` alongside the description.
|
|
304
304
|
*/
|
|
305
305
|
type ZodResponseDescription = string | {
|
|
306
306
|
description: string;
|
|
307
|
+
/** 3.2-only. `applyZodNest` drops it, with a warning, when emitting 3.1. */
|
|
308
|
+
summary?: string;
|
|
307
309
|
headers?: Record<string, unknown>;
|
|
308
310
|
links?: Record<string, unknown>;
|
|
309
311
|
};
|
|
@@ -601,16 +603,19 @@ interface ZodQueryOptions {
|
|
|
601
603
|
/** Registry to register into. Defaults to `defaultRegistry`. */
|
|
602
604
|
readonly registry?: ZodNestRegistry;
|
|
603
605
|
/**
|
|
604
|
-
* Override how this query DTO is represented
|
|
605
|
-
*
|
|
606
|
+
* Override how this query DTO is represented, taking precedence over
|
|
607
|
+
* `applyZodNest`'s `queryParamStyle` and the target version:
|
|
606
608
|
*
|
|
607
|
-
* - `true` —
|
|
608
|
-
* `
|
|
609
|
+
* - `true` — collapse to one parameter carrying the whole schema
|
|
610
|
+
* (`in: 'querystring'` under 3.2, `style: 'form'` under 3.1).
|
|
609
611
|
* - `false` — one parameter per top-level property.
|
|
610
|
-
* - unset — follow
|
|
612
|
+
* - unset — follow `queryParamStyle`, then the version (3.2 collapses).
|
|
611
613
|
*
|
|
612
|
-
*
|
|
614
|
+
* Collapsing needs a named schema to reference: `ref: true` on an anonymous
|
|
613
615
|
* schema (no `.meta({ id })` and no `id` option) throws `ZodNestError`.
|
|
616
|
+
*
|
|
617
|
+
* @deprecated Removed in the next major, where 3.1 always expands and 3.2
|
|
618
|
+
* always collapses. Under 3.2 an explicit value warns.
|
|
614
619
|
*/
|
|
615
620
|
readonly ref?: boolean;
|
|
616
621
|
}
|
|
@@ -729,15 +734,14 @@ declare class ZodNestModule {
|
|
|
729
734
|
/**
|
|
730
735
|
* How a named `@Query()` / `@ZodQuery` DTO is represented in the OpenAPI doc:
|
|
731
736
|
*
|
|
732
|
-
* - `'expand'`
|
|
733
|
-
*
|
|
734
|
-
*
|
|
735
|
-
*
|
|
736
|
-
*
|
|
737
|
-
* document representation collapses to the shared component.
|
|
737
|
+
* - `'expand'` — one parameter per top-level property of the DTO schema.
|
|
738
|
+
* - `'ref'` — collapse to a single parameter carrying the whole schema.
|
|
739
|
+
*
|
|
740
|
+
* Query-only: path / header / cookie markers always expand, since collapsing
|
|
741
|
+
* an object into one parameter is a query serialization.
|
|
738
742
|
*
|
|
739
|
-
*
|
|
740
|
-
*
|
|
743
|
+
* @deprecated Removed in the next major. 3.2 collapses named query DTOs to
|
|
744
|
+
* `in: 'querystring'` by default, which is what this option approximated.
|
|
741
745
|
*/
|
|
742
746
|
type QueryParamStyle = 'expand' | 'ref';
|
|
743
747
|
|
|
@@ -757,17 +761,17 @@ interface ApplyZodNestOptions {
|
|
|
757
761
|
*/
|
|
758
762
|
strict?: boolean;
|
|
759
763
|
/**
|
|
760
|
-
*
|
|
761
|
-
*
|
|
764
|
+
* Overrides the version-derived default for named `@Query()` / `@ZodQuery`
|
|
765
|
+
* DTOs: `'expand'` for one parameter per property, `'ref'` to collapse to a
|
|
766
|
+
* single parameter carrying the whole schema.
|
|
762
767
|
*
|
|
763
|
-
*
|
|
764
|
-
* -
|
|
765
|
-
*
|
|
766
|
-
* format is unchanged; only the spec representation collapses to the
|
|
767
|
-
* shared component. Note: Swagger UI renders the two forms differently.
|
|
768
|
+
* Left unset, 3.2 collapses (as `in: 'querystring'`) and 3.1 expands.
|
|
769
|
+
* Query-only — path / header / cookie DTOs always expand — and a per-handler
|
|
770
|
+
* `@ZodQuery({ ref })` takes precedence.
|
|
768
771
|
*
|
|
769
|
-
*
|
|
770
|
-
*
|
|
772
|
+
* @deprecated Removed in the next major, where 3.1 always expands and 3.2
|
|
773
|
+
* always collapses. This option existed because 3.1 could not express a
|
|
774
|
+
* whole-query-string schema; 3.2's `querystring` can.
|
|
771
775
|
*/
|
|
772
776
|
queryParamStyle?: QueryParamStyle;
|
|
773
777
|
/**
|
|
@@ -793,9 +797,9 @@ interface ApplyZodNestOptions {
|
|
|
793
797
|
* keyed by the marker's `dtoId` (renaming as needed).
|
|
794
798
|
* - Every `@Query()` / `@Param()` / `@Headers()` / `@Cookie()` marker
|
|
795
799
|
* parameter is expanded into one parameter per top-level property of the
|
|
796
|
-
* DTO's schema (`expandParamMarkers`) — except `@Query()` DTOs under
|
|
797
|
-
*
|
|
798
|
-
*
|
|
800
|
+
* DTO's schema (`expandParamMarkers`) — except named `@Query()` DTOs under
|
|
801
|
+
* 3.2, which collapse to a single `in: 'querystring'` parameter, and their
|
|
802
|
+
* 3.1 equivalent under `queryParamStyle: 'ref'`. The synthetic
|
|
799
803
|
* `components.schemas.Object` that `@nestjs/swagger` materialises for the
|
|
800
804
|
* marker placeholder is pruned when it has no remaining referrers.
|
|
801
805
|
* - The I/O suffix truth table is applied — equal input/output bodies collapse
|
|
@@ -818,6 +822,11 @@ interface ApplyZodNestOptions {
|
|
|
818
822
|
* `additionalOperations`, the only place that version accepts them, and
|
|
819
823
|
* rewrites `schema` to `itemSchema` on sequential media types (SSE, NDJSON, …)
|
|
820
824
|
* so a streamed body documents one item rather than the whole sequence.
|
|
825
|
+
* - Response Object `summary` survives only under 3.2; emitting 3.1 drops each
|
|
826
|
+
* one with a warning naming the operation, since 3.1 forbids the field.
|
|
827
|
+
* - Under 3.2 a named query DTO collapses to `in: 'querystring'`, degrading to
|
|
828
|
+
* per-property expansion (with a warning) where that version's coexistence
|
|
829
|
+
* rules forbid it — a sibling `in: 'query'` parameter, or a second candidate.
|
|
821
830
|
*
|
|
822
831
|
* Composable with other doc-transform passes — apply other mutations before
|
|
823
832
|
* or after this function.
|