Skip to content

Conversation

Prithpal-Sooriya
Copy link

@Prithpal-Sooriya Prithpal-Sooriya commented Oct 18, 2025

Issue

Elysia’s fromTypes() type generation fails when a route path contains alphanumeric segments (e.g. /v1, /v2/foo).

For example this snippet.

import { Elysia } from 'elysia'
import openapi, { fromTypes } from '@elysiajs/openapi'

export const app = new Elysia()
  .use(openapi({
    references: fromTypes('<path-to-this-file>.ts'),
  }))
  .get('/v', () => 5 as const)    // ✅ works
  .get('/1', () => 5 as const)    // ✅ works
  .get('/v1', () => 5 as const)   // ❌ fails
  .get('/v1/foo', () => 5 as const) // ❌ fails

console.log(JSON.stringify(fromTypes('<path-to-this-file>.ts')(), null, 2))

Root Cause

During type generation, the declaration string is parsed and numeric keys are quoted using this regex:

const numberKey = /(\d+):/g

This works for numeric property keys:

- 1: { ... }
+ "1": { ... } ✅ 

But breaks for alphanumeric property keys:

- v1: { ... }
+ v"1": { ... } ❌

Fix

Replace the numeric-only key matcher with a more general regex that safely quotes all unquoted valid property keys.

This results in

- v1: { ... }
+ "v1": { ... } ✅
- 2: { ... }
+ "2": { ... } ✅
- foo: { ... }
+ "foo": { ... } ✅

@coderabbitai
Copy link

coderabbitai bot commented Oct 18, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (2)
  • src/gen/index.ts is excluded by !**/gen/**
  • test/gen/index.test.ts is excluded by !**/gen/**

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Prithpal-Sooriya Prithpal-Sooriya changed the title fix: add type-gen support for versioning paths fix: add type-gen support for alphanumeric paths Oct 18, 2025
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.

1 participant