[REQ][typescript-fetch] Option to keep the previous UTC anchoring of format: date (behaviour change in 7.25.0)
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 68/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, typescript
- Lĩnh vực
- tooling
Hướng nghiên cứu
Read the typescript-fetch generator options and its runtime.mustache template, especially the parseDate and serializeDate helpers; the issue says generated date handling already goes through them. Check the generator's option tests and add coverage for both local and utc behavior, including parsing and serialization. Done means the new option defaults to local and selects the documented UTC behavior when configured.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Is your feature request related to a problem? Please describe.
Since 7.25.0, typescript-fetch anchors format: date values to the local calendar instead of UTC (#24722, based on #24637, which fixes #24636). #24637 documents it as a behaviour change, and it is deliberate. This issue is not about reverting it: it asks for a way to keep the previous behaviour.
Code that treats a date-only value as a UTC calendar day now gets the wrong day in every time zone except UTC, with no error and no type change. For example code that:
- reads a parsed date with
getUTC*/toISOString(), or compares it withDate.UTC(...); - turns an API or URL string into a
Datewithnew Date("YYYY-MM-DD")(which the spec defines as UTC midnight) and passes it back as aformat: dateparameter; - renders on the server, where the instant now depends on the process time zone.
Neither anchor is "the" correct one: both round-trip consistently, they just disagree about which instant a date-only value is. The 7.22 (UTC) anchor is right for dates that come from the API or from ISO strings and wrong for dates built from a local date picker, new Date(2026, 7, 5). The 7.27 (local) anchor is the other way round (the table below shows both). So whichever one an application was written against, the other one breaks it, and the generator upgrade silently forces a migration of every date-handling code path.
Today the only ways out are dateLibrary=string / temporal (they change the types of every date and date-time property, see "Alternatives") or maintaining a custom copy of runtime.mustache.
Reproduction
spec.yaml:
openapi: 3.0.3
info: { title: Date handling repro, version: 1.0.0 }
paths:
/events:
get:
operationId: listEvents
parameters:
- { name: from, in: query, schema: { type: string, format: date } }
responses:
"200":
description: ok
content:
application/json:
schema: { $ref: "#/components/schemas/Event" }
components:
schemas:
Event:
type: object
required: [name]
properties:
name: { type: string }
starts_on: { type: string, format: date }
starts_at: { type: string, format: date-time }
Generate with the two versions and compile (Node v26.13.1, TypeScript from any recent install):
docker run --rm -v "$PWD:/local" openapitools/openapi-generator-cli:v7.22.0 generate -g typescript-fetch -i /local/spec.yaml -o /local/out-7.22.0
docker run --rm -v "$PWD:/local" openapitools/openapi-generator-cli:v7.27.0 generate -g typescript-fetch -i /local/spec.yaml -o /local/out-7.27.0
for d in out-7.22.0 out-7.27.0; do tsc --target es2020 --module commonjs --lib es2020,dom --skipLibCheck --outDir $d/js $d/index.ts; done
repro.cjs (run as TZ=Europe/Paris node repro.cjs out-7.27.0)
const dir = require("path").resolve(process.argv[2]);
const { EventFromJSON } = require(`${dir}/js/models/Event`);
const { DefaultApi } = require(`${dir}/js/apis/DefaultApi`);
const { Configuration } = require(`${dir}/js/runtime`);
(async () => {
const event = EventFromJSON({ name: "x", starts_on: "2026-08-05", starts_at: "2026-08-05T00:00:00Z" });
let url;
const fetchApi = async (input) => {
url = String(input);
return new Response("{}", { status: 200, headers: { "Content-Type": "application/json" } });
};
const api = new DefaultApi(new Configuration({ basePath: "http://example.test", fetchApi }));
const sent = async (date) => {
await api.listEventsRaw({ from: date });
return new URL(url).searchParams.get("from");
};
console.log(
JSON.stringify({
tz: process.env.TZ,
// the API sent "starts_on": "2026-08-05"
startsOn_getUTCDate: event.startsOn.getUTCDate(),
startsOn_getDate: event.startsOn.getDate(),
// value of the `from` query parameter for these two Dates
from_for_new_Date_2026_08_05: await sent(new Date("2026-08-05")), // UTC midnight
from_for_new_Date_2026_7_5: await sent(new Date(2026, 7, 5)), // local midnight
})
);
})();
Results (the same script, run for each TZ):
Parsing: the API sends "starts_on": "2026-08-05"; getUTCDate() / getDate() of the resulting Date:
| TZ | 7.22.0 | 7.27.0 |
|---|---|---|
| UTC | 5 / 5 | 5 / 5 |
| Europe/Paris | 5 / 5 | 4 / 5 |
| America/Sao_Paulo | 5 / 4 | 5 / 5 |
| America/New_York | 5 / 4 | 5 / 5 |
| Pacific/Kiritimati | 5 / 5 | 4 / 5 |
Serializing: from sent for new Date("2026-08-05") (UTC midnight) / for new Date(2026, 7, 5) (local midnight):
| TZ | 7.22.0 | 7.27.0 |
|---|---|---|
| UTC | 2026-08-05 / 2026-08-05 | 2026-08-05 / 2026-08-05 |
| Europe/Paris | 2026-08-05 / 2026-08-04 | 2026-08-05 / 2026-08-05 |
| America/Sao_Paulo | 2026-08-05 / 2026-08-05 | 2026-08-04 / 2026-08-05 |
| America/New_York | 2026-08-05 / 2026-08-05 | 2026-08-04 / 2026-08-05 |
| Pacific/Kiritimati | 2026-08-05 / 2026-08-04 | 2026-08-05 / 2026-08-05 |
(Bold = the day is not the one the code meant, for that convention.) format: date-time is handled the same way in both versions (new Date(value) on parsing, toISOString() on serializing).
The template on master has the same serializeDate / parseDate as 7.27.0.
Describe the solution you'd like
A typescript-fetch option that picks how a format: date value is anchored to an instant, with:
local: the current behaviour, and the default, so nothing changes for anyone relying on 7.25+;utc: the behaviour up to 7.24, i.e.parseDate=new Date(value)andserializeDate=value.toISOString().substring(0, 10).
The name is open (dateAnchor? dateTimeZone? a value of dateLibrary is not an option, see below). Thanks to the centralisation in #24722, the difference between the two is just the bodies of two helpers in runtime.mustache (parseDate, serializeDate): every generated call site already goes through them.
Describe alternatives you've considered
dateLibrary=string: the description of #24637 calls it a way out that "reproduces the current behaviour exactly". In the repro above it changes the type of every date and date-time property: with-p dateLibrary=stringthe generatedEventhasstartsOn: stringandstartsAt: string(typeofis"string"for both), so every consumer has to parse all of them, including the date-times whose behaviour is identical in both versions.dateLibrary=temporal: experimental, and changes every date type again.- Overriding
runtime.mustachewith a custom template (-t) should work, but it means maintaining a copy of a ~600-line template and re-diffing it on every generator upgrade, to change two functions. - Staying on 7.24.x: forgoes the other fixes since.
Additional context
Tested with the openapitools/openapi-generator-cli images v7.22.0 and v7.27.0 and the template on master. Related: #24636, #24637, #24722, and #17284 / #17272 (cited in #24637 as the same question for the typescript generator).
- Ngôn ngữ chính
- Java
- Star
- 26.9k
- Fork
- 7.8k
- Merge trung bình
- 2 ngày 23 phút
- Pull request đã merge (30 ngày)
- 177
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của OpenAPITools/openapi-generator
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
OpenAPITools/openapi-generator#25768 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Enhancement: Feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
OpenAPITools/openapi-generator#25753 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG][RUBY-NEXTGEN] A non-String value in a pattern-constrained attribute raises NoMethodErrorCó thể đã có người làm @Inf1mum đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
OpenAPITools/openapi-generator#25724 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG][RUBY-NEXTGEN] Response#to_hash is advertised and raises when the data is an ArrayCó thể đã có người làm @Inf1mum đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
OpenAPITools/openapi-generator#25723 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG][RUBY-NEXTGEN] A JSON string response raises ApiError because the body is parsed twiceCó thể đã có người làm @Inf1mum đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
OpenAPITools/openapi-generator#25719 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của OpenAPITools/openapi-generator
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
eclipse-tradista/tradista#371 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Failed to start Rescue missionĐang mởcritical
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
mars-sim/mars-sim#2199 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG-02] Endpoints /assistente/relatorio/*/preview retornam 404 ("Ver na tela" dos relatórios)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
projeto-ong-amar/projeto-ong-amar-backend#26 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
primefaces/primefaces#15568 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
崩溃日志只按 CRLF 分行Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
PCL-Community/PCL-CE#3872 ·
Maintainer thường phản hồi trong vòng 1 ngày