feat: add typescriptDefinitionRefiner to TemplateContext options #278
+18
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implement
typescriptDefinitionRefiner
FunctionalityOverview
Following the discussion in PR #275 , this pull request introduces the
typescriptDefinitionRefiner
function, allowing for the customization of TypeScript type definitions generated by theopenapi-zod-client
tool. This functionality supports all type description customization needs, including the ability to add JSDoc comments based on OpenAPI schema properties.Functionality
The
typescriptDefinitionRefiner
function is called within the recursivegetTypescriptFromOpenApi
before returning each Tanu type result. It enables users to modify the TypeScript definitions on the fly, providing a flexible approach to enhance the generated types, such as by adding comprehensive JSDoc comments.Function signature
Example Usage
Below is an example demonstrating how to use the
typescriptDefinitionRefiner
option to add JSDoc comments to the generated TypeScript types with the help of agenerateJSDocArray
function. This example showcases how to dynamically generate JSDoc comments based on the OpenAPI schema, including descriptions, examples, deprecation notices, and more:This approach allows for significant flexibility in customizing the generated types, addressing the original concern about increasing configuration complexity and maintenance overhead.
Request for Comments
I welcome feedback on this feature, including suggestions for improvement or concerns about potential impacts. Please feel free to leave comments or questions in this pull request.
Thank you for considering this contribution to this project.