@bram-dc/fastify-type-provider-zod 5.0.0 → 5.0.2

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.
@@ -10,14 +10,15 @@ interface Schema extends FastifySchema {
10
10
  hide?: boolean;
11
11
  }
12
12
  type CreateJsonSchemaTransformOptions = {
13
- skipList: readonly string[];
13
+ skipList?: readonly string[];
14
+ schemaRegistry?: z.core.$ZodJSONSchemaRegistry;
14
15
  };
15
- export declare const createJsonSchemaTransform: ({ skipList, }: CreateJsonSchemaTransformOptions) => SwaggerTransform<Schema>;
16
+ export declare const createJsonSchemaTransform: ({ skipList, schemaRegistry, }: CreateJsonSchemaTransformOptions) => SwaggerTransform<Schema>;
16
17
  export declare const jsonSchemaTransform: SwaggerTransform<Schema>;
17
18
  type CreateJsonSchemaTransformObjectOptions = {
18
- schemaRegistry: z.core.$ZodJSONSchemaRegistry;
19
+ schemaRegistry?: z.core.$ZodJSONSchemaRegistry;
19
20
  };
20
- export declare const createJsonSchemaTransformObject: ({ schemaRegistry }: CreateJsonSchemaTransformObjectOptions) => SwaggerTransformObject;
21
+ export declare const createJsonSchemaTransformObject: ({ schemaRegistry, }: CreateJsonSchemaTransformObjectOptions) => SwaggerTransformObject;
21
22
  export declare const jsonSchemaTransformObject: SwaggerTransformObject;
22
23
  export declare const validatorCompiler: FastifySchemaCompiler<z.ZodTypeAny>;
23
24
  type ReplacerFunction = (this: any, key: string, value: any) => any;
package/dist/src/core.js CHANGED
@@ -12,15 +12,7 @@ const defaultSkipList = [
12
12
  '/documentation/*',
13
13
  '/documentation/static/*',
14
14
  ];
15
- const zodtoJSONSchemaOptions = {
16
- uri: (id) => `#/components/schemas/${id}`,
17
- external: {
18
- registry: zod_1.z.globalRegistry,
19
- uri: (id) => `#/components/schemas/${id}`,
20
- defs: {},
21
- },
22
- };
23
- const createJsonSchemaTransform = ({ skipList, }) => {
15
+ const createJsonSchemaTransform = ({ skipList = defaultSkipList, schemaRegistry = zod_1.z.globalRegistry, }) => {
24
16
  return ({ schema, url }) => {
25
17
  if (!schema) {
26
18
  return {
@@ -38,7 +30,13 @@ const createJsonSchemaTransform = ({ skipList, }) => {
38
30
  for (const prop in zodSchemas) {
39
31
  const zodSchema = zodSchemas[prop];
40
32
  if (zodSchema) {
41
- transformed[prop] = zod_1.z.toJSONSchema(zodSchema, zodtoJSONSchemaOptions);
33
+ transformed[prop] = zod_1.z.toJSONSchema(zodSchema, {
34
+ external: {
35
+ registry: schemaRegistry,
36
+ uri: (id) => `#/components/schemas/${id}`,
37
+ defs: {},
38
+ },
39
+ });
42
40
  }
43
41
  }
44
42
  if (response) {
@@ -47,7 +45,13 @@ const createJsonSchemaTransform = ({ skipList, }) => {
47
45
  for (const prop in response) {
48
46
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
47
  const zodSchema = resolveSchema(response[prop]);
50
- const transformedResponse = zod_1.z.toJSONSchema(zodSchema, zodtoJSONSchemaOptions);
48
+ const transformedResponse = zod_1.z.toJSONSchema(zodSchema, {
49
+ external: {
50
+ registry: schemaRegistry,
51
+ uri: (id) => `#/components/schemas/${id}`,
52
+ defs: {},
53
+ },
54
+ });
51
55
  transformed.response[prop] = transformedResponse;
52
56
  }
53
57
  }
@@ -61,15 +65,20 @@ const createJsonSchemaTransform = ({ skipList, }) => {
61
65
  };
62
66
  };
63
67
  exports.createJsonSchemaTransform = createJsonSchemaTransform;
64
- exports.jsonSchemaTransform = (0, exports.createJsonSchemaTransform)({
65
- skipList: defaultSkipList,
66
- });
67
- const createJsonSchemaTransformObject = ({ schemaRegistry }) => (input) => {
68
+ exports.jsonSchemaTransform = (0, exports.createJsonSchemaTransform)({});
69
+ const createJsonSchemaTransformObject = ({ schemaRegistry = zod_1.z.globalRegistry, }) => (input) => {
68
70
  if ('swaggerObject' in input) {
69
71
  console.warn('This package currently does not support component references for Swagger 2.0');
70
72
  return input.swaggerObject;
71
73
  }
72
- const { schemas } = zod_1.z.toJSONSchema(schemaRegistry, zodtoJSONSchemaOptions);
74
+ const { schemas } = zod_1.z.toJSONSchema(schemaRegistry, {
75
+ uri: (id) => `#/components/schemas/${id}`,
76
+ external: {
77
+ registry: schemaRegistry,
78
+ uri: (id) => `#/components/schemas/${id}`,
79
+ defs: {},
80
+ },
81
+ });
73
82
  return {
74
83
  ...input.openapiObject,
75
84
  components: {
@@ -82,9 +91,7 @@ const createJsonSchemaTransformObject = ({ schemaRegistry }) => (input) => {
82
91
  };
83
92
  };
84
93
  exports.createJsonSchemaTransformObject = createJsonSchemaTransformObject;
85
- exports.jsonSchemaTransformObject = (0, exports.createJsonSchemaTransformObject)({
86
- schemaRegistry: zod_1.z.globalRegistry,
87
- });
94
+ exports.jsonSchemaTransformObject = (0, exports.createJsonSchemaTransformObject)({});
88
95
  const validatorCompiler = ({ schema }) => (data) => {
89
96
  const result = schema.safeParse(data);
90
97
  if (result.error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bram-dc/fastify-type-provider-zod",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
4
4
  "description": "Zod Type Provider for Fastify@5",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",