Skip to content

Conversation

tinglei8
Copy link

@tinglei8 tinglei8 commented Jan 3, 2025

There are 3 fixes in this PR:

Fix 1: Flatten chained function calls.

An example:

import { z } from 'zod';

const TypeEnum = z
  .enum(['Normal', 'Unknown'])
  .describe('Type of the item');

const FindManyInput = z.object({
  options: z
    .object({
      userId: z.string().describe('ID of the current user'),
      type1: TypeEnum.optional().describe('Type 1 of the item')
    })
    .merge({
      z.object({
        type2: TypeEnum.optional().describe('Type 2 of the item')
      })
    })
    .describe('Options to find many items'),
});

Before the fix, references to TypeEnum are not flattened in FindManyInput because it's referenced as parameters of the object() and merge() calls instead of the last describe() call.

After the fix, The TypeEnum schema is properly flattened in all places that reference it.

Fix 2: add tsConfigFilePath to module config.

See issue: #18

Fix 3: Flatten enum name to literal values.

An example:

// types.ts
export enum TypeEnum { Normal = 'Normal', Unknown = 'Unknown' };
// test.ts
import { z } from 'zod';
import { TypeEnum } from './types';

const FindManyInput = z.object({
  options: z
    .object({
      userId: z.string().describe('ID of the current user'),
      type: z.literal(TypeEnum.Normal).describe('Type of the item')
    })
    .describe('Options to find many items'),
});

Before the fix, it generates: type: z.literal(export enum TypeEnum { Normal = 'Normal', Unknown = 'Unknown' }).describe('Type of the item')

After the fix, it generates: type: z.literal('Normal').describe('Type of the item')

Copy link

vercel bot commented Jan 3, 2025

@tinglei8 is attempting to deploy a commit to the Kevin's Projects Team on Vercel.

A member of the Team first needs to authorize it.

@ewrogers
Copy link
Collaborator

I assume this would fix #18 with tsConfig paths not generating schemas? Definitely would like to see this merged if so!

Copy link

vercel bot commented Apr 9, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nestjs-trpc-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 9, 2025 4:36am

@josefmic
Copy link

josefmic commented Jul 7, 2025

Hello, I know there hasn't been any releases in a while and that @KevinEdry said that he's busy but planning on working on this repo - but it has been 6 months and still nothing - does anyone have info about this? Is there a fork of this library, if it has been abandoned? The zod schemas not being flattened is a big issue because it won't allow build without type errors...

@KevinEdry
Copy link
Owner

I've added some maintainers to this library recently so we should see those getting merged pretty soon.

@josefmic
Copy link

josefmic commented Jul 7, 2025

Wow, thank you for the info. This library is amazing and I appreciate your work very much!

@ewrogers
Copy link
Collaborator

ewrogers commented Jul 7, 2025

Hello, I know there hasn't been any releases in a while and that @KevinEdry said that he's busy but planning on working on this repo - but it has been 6 months and still nothing - does anyone have info about this? Is there a fork of this library, if it has been abandoned? The zod schemas not being flattened is a big issue because it won't allow build without type errors...

This is also a big thing for me that I would like to see, so it will be one of the first PRs that I look into getting merged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants