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

Override some field in specific type definition that was generated #1041

Closed
vlanemcev opened this issue Jun 17, 2024 · 3 comments
Closed

Override some field in specific type definition that was generated #1041

vlanemcev opened this issue Jun 17, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@vlanemcev
Copy link

What is the problem this feature would solve?

Sometimes it happens that the swagger / open api schemes that are generated by the backend do not quite correspond to what the backend actually sends as a response.
Because of this, sometimes you need to help the typescript plugin correctly define/override types for models/operations, etc.
Changing the schema file itself is not an option because it itself is automatically generated on the backend side and is dynamically generated.

For example, after running Kubb generation with pluginTs I take this type:

type Generated = {
 fieldA: number | string;
 fieldB: string;
}

And I want to have override the type definition that will be generated for this type Generated.
For example, I want fieldA to be a string and not a number | string.

As I know, the Kubb already has this possibility for Zod plugin by mapping field inside plugin configurator, something like this:

mapper: {
    balance_history: "z.array(z.tuple([z.number(), z.number()]))", // we're overriding the resulted schema
}

According to my feeling and already using generation in projects, I can say that this is the most requested feature.

External documents/projects?

No response

What is the feature you are proposing to solve the problem?

Add some mappers (similar to the Zod plugin) to be able to override generated typescript definitions.

What alternatives have you considered?

I have not found any alternative solutions to solve this other than defining the type on my side and using it.

@vlanemcev vlanemcev added the enhancement New feature or request label Jun 17, 2024
@stijnvanhulle
Copy link
Collaborator

@vlanemcev I added the following pr: #1075. The big difference with the Zod and Faker plugin is that you need to use the Factory functionality of TypeScript instead of returning string.

@vlanemcev
Copy link
Author

@stijnvanhulle Nice, thanks so much for this functionality! I'll try it in my project.

Btw, could we update the doc regarding it? Because using mappers is unspecified there..
Thanks!

@stijnvanhulle
Copy link
Collaborator

@vlanemcev Hi, that is on purpose right now because the API is still incomplete. I will probably make some changes before v3 and then make it an official feature.

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

2 participants