sachinraja / trpc-playground

playground for running tRPC queries in the browser
MIT License
281 stars 19 forks source link

Input descriptions do not show up in docs #37

Closed roninjin10 closed 1 year ago

roninjin10 commented 1 year ago

If I describe an input like this:

this.trpc.procedure
    .input(
      z
        .object({
          address: z.string.describe('Any valid ethereum address'),
        })
        .describe(
          'returns nft metadata',
        ),
    )

The address description shows up in the docs but not the object description. (see metadata endpoint) image

MatsDK commented 1 year ago

This seems to be an issue with zod-to-ts. It seems like it is only rendering descriptions on ZodObject fields (https://github.com/sachinraja/zod-to-ts/blob/main/src/index.ts#L142-#L144).

roninjin10 commented 1 year ago

@MatsDK looked into it and the issue is not zod-to-ts. We are expected to be passing in the description here

image

The description comes from a util method that merges inputs (TIL trpc can define and merge more than 1 input object) . The description never gets copied over. I put up a pr adding it here: https://github.com/sachinraja/trpc-playground/pull/38

roninjin10 commented 1 year ago

Update: Actually my theory doesn't make sense because I only use 1 input so that should be getting copied over

image

I have time to continue to debug later this week

MatsDK commented 1 year ago

I created the printTypeForDocs function to solve this problem. After testing, it seems like it is working. The createTypeAlias is adding the description of the input above the the type declaration. image This change is not published yet (commit).

MatsDK commented 1 year ago

I don't know how we should handle multiple inputParser. What if there are multiple descriptions? Maybe something like #38 is necessary in that case.

roninjin10 commented 1 year ago

ah yea good point about many. The code I wrote only the last one is available. The cleanest way to do it might be to hackily concat them together so make it look like

/ description 1 / propertyOnOne: string anotherPropertyOnOne: number / description 2 / propertyOnTwo: Date anotherPropertyOnTwo: boolean

roninjin10 commented 1 year ago

Another option would be to make them a zod.union and see what zod prints

sachinraja commented 1 year ago

published in v1.0.3, please open another issue if you want this for multiple input parsers