Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zod-openapi] feature request: Infer example and examples with the type of the schema #219

Open
samhwang opened this issue Aug 19, 2024 · 0 comments

Comments

@samhwang
Copy link

Hi anatine team, I keep running to this problem that I think if this feature is done, it would be a massive help DX-wise.

Currently, the type inferred from the AnatineSchemaObject has the example, examples, properties... all has any types => I lose all of the Intellisense/autocomplete goodness, and when running build/type checks, TypeScript cannot pick up the wrong attribute type.

Example:

import { z } from 'zod'
import { extendApi } from '@anatine/zod-openapi'

const Input = z.object({
  name: z.string(),
  age: z.number(),
})

const InputSchema = extendApi(Input, {
  name: 'input'
  example: {
    // I don't have any autocomplete here.
  }
})

This also leads to another problem when I convert it into a Nest DTO and then build into Swagger doc (like via @anatine/zod-nestjs createZodDto), the generated example also has the wrong attribute name (because TypeScript could not pick up the wrong type structure) => break swagger examples.

perhaps this AnatineSchemaObject type can be converted into a Generic type that takes in the inferred type of the Schema instead of taking in ZodTypeAny ?

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

No branches or pull requests

1 participant