Skip to content

Conversation

@hyeonss0417
Copy link
Contributor

Summary

Fix incorrect OpenAPI schema generation for string, enum, and array types in NestJS parser.

Problem

The following types were being incorrectly converted to { type: 'object', additionalProperties: ... }:

  1. String properties - key: string{ type: 'object', additionalProperties: { type: 'string' } }
  2. Enum properties - gender: Gender{ type: 'object', additionalProperties: ... }
  3. Array properties - users: UserDto[]{ type: 'object', additionalProperties: { $ref: '...' } }

Root Cause

TypeScript's getIndexInfosOfType() returns index signatures for:

  • Primitive types (string[number]string)
  • Enum types (union of literals)
  • Array types (T[])

These were incorrectly treated as Record<K, V> or Map<K, V> types.

Solution

Added checks in getIndexSignatureInfoFromType() to skip:

  • Primitive types (string, number, boolean, etc.)
  • Array types (T[] or Array<T>)
  • Enum types (union of literals or TypeFlags.Enum)

Additional Changes

  • TJS Integration: Added typescript-json-schema as fallback for types not found in typeDefinitions
  • Async Support: Made generateOpenApiFromNest async for TJS schema conversion
  • Test Coverage: Added test for array property types to prevent regression

Testing

  • All 132 tests pass
  • Added new test case: should handle array properties correctly (not as Record/Map)

Example

Before:

"subscriptionProducts": {
  "type": "object",
  "additionalProperties": {
    "$ref": "#/components/schemas/SubscriptionProductDto"
  }
}

After:

"subscriptionProducts": {
  "type": "array",
  "items": {
    "$ref": "#/components/schemas/SubscriptionProductDto"
  }
}

…ay types

- Fix string types being incorrectly converted to Record<string, string>
- Fix enum types being incorrectly treated as index signature types
- Fix array types (T[]) being converted to object with additionalProperties
- Add TJS integration as fallback for types not found in typeDefinitions
- Add test for array property types to prevent regression
- Make generateOpenApiFromNest async for TJS schema conversion

The root cause was that TypeScript's getIndexInfosOfType() returns index
signatures for primitive types (string[number] -> string), enum types,
and array types. These should not be treated as Record/Map types.

Added checks in getIndexSignatureInfoFromType() to skip:
- Primitive types (string, number, boolean, etc.)
- Array types (T[] or Array<T>)
- Enum types (union of literals or TypeFlags.Enum)
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@hyeonss0417 hyeonss0417 merged commit 08a503d into main Dec 25, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants