feat: add typescriptDefinitionRefiner to TemplateContext options#278
Open
senecolas wants to merge 1 commit intoastahmer:mainfrom
Open
feat: add typescriptDefinitionRefiner to TemplateContext options#278senecolas wants to merge 1 commit intoastahmer:mainfrom
senecolas wants to merge 1 commit intoastahmer:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Owner
|
thank you, this looks great ! 🙏 could you add a test with your example from the PR description ? |
senecolas
commented
Mar 29, 2024
|
|
||
| const base = t.type(inheritedMeta.name, doWrapReadOnly(objectType)); | ||
| if (!isPartial) return base; | ||
| if (!isPartial) return t.type(inheritedMeta.name, doWrapReadOnly(objectType)); |
Contributor
Author
There was a problem hiding this comment.
This adjustment was necessary due to an unforeseen issue where t.type caused modifications to the generated types (even when isPartial is true), leading to bugs when attempting to modify the Tanu object after that.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
typescriptDefinitionRefinerFunctionalityOverview
Following the discussion in PR #275 , this pull request introduces the
typescriptDefinitionRefinerfunction, allowing for the customization of TypeScript type definitions generated by theopenapi-zod-clienttool. This functionality supports all type description customization needs, including the ability to add JSDoc comments based on OpenAPI schema properties.Functionality
The
typescriptDefinitionRefinerfunction is called within the recursivegetTypescriptFromOpenApibefore 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
typescriptDefinitionRefineroption to add JSDoc comments to the generated TypeScript types with the help of agenerateJSDocArrayfunction. 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.