Repository navigation
Conversation
…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>
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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())))) { |
There was a problem hiding this comment.
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>
| 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; |
There was a problem hiding this comment.
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>
| public static final String DATE_ANCHOR_VALUE = TypeScriptFetchClientCodegen.DATE_ANCHOR_UTC; | |
| public static final String DATE_ANCHOR_VALUE = TypeScriptFetchClientCodegen.DATE_ANCHOR_LOCAL; |
thekhegay
left a comment
There was a problem hiding this comment.
Default local keeps what master emits today, so no break for existing users. Few things:
dateAnchoraccepts any string, soUTCorutcsilently ends up aslocal, oposite of what user asked. Better reject unknown values with IllegalArgumentException like fileNaming does- doc comment above
serializeDateTimesays date is converted against local calendar on both ends, but it is emitted withutctoo where its wrong. Wrapping it inisDateAnchorUtcwould fix it testDateAnchorUtcIsIgnoredWithoutDateLibraryDatepasses without the change, string library emits no date helpers at all. AssertingisDateAnchorUtcis false in additionalProperties would pin it
Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
…rties Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
|
All three review points are addressed on the branch (d30b8c5 + 21b39e9):
|
Fixes #25725
Restores the pre-7.25 UTC anchoring of
format: datequery parameters behind a newdateAnchorgenerator option (localby default = current behavior,utc= the legacytoISOString().substring(0, 10)/new Date(value)semantics), as approved in the issue discussion. The option is ignored with a warning fordateLibraryvalues without date anchoring.parseDate/serializeDatebranch on the option inruntime.mustache; 3 new generator tests plus options coverage; a newdate-anchor-utcsample 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
dateAnchoroption to typescript-fetch soformat: datevalues 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=localis the default and produces byte-identical output to the current behaviour.dateAnchor=utcrestores the legacynew Date(value)parse andtoISOString().substring(0, 10)serialization.dateLibraryisstringortemporal; invalid values are rejected, and tests plus adate-anchor-utcsample cover bothdatepaths.Written for commit 21b39e9. Summary will update on new commits.