Open vlanemcev opened 1 month ago
@vlanemcev I added the following pr: https://github.com/kubb-labs/kubb/pull/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
.
@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!
@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.
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:
And I want to have override the type definition that will be generated for this type
Generated
. For example, I wantfieldA
to be astring
and not anumber | string
.As I know, the Kubb already has this possibility for Zod plugin by mapping field inside plugin configurator, something like this:
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.