Feature Request: Adding validation JSDoc annotations (@minLength, @pattern, etc.) to generated TypeScript properties #2411
kristianjf
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
This sounds great! The current JSDoc generated only provides minimal QoL, and currently doesn’t interop with any tools. So even minor breaking changes would be OK. This is definitely within scope of this tool, and I think it’d be an important addition! We can also bake “generate tsoa-compatible JSDoc comments” into the core tests. I don’t anticipate there would be any breaking changes, but even if there were I think it would be worth it. Thanks for suggesting! I made an issue to track this. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Background
We're using openapi-typescript to generate TypeScript types for use with tsoa (TypeScript OpenAPI) for API validation. We'd like to automatically generate JSDoc validation annotations above properties based on OpenAPI schema validation constraints.
Current Challenge
OpenAPI schemas with validation constraints like:
Currently generate clean TypeScript:
Using
transform
to add JSDoc results in inline comments:But we need tsoa-compatible JSDoc annotations above properties:
Approaches Considered
addJSDocComment
function - Add validation constraints to the existing JSDoc generationtransformProperty
hook - Similar totransform
/postTransform
but exposes the property signature for modificationQuestion
Is extending openapi-typescript's source code (option 1 or 2) the right approach for this use case, or would this be considered outside the tool's scope?
Both
transform
andpostTransform
only expose type nodes (resulting in inline JSDoc), but we need access to property signatures for above-property JSDoc placement. AtransformProperty
hook would provide this access.Would the maintainers be open to a PR for either approach, or should we pursue external solutions?
Use Case
This would enable seamless integration between OpenAPI schemas and tsoa for runtime validation without manual JSDoc maintenance.
Beta Was this translation helpful? Give feedback.
All reactions