Skip to content

Comments

fix: improve typescript generator#331

Open
jonaslagoni wants to merge 11 commits intomainfrom
improve_typescript_generator
Open

fix: improve typescript generator#331
jonaslagoni wants to merge 11 commits intomainfrom
improve_typescript_generator

Conversation

@jonaslagoni
Copy link
Contributor

@jonaslagoni jonaslagoni commented Feb 22, 2026

Note

Medium Risk
Changes core TypeScript codegen semantics (notably Date vs string and union/array marshal/unmarshal behavior), which can affect downstream generated clients and runtime validation behavior.

Overview
Improves the TypeScript Modelina presets to better handle schema edge cases: adds explicit null marshal/unmarshal generation, treats string formats date/date-time as Date during unmarshal, and avoids attempting per-item unmarshal for arrays of arrays/unions.

Adjusts generated AJV schema/validation output by making validate() accept marshalled JSON strings (parses string input) and by safeStringify dropping root-level type: "object" when it conflicts with oneOf/anyOf unions.

Updates runtime/generated fixtures accordingly, bumps @asyncapi/modelina to 6.0.0-next.8, and adds a comprehensive AsyncAPI payload-types runtime test spec + generator config to validate many JSON Schema type variations end-to-end.

Written by Cursor Bugbot for commit cae72a5. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Feb 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
the-codegen-project Ready Ready Preview, Comment Feb 22, 2026 9:57pm
the-codegen-project-mcp Ready Ready Preview, Comment Feb 22, 2026 9:57pm

@netlify
Copy link

netlify bot commented Feb 22, 2026

Deploy Preview for the-codegen-project canceled.

Name Link
🔨 Latest commit cae72a5
🔍 Latest deploy log https://app.netlify.com/projects/the-codegen-project/deploys/699b7b609a42e40008f9f8e2

@jonaslagoni
Copy link
Contributor Author

Re: Date unmarshal bug

Acknowledged. This is a valid bug that will require fixes in two places:

  1. This repo (cli): The primitives.ts preset handles simple type aliases like FormatDate. The unmarshal needs to wrap date strings with new Date().

  2. Modelina repo: The class-based models like PetOrder and AllOfTwoTypes have unmarshal code generated by Modelina. Date conversion needs to be added there.

Tracking this for a follow-up fix that spans both repos.

- Remove 'time' format from isDateFormatModel to prevent Invalid Date
  (time strings like "14:30:00" are not valid Date constructor args)
- Exclude ConstrainedUnionModel from hasItemUnmarshal to prevent
  undefined Union.unmarshal reference for tuple arrays

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

}
const format = model.originalInput?.format;
return format === 'date' || format === 'date-time';
}
Copy link

Choose a reason for hiding this comment

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

FormatTime unmarshal returns string despite Date type

Medium Severity

The isDateFormatModel function correctly excludes time format from new Date() wrapping because time-only strings produce Invalid Date. However, Modelina still generates type FormatTime = Date for format: "time" schemas. The resulting unmarshal uses the primitive path (JSON.parse(json) as FormatTime), returning a string unsafely cast to Date. Any caller using Date methods on the result will get runtime errors. Either the time format needs new Date() wrapping or Modelina's type mapping needs to produce string instead of Date for time-only formats.

Additional Locations (1)

Fix in Cursor Fix in Web

}
if (obj["updatedAt"] !== undefined) {
instance.updatedAt = obj["updatedAt"];
}
Copy link

Choose a reason for hiding this comment

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

Class model unmarshal assigns strings to Date fields

High Severity

Class-based models like AllOfTwoTypes, AllOfThreeTypes, and PetOrder now type createdAt, updatedAt, and shipDate as Date (from the Modelina upgrade), but their unmarshal methods assign raw JSON-parsed string values directly without wrapping in new Date(). Consumers will get a string at runtime despite the Date type annotation, causing runtime failures on any Date method call.

Additional Locations (2)

Fix in Cursor Fix in Web

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