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

Flag to skip types that are not supported #157

Open
martitv opened this issue Sep 11, 2023 · 7 comments
Open

Flag to skip types that are not supported #157

martitv opened this issue Sep 11, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@martitv
Copy link

martitv commented Sep 11, 2023

Feature description

I am trying to generate zod schemas from the Api generated by swagger-typescript-api. But this API contains a bunch of unsupported types related to the API it self which i don't really need zod-schemas for. Like Interface with generics etc.

I would like to be able to give a flag to the ts-to-zod command so the script doesn't exit when it find an unsupported type, e.g:

npx ts-to-zod src/myApi.ts src/myZodApi.ts --skip-unsupported

Input

export type QueryParamsType = Record<string | number, any>;

Output

// nothing
@baloodevil
Copy link

Or I would like support for interfaces with generics.

@martitv
Copy link
Author

martitv commented Sep 13, 2023

This would make the library much more compatible with other code generator libraries as very many of them use generics and other unsupported types for their own typings. Plzplz!!

@martitv
Copy link
Author

martitv commented Sep 18, 2023

I found a way to get around this using the --modular option of swagger-typescript-api. This put the contracts into a separate file which allowed me to generate schemas without errors

@martitv martitv closed this as completed Sep 18, 2023
@martitv martitv reopened this Jan 22, 2024
@martitv
Copy link
Author

martitv commented Jan 22, 2024

This has again become an issue when introducing discriminators in the swagger contract. The typescript types are then created with generics.

Please add an option to not fail the generation when an error occurs! --skip-unsupported or something.

@schiller-manuel
Copy link
Collaborator

Can you create a PR that implements this?

@tvillaren tvillaren added the enhancement New feature or request label Feb 28, 2024
@jbogil
Copy link

jbogil commented Apr 16, 2024

Also in need of a skip flag but do not have the bandwidth to create a PR for this.

@tvillaren
Copy link
Collaborator

tvillaren commented Apr 16, 2024

Hello,

Can you provide an example of a few failing cases (besides generic types)?

The first example provided

export type QueryParamsType = Record<string | number, any>;

currently generates

// Generated by ts-to-zod
import { z } from "zod";

export const queryParamsTypeSchema = z.record(
  z.union([z.string(), z.number()]),
  z.any()
);

so I see no error to "skip" in that specific example.

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

No branches or pull requests

5 participants