Skip to content

Commit 116405e

Browse files
Bump zod from 3.25.42 to 3.25.46 (#2691)
Bumps [zod](https://github.com/colinhacks/zod) from 3.25.42 to 3.25.45. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/colinhacks/zod/releases">zod's releases</a>.</em></p> <blockquote> <h2>v3.25.45</h2> <h2>Commits:</h2> <ul> <li>dc2c0b0fccd893a08306ccadc8baa821b1b06a5b minor grammar typo fix (<a href="https://redirect.github.com/colinhacks/zod/issues/4584">#4584</a>)</li> <li>6fd3b39ab65970ec7f708e0aa4d0c9e20d9d2050 fix(JSONSchema): add type for enum (<a href="https://redirect.github.com/colinhacks/zod/issues/4577">#4577</a>)</li> <li>6be478b98c6a36895e28ab0d8b214880dc645d88 Fix ZodType assignability issues</li> <li>69ccb67f6d9d264dd26b6ba0bcc6f2ddc90a8fbc 3.25.45</li> </ul> <h2>v3.25.44</h2> <h2>Commits:</h2> <ul> <li>91267823162009488fff03f2a7240b89767e4d7d Update input<!-- raw HTML omitted --> to prevent excessively deep in more cases</li> <li>e2d72afba3378ab81c691bc81c7e96d6f4845e06 Loosen and expand metadata typing (<a href="https://redirect.github.com/colinhacks/zod/issues/4586">#4586</a>)</li> <li>fc69453e625a1b1c1a4523def3e4e60e5f2af8ca 3.25.44</li> </ul> <h2>v3.25.43</h2> <h2>Commits:</h2> <ul> <li>508e3065ca2debf43a2a8c27845ab7c7d4fe3bb0 Fix type inference in ZodMiniType check method (<a href="https://redirect.github.com/colinhacks/zod/issues/4568">#4568</a>)</li> <li>f8fef45cfa813412beecadfbbe9d6df09ac33a86 Ecosystem: Add Express Zod API (<a href="https://redirect.github.com/colinhacks/zod/issues/4579">#4579</a>)</li> <li>289cba3b95e522b9c66611b94c218bcdfe8566b2 Fix type inference in ZodMiniType check method (<a href="https://redirect.github.com/colinhacks/zod/issues/4568">#4568</a>)</li> <li>011623a7daaa4e5215178073e3a0aeb2e760b2a9 Fix dts files</li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/colinhacks/zod/commit/69ccb67f6d9d264dd26b6ba0bcc6f2ddc90a8fbc"><code>69ccb67</code></a> 3.25.45</li> <li><a href="https://github.com/colinhacks/zod/commit/6be478b98c6a36895e28ab0d8b214880dc645d88"><code>6be478b</code></a> Fix ZodType assignability issues</li> <li><a href="https://github.com/colinhacks/zod/commit/6fd3b39ab65970ec7f708e0aa4d0c9e20d9d2050"><code>6fd3b39</code></a> fix(JSONSchema): add type for enum (<a href="https://redirect.github.com/colinhacks/zod/issues/4577">#4577</a>)</li> <li><a href="https://github.com/colinhacks/zod/commit/dc2c0b0fccd893a08306ccadc8baa821b1b06a5b"><code>dc2c0b0</code></a> minor grammar typo fix (<a href="https://redirect.github.com/colinhacks/zod/issues/4584">#4584</a>)</li> <li><a href="https://github.com/colinhacks/zod/commit/fc69453e625a1b1c1a4523def3e4e60e5f2af8ca"><code>fc69453</code></a> 3.25.44</li> <li><a href="https://github.com/colinhacks/zod/commit/e2d72afba3378ab81c691bc81c7e96d6f4845e06"><code>e2d72af</code></a> Loosen and expand metadata typing (<a href="https://redirect.github.com/colinhacks/zod/issues/4586">#4586</a>)</li> <li><a href="https://github.com/colinhacks/zod/commit/91267823162009488fff03f2a7240b89767e4d7d"><code>9126782</code></a> Update input&lt;&gt; and output&lt;&gt; to prevent excessively deep in more cases</li> <li><a href="https://github.com/colinhacks/zod/commit/011623a7daaa4e5215178073e3a0aeb2e760b2a9"><code>011623a</code></a> Fix dts files</li> <li><a href="https://github.com/colinhacks/zod/commit/289cba3b95e522b9c66611b94c218bcdfe8566b2"><code>289cba3</code></a> Fix type inference in ZodMiniType check method (<a href="https://redirect.github.com/colinhacks/zod/issues/4568">#4568</a>)</li> <li><a href="https://github.com/colinhacks/zod/commit/f8fef45cfa813412beecadfbbe9d6df09ac33a86"><code>f8fef45</code></a> Ecosystem: Add Express Zod API (<a href="https://redirect.github.com/colinhacks/zod/issues/4579">#4579</a>)</li> <li>Additional commits viewable in <a href="https://github.com/colinhacks/zod/compare/v3.25.42...v3.25.45">compare view</a></li> </ul> </details> <br /> <details> <summary>Most Recent Ignore Conditions Applied to This Pull Request</summary> | Dependency Name | Ignore Conditions | | --- | --- | | zod | [>= 3.10.1.a, < 3.10.2] | </details> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=zod&package-manager=npm_and_yarn&previous-version=3.25.42&new-version=3.25.45)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new helper to retrieve example values from schemas, improving consistency in how examples are accessed across the library. - **Bug Fixes** - Improved compatibility with recent Zod updates, ensuring restored and updated example handling in schemas. - **Documentation** - Updated changelog with detailed notes on compatibility improvements and restored helpers. - **Tests** - Added comprehensive tests for the new example retrieval helper to ensure correct behavior in various scenarios. - **Chores** - Upgraded Zod dependency to the latest compatible version. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Anna Bocharova <[email protected]>
1 parent 9382e4b commit 116405e

17 files changed

Lines changed: 130 additions & 51 deletions

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
### v24.1.0
66

7-
- Supporting the new `z.templateLiteral()` schema by the `Integration` (client side types generator).
7+
- Supporting the new `z.templateLiteral()` schema by the `Integration` (client side types generator);
8+
- Compatibility improvements due to the recent changes in Zod 4:
9+
- Restoring publicly exposed `getExamples()` helper (with a new signature);
810

911
```ts
1012
// z.templateLiteral(["start", z.number(), "mid", z.boolean(), "end"])

example/endpoints/retrieve-user.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ export const retrieveUserEndpoint = defaultEndpointsFactory
2929
output: z.object({
3030
id: z.int().nonnegative(),
3131
name: z.string(),
32-
features: feature.array(),
32+
/**
33+
* @todo rm .optional() when external bug fixed
34+
* @link https://github.com/colinhacks/zod/issues/4592
35+
*/
36+
features: feature.array().optional(),
3337
}),
3438
handler: async ({ input: { id }, options: { method }, logger }) => {
3539
logger.debug(`Requested id: ${id}, method ${method}`);

example/example.client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type GetV1UserRetrievePositiveVariant1 = {
1717
data: {
1818
id: number;
1919
name: string;
20-
features: Type1[];
20+
features?: Type1[] | undefined;
2121
};
2222
};
2323

example/example.documentation.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ paths:
4646
required:
4747
- id
4848
- name
49-
- features
5049
additionalProperties: false
5150
required:
5251
- status

express-zod-api/src/date-out-schema.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@ import { z } from "zod/v4";
22

33
export const ezDateOutBrand = Symbol("DateOut");
44

5-
export const dateOut = ({
6-
examples,
7-
...rest
8-
}: Parameters<z.ZodString["meta"]>[0] = {}) =>
5+
export const dateOut = (meta: Parameters<z.ZodString["meta"]>[0] = {}) =>
96
z
107
.date()
118
.transform((date) => date.toISOString())
129
.brand(ezDateOutBrand as symbol)
13-
.meta({
14-
...rest,
15-
examples: examples as
16-
| Array<NonNullable<typeof examples>[number] & z.$brand>
17-
| undefined,
18-
});
10+
.meta(meta);

express-zod-api/src/endpoint.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { IOSchema } from "./io-schema";
2222
import { lastResortHandler } from "./last-resort";
2323
import { ActualLogger } from "./logger-helpers";
2424
import { LogicalContainer } from "./logical-container";
25-
import { getBrand } from "./metadata";
25+
import { getBrand, getExamples } from "./metadata";
2626
import { AuxMethod, Method } from "./method";
2727
import { AbstractMiddleware, ExpressMiddleware } from "./middleware";
2828
import { ContentType } from "./content-type";
@@ -86,17 +86,14 @@ export class Endpoint<
8686

8787
/** considered expensive operation, only required for generators */
8888
#ensureOutputExamples = R.once(() => {
89-
const meta = this.#def.outputSchema.meta();
90-
if (meta?.examples?.length) return; // has examples on the output schema, or pull up:
89+
if (getExamples(this.#def.outputSchema).length) return; // has examples on the output schema, or pull up:
9190
if (!isSchema<$ZodObject>(this.#def.outputSchema, "object")) return;
9291
const examples = pullResponseExamples(this.#def.outputSchema as $ZodObject);
9392
if (!examples.length) return;
93+
const current = this.#def.outputSchema.meta();
9494
globalRegistry
9595
.remove(this.#def.outputSchema) // reassign to avoid cloning
96-
.add(this.#def.outputSchema as $ZodObject, {
97-
...meta,
98-
examples,
99-
});
96+
.add(this.#def.outputSchema as $ZodObject, { ...current, examples });
10097
});
10198

10299
constructor(def: {

express-zod-api/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export {
2929
export { testEndpoint, testMiddleware } from "./testing";
3030
export { Integration } from "./integration";
3131
export { EventStreamFactory } from "./sse";
32+
export { getExamples } from "./metadata";
3233

3334
export { ez } from "./proprietary-schemas";
3435

express-zod-api/src/metadata.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { globalRegistry } from "zod/v4";
12
import type { $ZodType } from "zod/v4/core";
23

34
export const metaSymbol = Symbol.for("express-zod-api");
@@ -12,3 +13,17 @@ export const getBrand = (subject: $ZodType) => {
1213
return brand;
1314
return undefined;
1415
};
16+
17+
/**
18+
* @since zod 3.25.44
19+
* @link https://github.com/colinhacks/zod/pull/4586
20+
* */
21+
export const getExamples = (subject: $ZodType): ReadonlyArray<unknown> => {
22+
const { examples, example } = globalRegistry.get(subject) || {};
23+
if (examples) {
24+
return Array.isArray(examples)
25+
? examples
26+
: Object.values(examples).map(({ value }) => value);
27+
}
28+
return example === undefined ? [] : [example];
29+
};

express-zod-api/src/result-handler.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { FlatObject, isObject } from "./common-helpers";
99
import { contentTypes } from "./content-type";
1010
import { IOSchema } from "./io-schema";
1111
import { ActualLogger } from "./logger-helpers";
12+
import { getExamples } from "./metadata";
1213
import {
1314
DiscriminatedResult,
1415
ensureHttpError,
@@ -100,7 +101,7 @@ export const defaultResultHandler = new ResultHandler({
100101
status: z.literal("success"),
101102
data: output,
102103
});
103-
const { examples = [] } = globalRegistry.get(output) || {}; // pulling down:
104+
const examples = getExamples(output); // pulling down:
104105
if (examples.length) {
105106
globalRegistry.add(responseSchema, {
106107
examples: examples.map((data) => ({
@@ -151,9 +152,8 @@ export const arrayResultHandler = new ResultHandler({
151152
output.shape.items instanceof z.ZodArray
152153
? output.shape.items
153154
: z.array(z.any());
154-
const meta = responseSchema.meta();
155-
if (meta?.examples?.length) return responseSchema; // has examples on the items, or pull down:
156-
const examples = (globalRegistry.get(output)?.examples || [])
155+
if (getExamples(responseSchema).length) return responseSchema; // has examples on the items, or pull down:
156+
const examples = getExamples(output)
157157
.filter(
158158
(example): example is { items: unknown[] } =>
159159
isObject(example) &&
@@ -162,9 +162,10 @@ export const arrayResultHandler = new ResultHandler({
162162
)
163163
.map((example) => example.items);
164164
if (examples.length) {
165+
const current = responseSchema.meta();
165166
globalRegistry
166167
.remove(responseSchema) // reassign to avoid cloning
167-
.add(responseSchema, { ...meta, examples });
168+
.add(responseSchema, { ...current, examples });
168169
}
169170
return responseSchema;
170171
},

express-zod-api/src/result-helpers.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Request } from "express";
22
import createHttpError, { HttpError, isHttpError } from "http-errors";
33
import * as R from "ramda";
4-
import { globalRegistry, z } from "zod/v4";
4+
import { z } from "zod/v4";
55
import type { $ZodObject } from "zod/v4/core";
66
import { NormalizedResponse, ResponseVariant } from "./api-response";
77
import {
@@ -12,6 +12,7 @@ import {
1212
} from "./common-helpers";
1313
import { InputValidationError, ResultHandlerError } from "./errors";
1414
import { ActualLogger } from "./logger-helpers";
15+
import { getExamples } from "./metadata";
1516
import type { LazyResult, Result } from "./result-handler";
1617

1718
export type ResultSchema<R extends Result> =
@@ -90,13 +91,15 @@ export const getPublicErrorMessage = (error: HttpError): string =>
9091

9192
/** @see pullRequestExamples */
9293
export const pullResponseExamples = <T extends $ZodObject>(subject: T) =>
93-
Object.entries(subject._zod.def.shape).reduce<Partial<z.output<T>>[]>(
94-
(acc, [key, schema]) => {
95-
const { examples = [] } = globalRegistry.get(schema) || {};
96-
return combinations(acc, examples.map(R.objOf(key)), ([left, right]) => ({
97-
...left,
98-
...right,
99-
}));
100-
},
94+
Object.entries(subject._zod.def.shape).reduce<FlatObject[]>(
95+
(acc, [key, schema]) =>
96+
combinations(
97+
acc,
98+
getExamples(schema).map(R.objOf(key)),
99+
([left, right]) => ({
100+
...left,
101+
...right,
102+
}),
103+
),
101104
[],
102105
);

0 commit comments

Comments
 (0)