Skip to content

Feature Request: Adding validation JSDoc annotations (@minLength, @pattern, etc.) to generated TypeScript properties #2448

@drwpow

Description

@drwpow

Discussed in #2411

Originally posted by kristianjf August 13, 2025

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:

name:
  type: string
  minLength: 1
  pattern: "^[a-zA-Z0-9]+$"

Currently generate clean TypeScript:

interface MyType {
  name: string;
}

Using transform to add JSDoc results in inline comments:

interface MyType {
  name: /** @minLength 1 @pattern ^[a-zA-Z0-9]+$ */string;
}

But we need tsoa-compatible JSDoc annotations above properties:

interface MyType {
  /**
   * @minLength 1
   * @pattern ^[a-zA-Z0-9]+$
   */
  name: string;
}

Approaches Considered

  1. Extending addJSDocComment function - Add validation constraints to the existing JSDoc generation
  2. Adding transformProperty hook - Similar to transform/postTransform but exposes the property signature for modification
  3. External post-processing - Parse generated types and add JSDoc via AST manipulation

Question

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 and postTransform only expose type nodes (resulting in inline JSDoc), but we need access to property signatures for above-property JSDoc placement. A transformProperty 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    PRs welcomePRs are welcome to solve this issue!enhancementNew feature or requestgood first issueStraightforward problem, solvable for first-time contributors without deep knowledge of the projectopenapi-tsRelevant to the openapi-typescript library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions