ts-typed-api 0.1.19 → 0.1.21

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.
@@ -41,6 +41,11 @@ function getZodOptions(schema) {
41
41
  function getZodValues(schema) {
42
42
  try {
43
43
  const def = getZodDef(schema);
44
+ // Handle Zod enum entries (both z.enum and z.nativeEnum)
45
+ if (def?.entries && typeof def.entries === 'object') {
46
+ return Object.values(def.entries);
47
+ }
48
+ // Fallback for other structures that might use values array
44
49
  return Array.isArray(def?.values) ? def.values : undefined;
45
50
  }
46
51
  catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-typed-api",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "description": "A lightweight, type-safe RPC library for TypeScript with Zod validation",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -133,6 +133,11 @@ function getZodOptions(schema: ZodTypeAny): any[] | undefined {
133
133
  function getZodValues(schema: ZodTypeAny): any[] | undefined {
134
134
  try {
135
135
  const def = getZodDef(schema);
136
+ // Handle Zod enum entries (both z.enum and z.nativeEnum)
137
+ if (def?.entries && typeof def.entries === 'object') {
138
+ return Object.values(def.entries);
139
+ }
140
+ // Fallback for other structures that might use values array
136
141
  return Array.isArray(def?.values) ? def.values : undefined;
137
142
  } catch {
138
143
  return undefined;
@@ -146,24 +146,20 @@ describe('OpenAPI Specification Generation', () => {
146
146
  expect(statusProperty?.type).toBe('string');
147
147
 
148
148
  // The enum should either have values or be a basic string type (no empty enum arrays)
149
- if (statusProperty?.enum) {
150
- expect(statusProperty.enum.length).toBeGreaterThan(0);
151
- expect(statusProperty.enum).toContain('active');
152
- expect(statusProperty.enum).toContain('inactive');
153
- expect(statusProperty.enum).toContain('pending');
154
- }
149
+ expect(statusProperty.enum.length).toBeGreaterThan(0);
150
+ expect(statusProperty.enum).toContain('active');
151
+ expect(statusProperty.enum).toContain('inactive');
152
+ expect(statusProperty.enum).toContain('pending');
155
153
 
156
154
  const priorityProperty = actualSchema?.properties?.priority;
157
155
  expect(priorityProperty).toBeDefined();
158
156
  expect(priorityProperty?.type).toBe('string');
159
157
 
160
158
  // The enum should either have values or be a basic string type (no empty enum arrays)
161
- if (priorityProperty?.enum) {
162
- expect(priorityProperty.enum.length).toBeGreaterThan(0);
163
- expect(priorityProperty.enum).toContain('low');
164
- expect(priorityProperty.enum).toContain('medium');
165
- expect(priorityProperty.enum).toContain('high');
166
- }
159
+ expect(priorityProperty.enum.length).toBeGreaterThan(0);
160
+ expect(priorityProperty.enum).toContain('low');
161
+ expect(priorityProperty.enum).toContain('medium');
162
+ expect(priorityProperty.enum).toContain('high');
167
163
 
168
164
  // Check response schema
169
165
  const responseSchema = enumEndpoint.post?.responses?.['200']?.content?.['application/json']?.schema;
@@ -188,8 +184,6 @@ describe('OpenAPI Specification Generation', () => {
188
184
  expect(resultProperty?.type).toBe('string');
189
185
 
190
186
  // The enum should either have values or be a basic string type (no empty enum arrays)
191
- if (resultProperty?.enum) {
192
- expect(resultProperty.enum.length).toBeGreaterThan(0);
193
- }
187
+ expect(resultProperty.enum.length).toBeGreaterThan(0);
194
188
  });
195
189
  });