[typescript-fetch] Add Temporal support - #24924
Conversation
This adds a new date library option to the typescript-fetch generator: "temporal". With it, the generator uses Temporal.Instant for "type: string, format: date-time" and Temporal.PlainDate for "type: string, format: date".
|
|
||
| {{#isDateLibraryTemporal}} | ||
| export function serializeDateTime(value: Temporal.Instant): string { | ||
| return value.toString(); |
There was a problem hiding this comment.
It's worth noting that Temporal.Instant's toString() method gives something like this (based on my experiments):
- Node: "2026-08-15T14:25:49.161593018Z"
- Firefox: "2026-08-15T14:25:46.876Z"
- Chromium: "2026-08-15T14:26:24.1674Z"
So in Node, the precision is up to nanoseconds. Also, the Temporal specification says that the number of places after the decimal point may differ because trailing zeroes are removed.
Date's toISOString() method uses precision only down to milliseconds in all three runtimes I've tried.
There was a problem hiding this comment.
1 issue found across 7 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache:311">
P2: When `dateLibrary=temporal` is used for a path parameter, the generated API references `Temporal` without providing its TypeScript declaration. Add an explicit Temporal type dependency/reference, or otherwise generate the required ambient typing so the generated package builds without manual consumer setup.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| {{#pathParams}} | ||
| {{#isDateTimeType}} | ||
| {{#isDateLibraryTemporal}} | ||
| if (requestParameters['{{paramName}}'] instanceof Temporal.Instant) { |
There was a problem hiding this comment.
P2: When dateLibrary=temporal is used for a path parameter, the generated API references Temporal without providing its TypeScript declaration. Add an explicit Temporal type dependency/reference, or otherwise generate the required ambient typing so the generated package builds without manual consumer setup.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache, line 311:
<comment>When `dateLibrary=temporal` is used for a path parameter, the generated API references `Temporal` without providing its TypeScript declaration. Add an explicit Temporal type dependency/reference, or otherwise generate the required ambient typing so the generated package builds without manual consumer setup.</comment>
<file context>
@@ -307,16 +307,28 @@ export class {{classname}} extends runtime.BaseAPI {
{{#pathParams}}
{{#isDateTimeType}}
+ {{#isDateLibraryTemporal}}
+ if (requestParameters['{{paramName}}'] instanceof Temporal.Instant) {
+ urlPath = urlPath.replace({{=<< >>=}}'{<<baseName>>}'<<={{ }}=>>, encodeURIComponent(runtime.serializeDateTime(requestParameters['{{paramName}}'])));
+ {{/isDateLibraryTemporal}}
</file context>
Based on comments from cubic-dev-ai.
This adds a new date library option to the typescript-fetch generator: "temporal". With it, the generator uses Temporal.Instant for "type: string, format: date-time" and Temporal.PlainDate for "type: string, format: date".
It does what the commit comment says: it adds the option to use Temporal types instead of Date (or String) for typescript-fetch. I've manually tried it on an OpenAPI YAML file having date and date-time parameters/attributes in a URL path, in URL query parameters, and in request/response (JSON) bodies. Everything seems to work well.
Rationale for the changes:
The goal is to stay as close as possible to the current implementation built around Date and only use Instant/PlainDate in a manner that's as similar to the existing implementation as possible.
Tagging: @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @topce @akehir @petejohansonxo @amakhrov @davidgamero @mkusaka @joscha @KannaKim.
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
Tests run: 4977, Failures: 2, Errors: 0, Skipped: 7). However, the same two tests fail for me also on master (as of 888f17b) when runningmvn clean package -Ddevelocity.cache.local.enabled=false -Ddevelocity.cache.remote.enabled=false. The tests in question:org.openapitools.codegen.cppboostbeast.Oas31ExactRuntimeTest.generatedClientHonorsCompositionAndParameterWireSemanticsandorg.openapitools.codegen.cppboostbeast.Oas31ExactRuntimeTest.generatedClientPreservesAdditionalPropertiesWhenEnabled.Summary by cubic
Adds a
temporaloption to thedateLibrarysetting for thetypescript-fetchgenerator, mapping OpenAPIdatetoTemporal.PlainDateanddate-timetoTemporal.Instantinstead ofDate.Changes
dateLibrary=temporaloption with runtime serialization/deserialization helpers.withoutRuntimeChecksfalls back tostringfor temporal, same as fordate.Temporal.InstantandTemporal.PlainDateare now recognized as language-specific primitives.Written for commit 168198a. Summary will update on new commits.