[typescript-fetch] centralise date handling, add dateLibrary

Merged
WI
4mo ago
+3832-134

based on https://github.com/OpenAPITools/openapi-generator/pull/24637 with updated samples.

all TS tests passed.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Centralizes date handling for typescript-fetch and adds a dateLibrary option to choose Date (default) or string. Fixes format: date bugs (incorrect form param serialization and UTC day shifts) by using the local calendar for date and UTC for date-time.

  • Runtime: all date parsing/serialization now uses parseDate, parseDateTime, serializeDate, and serializeDateTime in runtime.ts; querystring and path/query/form params route through these.
  • Generator: new additionalProperties.dateLibrary option (date | string); withoutRuntimeChecks implies string. Docs updated.
  • Templates: models and oneOf guards align with helpers; date imports only when needed via x-hasDateVars. ES6-safe code; preserves years 0000–0099 and rejects invalid dates.
  • Tests/samples: added a fixture covering all date locations and two sample builds (date and string).

Migration

  • If your client expects string dates, set -p dateLibrary=string (or dateLibrary: string in config). Regenerate and update types accordingly.
  • If you relied on withoutRuntimeChecks for string dates, no change; to get Date, disable that flag and/or set -p dateLibrary=date.