transit-kit 0.6.2 → 0.6.3

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.
@@ -1,38 +1,6 @@
1
1
  import z from "zod";
2
2
  import { hasValue } from "../server/utils/typeGuards";
3
3
  import { isJsonResponseSchema } from "../server/handlers/api/responses/jsonResponse";
4
- function prepareForJsonSchema(schema) {
5
- // 1. Handle Dates (The Core Issue)
6
- if (schema instanceof z.ZodDate) {
7
- return z.string().datetime().describe("ISO 8601 date-time string");
8
- }
9
- // 2. Handle Objects
10
- if (schema instanceof z.ZodObject) {
11
- const newShape = {};
12
- for (const key in schema.shape) {
13
- newShape[key] = prepareForJsonSchema(schema.shape[key]);
14
- }
15
- return z.object(newShape);
16
- }
17
- // 3. Handle Arrays
18
- if (schema instanceof z.ZodArray) {
19
- return z.array(prepareForJsonSchema(schema.element));
20
- }
21
- // 4. Handle Optionals
22
- if (schema instanceof z.ZodOptional) {
23
- return prepareForJsonSchema(schema.unwrap()).optional();
24
- }
25
- // 5. Handle Nullables
26
- if (schema instanceof z.ZodNullable) {
27
- return prepareForJsonSchema(schema.unwrap()).nullable();
28
- }
29
- // 7. Handle Unions
30
- if (schema instanceof z.ZodUnion) {
31
- return z.union(schema.options.map((option) => prepareForJsonSchema(option)));
32
- }
33
- // Return as-is if no transformation is needed
34
- return schema;
35
- }
36
4
  function extractPathAndParameters(path) {
37
5
  const parameters = path.match(/:([a-zA-Z0-9_]+)/g)?.map((param) => {
38
6
  return {
@@ -49,7 +17,7 @@ function extractPathAndParameters(path) {
49
17
  return { openApiPath, parameters };
50
18
  }
51
19
  function extractQueryParameters(querySchema) {
52
- const querySchemaObject = z.toJSONSchema(prepareForJsonSchema(querySchema));
20
+ const querySchemaObject = z.toJSONSchema(querySchema, { io: "input" });
53
21
  if (querySchemaObject.properties) {
54
22
  return Object.entries(querySchemaObject.properties).map(([name, schema]) => ({
55
23
  name: name,
@@ -95,7 +63,9 @@ function translateToOpenAPIPathItem(definition) {
95
63
  required: true,
96
64
  content: {
97
65
  "application/json": {
98
- schema: z.toJSONSchema(prepareForJsonSchema(requestBodySchema)), // Type assertion
66
+ schema: z.toJSONSchema(requestBodySchema, {
67
+ io: "input",
68
+ }), // Type assertion
99
69
  },
100
70
  },
101
71
  },
@@ -106,7 +76,7 @@ function translateToOpenAPIPathItem(definition) {
106
76
  .map(([statusCode, responseDef]) => {
107
77
  if (isJsonResponseSchema(responseDef)) {
108
78
  const zodSchema = responseDef.dataSchema;
109
- const responseSchema = z.toJSONSchema(prepareForJsonSchema(zodSchema));
79
+ const responseSchema = z.toJSONSchema(zodSchema, { io: "input" });
110
80
  return {
111
81
  [statusCode]: {
112
82
  description: `Response for status code ${statusCode}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "transit-kit",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "A declarative TypeScript framework for building type-safe Express.js APIs with automatic OpenAPI generation",
5
5
  "keywords": [
6
6
  "express",