Skip to content

JSDoc Constraint Support for Mock Data Generation #11

@Many0nne

Description

@Many0nne

Problem

The tool generated mock data based only on TypeScript types, without respecting specific business constraints. For example, a badge: string field was generated without considering the 10-character limit imposed by the future backend.

Solution Implemented

Added a comprehensive JSDoc annotation system to specify constraints directly in TypeScript interfaces. These constraints guide the mock data generation process.

Features

  • Constraint Extraction (constraintExtractor.ts) : Parses JSDoc annotations (@minlength, @maxlength, @pattern, @min, @max, @enum) directly from TypeScript code
  • Constraint Validation (constraintValidator.ts) : Validates that generated values respect the defined rules
  • Guided Generation (constrainedGenerator.ts) : Automatically generates data that respects constraints
  • Transparent Integration : Constraints are applied automatically during generation, with no API changes

Supported Constraints

Annotation Type Example
@minLength string @minLength 3
@maxLength string @maxLength 10
@pattern string @pattern ^[a-z]+$
@min number @min 1
@max number @max 100
@enum any @enum ACTIVE,INACTIVE,PENDING

Example

// @endpoint
export interface Badge {
  /** @maxLength 10 */
  label: string;
  
  /** @min 1 @max 5 */
  level: number;
  
  /** @enum ACTIVE,INACTIVE,PENDING */
  status: string;
}

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions