Skip to content

Fix #25725: add dateAnchor option to typescript-fetch (local default, utc legacy) - #25738

Open
Inf1mum wants to merge 3 commits into
OpenAPITools:masterfrom
Inf1mum:fix/25725-ts-fetch-utc
Open

Inf1mum wants to merge 3 commits into
OpenAPITools:masterfrom
Inf1mum:fix/25725-ts-fetch-utc

Conversation

@Inf1mum

@Inf1mum Inf1mum commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #25725

Restores the pre-7.25 UTC anchoring of format: date query parameters behind a new dateAnchor generator option (local by default = current behavior, utc = the legacy toISOString().substring(0, 10) / new Date(value) semantics), as approved in the issue discussion. The option is ignored with a warning for dateLibrary values without date anchoring.

parseDate/serializeDate branch on the option in runtime.mustache; 3 new generator tests plus options coverage; a new date-anchor-utc sample documents the output, and regenerating all 26 typescript-fetch samples with the built CLI proved the default path is byte-identical.


Summary by cubic

Fixes #25725 by adding a dateAnchor option to typescript-fetch so format: date values can keep the pre-7.25 UTC anchoring where the local-calendar behaviour introduced in 7.25.0 shifts the day for non-UTC consumers.

  • dateAnchor=local is the default and produces byte-identical output to the current behaviour.
  • dateAnchor=utc restores the legacy new Date(value) parse and toISOString().substring(0, 10) serialization.
  • The option is ignored with a warning when dateLibrary is string or temporal; invalid values are rejected, and tests plus a date-anchor-utc sample cover both date paths.

Written for commit 21b39e9. Summary will update on new commits.

View guided diff

…keep the previous UTC anchoring of format: date

Since 7.25.0 (OpenAPITools#24722) a format: date value is parsed to local midnight and serialized from the local calendar. Applications that treat a date-only value as a UTC calendar day (getUTC*/toISOString(), new Date("YYYY-MM-DD") round-trips) get a shifted day in every zone except UTC. This adds a typescript-fetch dateAnchor option: local (the default, current behaviour) and utc (the pre-7.25 behaviour: parseDate = new Date(value), serializeDate = value.toISOString().substring(0, 10)). The difference is only the bodies of the two centralised helpers in runtime.mustache; dateAnchor=utc is ignored with a warning for dateLibrary string/temporal.

Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

3 issues found across 28 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/test/java/org/openapitools/codegen/options/TypeScriptFetchClientOptionsProvider.java">

<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/options/TypeScriptFetchClientOptionsProvider.java:35">
P3: This fixture pairs `dateAnchor=utc` with `dateLibrary=string`, which the generator ignores and warns about on every options test run. Use a value that does not trigger the ignored-option path, such as the `local` default, or pick a dateLibrary that the options test can actually exercise.</violation>
</file>

<file name="samples/client/petstore/typescript-fetch/builds/date-anchor-utc/README.md">

<violation number="1" location="samples/client/petstore/typescript-fetch/builds/date-anchor-utc/README.md:31">
P2: The README example's bare date-time value is invalid TypeScript, and its bare date value evaluates to a number rather than a `Date`. Wrap these values in `new Date('…')` in the README and API examples.</violation>
</file>

<file name="samples/client/petstore/typescript-fetch/builds/date-anchor-utc/src/models/Holidays.ts">

<violation number="1" location="samples/client/petstore/typescript-fetch/builds/date-anchor-utc/src/models/Holidays.ts:32">
P2: Numeric arrays match the date branch first because `parseDate(1)` creates a valid timestamp, so `HolidaysFromJSON([1])` returns `Date[]` instead of `number[]`. Require date-shaped string items before parsing.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

// Date
startsOn: 2013-10-20,
// Date (optional)
createdAt: 2013-10-20T19:20:30+01:00,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: The README example's bare date-time value is invalid TypeScript, and its bare date value evaluates to a number rather than a Date. Wrap these values in new Date('…') in the README and API examples.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At samples/client/petstore/typescript-fetch/builds/date-anchor-utc/README.md, line 31:

<comment>The README example's bare date-time value is invalid TypeScript, and its bare date value evaluates to a number rather than a `Date`. Wrap these values in `new Date('…')` in the README and API examples.</comment>

<file context>
@@ -0,0 +1,117 @@
+    // Date
+    startsOn: 2013-10-20,
+    // Date (optional)
+    createdAt: 2013-10-20T19:20:30+01:00,
+  } satisfies CreateEventRequest;
+
</file context>

return json;
}
if (Array.isArray(json)) {
if (json.every(item => !(isNaN(parseDate(item).getTime())))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Numeric arrays match the date branch first because parseDate(1) creates a valid timestamp, so HolidaysFromJSON([1]) returns Date[] instead of number[]. Require date-shaped string items before parsing.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At samples/client/petstore/typescript-fetch/builds/date-anchor-utc/src/models/Holidays.ts, line 32:

<comment>Numeric arrays match the date branch first because `parseDate(1)` creates a valid timestamp, so `HolidaysFromJSON([1])` returns `Date[]` instead of `number[]`. Require date-shaped string items before parsing.</comment>

<file context>
@@ -0,0 +1,64 @@
+        return json;
+    }
+    if (Array.isArray(json)) {
+        if (json.every(item => !(isNaN(parseDate(item).getTime())))) {
+            return json.map(value => parseDate(value));
+        }
</file context>
Suggested change
if (json.every(item => !(isNaN(parseDate(item).getTime())))) {
if (json.every(item => typeof item === 'string' && !(isNaN(parseDate(item).getTime())))) {

public static final String STRING_ENUMS = "false";
public static final String FILE_NAMING_VALUE = PASCAL_CASE;
public static final String DATE_LIBRARY_VALUE = TypeScriptFetchClientCodegen.DATE_LIBRARY_STRING;
public static final String DATE_ANCHOR_VALUE = TypeScriptFetchClientCodegen.DATE_ANCHOR_UTC;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P3: This fixture pairs dateAnchor=utc with dateLibrary=string, which the generator ignores and warns about on every options test run. Use a value that does not trigger the ignored-option path, such as the local default, or pick a dateLibrary that the options test can actually exercise.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/test/java/org/openapitools/codegen/options/TypeScriptFetchClientOptionsProvider.java, line 35:

<comment>This fixture pairs `dateAnchor=utc` with `dateLibrary=string`, which the generator ignores and warns about on every options test run. Use a value that does not trigger the ignored-option path, such as the `local` default, or pick a dateLibrary that the options test can actually exercise.</comment>

<file context>
@@ -32,6 +32,7 @@ public class TypeScriptFetchClientOptionsProvider implements TypeScriptSharedCli
     public static final String STRING_ENUMS = "false";
     public static final String FILE_NAMING_VALUE = PASCAL_CASE;
     public static final String DATE_LIBRARY_VALUE = TypeScriptFetchClientCodegen.DATE_LIBRARY_STRING;
+    public static final String DATE_ANCHOR_VALUE = TypeScriptFetchClientCodegen.DATE_ANCHOR_UTC;
 
 
</file context>
Suggested change
public static final String DATE_ANCHOR_VALUE = TypeScriptFetchClientCodegen.DATE_ANCHOR_UTC;
public static final String DATE_ANCHOR_VALUE = TypeScriptFetchClientCodegen.DATE_ANCHOR_LOCAL;

@thekhegay thekhegay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Default local keeps what master emits today, so no break for existing users. Few things:

  • dateAnchor accepts any string, so UTC or utc silently ends up as local, oposite of what user asked. Better reject unknown values with IllegalArgumentException like fileNaming does
  • doc comment above serializeDateTime says date is converted against local calendar on both ends, but it is emitted with utc too where its wrong. Wrapping it in isDateAnchorUtc would fix it
  • testDateAnchorUtcIsIgnoredWithoutDateLibraryDate passes without the change, string library emits no date helpers at all. Asserting isDateAnchorUtc is false in additionalProperties would pin it

Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
…rties

Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
@Inf1mum

Inf1mum commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

All three review points are addressed on the branch (d30b8c5 + 21b39e9):

  • dateAnchor now rejects unknown values with IllegalArgumentException, same pattern as fileNaming (setDateAnchor validation + testDateAnchorInvalidValues);
  • the serializeDateTime doc comment is branch-wrapped on isDateAnchorUtc — the utc branch describes UTC anchoring, the local branch keeps master's wording verbatim;
  • testDateAnchorUtcIsIgnoredWithoutDateLibraryDate now asserts isDateAnchorUtc == false lands in additionalProperties.

TypeScriptFetch* suite: 87 tests, 0 failures; the date-anchor-utc sample only differs in the doc comment; local-behavior samples byte-identical.

@thekhegay thekhegay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

This branch has not been deployed

No deployments
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.

[REQ][typescript-fetch] Option to keep the previous UTC anchoring of format: date (behaviour change in 7.25.0)

2 participants