Feature Request: Adding validation JSDoc annotations (@minLength, @pattern, etc.) to generated TypeScript properties #2411
Unanswered
kristianjf
asked this question in
Q&A
Replies: 0 comments
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