• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RobinTail / express-zod-api / 11626186545

01 Nov 2024 07:52AM UTC coverage: 99.95% (-0.05%) from 100.0%
11626186545

Pull #2135

github

web-flow
Merge 8ac8f8981 into 2f2fdb358
Pull Request #2135: Exp: Switch coverage provider to v8

1133 of 1154 branches covered (98.18%)

11 of 12 new or added lines in 3 files covered. (91.67%)

2 existing lines in 2 files now uncovered.

3985 of 3987 relevant lines covered (99.95%)

379.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.15
/src/metadata.ts
1
import { combinations } from "./common-helpers";
6✔
2
import { z } from "zod";
3
import { clone, mergeDeepRight } from "ramda";
4

5
export const metaSymbol = Symbol.for("express-zod-api");
6✔
6

7
export interface Metadata {
8
  examples: unknown[];
9
  /** @override ZodDefault::_def.defaultValue() in depictDefault */
10
  defaultLabel?: string;
11
  brand?: string | number | symbol;
12
}
13

14
/** @link https://github.com/colinhacks/zod/blob/3e4f71e857e75da722bd7e735b6d657a70682df2/src/types.ts#L485 */
15
export const cloneSchema = <T extends z.ZodType>(schema: T) => {
6✔
16
  const copy = schema.describe(schema.description as string);
948✔
17
  copy._def[metaSymbol] = // clone for deep copy, issue #827
948✔
18
    clone(copy._def[metaSymbol]) || ({ examples: [] } satisfies Metadata);
948✔
19
  return copy;
948✔
20
};
948✔
21

22
export const copyMeta = <A extends z.ZodTypeAny, B extends z.ZodTypeAny>(
6✔
23
  src: A,
1,134✔
24
  dest: B,
1,134✔
25
): B => {
1,134✔
26
  if (!(metaSymbol in src._def)) {
1,134✔
27
    return dest;
1,014✔
28
  }
1,014✔
29
  const result = cloneSchema(dest);
120✔
30
  result._def[metaSymbol].examples = combinations(
120✔
31
    result._def[metaSymbol].examples,
120✔
32
    src._def[metaSymbol].examples,
120✔
33
    ([destExample, srcExample]) =>
120✔
34
      typeof destExample === "object" && typeof srcExample === "object"
120✔
35
        ? mergeDeepRight({ ...destExample }, { ...srcExample })
120!
UNCOV
36
        : srcExample, // not supposed to be called on non-object schemas
×
37
  );
120✔
38
  return result;
120✔
39
};
120✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc