@bram-dc/fastify-type-provider-zod 4.0.2 → 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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/src/core.d.ts +5 -4
- package/dist/src/core.js +26 -19
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { type ZodTypeProvider, type FastifyPluginAsyncZod, type FastifyPluginCallbackZod, type ZodSerializerCompilerOptions, jsonSchemaTransform, createJsonSchemaTransform, jsonSchemaTransformObject, serializerCompiler, validatorCompiler, createSerializerCompiler, } from './src/core';
|
|
1
|
+
export { type ZodTypeProvider, type FastifyPluginAsyncZod, type FastifyPluginCallbackZod, type ZodSerializerCompilerOptions, jsonSchemaTransform, createJsonSchemaTransform, jsonSchemaTransformObject, createJsonSchemaTransformObject, serializerCompiler, validatorCompiler, createSerializerCompiler, } from './src/core';
|
|
2
2
|
export { type ZodFastifySchemaValidationError, ResponseSerializationError, InvalidSchemaError, hasZodFastifySchemaValidationErrors, isResponseSerializationError, } from './src/errors';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isResponseSerializationError = exports.hasZodFastifySchemaValidationErrors = exports.InvalidSchemaError = exports.ResponseSerializationError = exports.createSerializerCompiler = exports.validatorCompiler = exports.serializerCompiler = exports.jsonSchemaTransformObject = exports.createJsonSchemaTransform = exports.jsonSchemaTransform = void 0;
|
|
3
|
+
exports.isResponseSerializationError = exports.hasZodFastifySchemaValidationErrors = exports.InvalidSchemaError = exports.ResponseSerializationError = exports.createSerializerCompiler = exports.validatorCompiler = exports.serializerCompiler = exports.createJsonSchemaTransformObject = exports.jsonSchemaTransformObject = exports.createJsonSchemaTransform = exports.jsonSchemaTransform = void 0;
|
|
4
4
|
var core_1 = require("./src/core");
|
|
5
5
|
Object.defineProperty(exports, "jsonSchemaTransform", { enumerable: true, get: function () { return core_1.jsonSchemaTransform; } });
|
|
6
6
|
Object.defineProperty(exports, "createJsonSchemaTransform", { enumerable: true, get: function () { return core_1.createJsonSchemaTransform; } });
|
|
7
7
|
Object.defineProperty(exports, "jsonSchemaTransformObject", { enumerable: true, get: function () { return core_1.jsonSchemaTransformObject; } });
|
|
8
|
+
Object.defineProperty(exports, "createJsonSchemaTransformObject", { enumerable: true, get: function () { return core_1.createJsonSchemaTransformObject; } });
|
|
8
9
|
Object.defineProperty(exports, "serializerCompiler", { enumerable: true, get: function () { return core_1.serializerCompiler; } });
|
|
9
10
|
Object.defineProperty(exports, "validatorCompiler", { enumerable: true, get: function () { return core_1.validatorCompiler; } });
|
|
10
11
|
Object.defineProperty(exports, "createSerializerCompiler", { enumerable: true, get: function () { return core_1.createSerializerCompiler; } });
|
package/dist/src/core.d.ts
CHANGED
|
@@ -10,14 +10,15 @@ interface Schema extends FastifySchema {
|
|
|
10
10
|
hide?: boolean;
|
|
11
11
|
}
|
|
12
12
|
type CreateJsonSchemaTransformOptions = {
|
|
13
|
-
skipList
|
|
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
|
|
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
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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,
|
|
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) {
|