From bfb141baa6f1d22de599d083f51cce0a2d5f3eb0 Mon Sep 17 00:00:00 2001 From: Nicolas Medda Date: Thu, 6 Aug 2026 17:28:22 +0200 Subject: [PATCH 1/2] [typescript-fetch] centralise date handling, add dateLibrary, fix format: date MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Date handling was spread across four templates, each inlining its own expression. That had three consequences: 1. `format: date` was not handled at all for form parameters, so a Date was appended raw and stringified by the browser ("Wed Aug 05 2026 00:00:00 GMT+0200 (…)") instead of "2026-08-05". 2. `format: date` shifted by a day everywhere except UTC, in one direction or the other. Parsing (`new Date('2026-08-05')`) and serialising (`.toISOString().substring(0, 10)`) both work in UTC, but consumers do not: a date picker builds local midnight and display reads local getters. West of UTC a date from the API displays as the previous day; east of UTC a locally built date is sent as the previous day. An RFC 3339 full-date has no offset, so both ends have to use the same wall clock — they now both use the local calendar. `format: date-time` is a genuine instant and stays UTC. 3. Whether dates were represented as Date or string was decided by `withoutRuntimeChecks`, an unrelated flag about payload validation. All call sites (models, oneOf models, path/query/form parameters and the querystring helper) now route through serializeDate/serializeDateTime and parseDate/parseDateTime in runtime.ts, so the representation is defined in one place. The new `dateLibrary` option (`date`, the default and previous behaviour, or `string`) makes the choice explicit; `withoutRuntimeChecks` implies `string`, as before, since there is no model code left to convert with. Adds a spec fixture covering every location a date can appear in, two sample builds (one per option value), and tests for the option, the fallback and the serialisation semantics. --- .../typescript-fetch-date-library-date.yaml | 6 + .../typescript-fetch-date-library-string.yaml | 6 + docs/generators/typescript-fetch.md | 1 + .../TypeScriptFetchClientCodegen.java | 47 ++ .../resources/typescript-fetch/apis.mustache | 11 +- .../apisAssignQueryParam.mustache | 4 +- .../typescript-fetch/modelGeneric.mustache | 10 +- .../typescript-fetch/modelOneOf.mustache | 19 +- .../typescript-fetch/runtime.mustache | 40 +- .../TypeScriptFetchClientOptionsProvider.java | 2 + .../TypeScriptFetchClientCodegenTest.java | 80 +++ .../TypeScriptFetchClientOptionsTest.java | 1 + .../3_0/typescript-fetch/date-handling.yaml | 81 +++ .../models/StructuredType.ts | 2 +- .../runtime.ts | 38 +- .../models/ExtendDto.ts | 2 +- .../models/TestBaseDto.ts | 2 +- .../infinite-recursion-issue/runtime.ts | 38 +- .../multipart-file-array/runtime.ts | 38 +- .../models/AbstractUserDto.ts | 2 +- .../self-import-issue/models/BranchDto.ts | 2 +- .../models/InternalAuthenticatedUserDto.ts | 2 +- .../models/RemoteAuthenticatedUserDto.ts | 2 +- .../self-import-issue/runtime.ts | 38 +- .../builds/allOf-nullable/models/Club.ts | 2 +- .../builds/allOf-nullable/models/Owner.ts | 2 +- .../builds/allOf-nullable/runtime.ts | 38 +- .../builds/allOf-readonly/models/Club.ts | 2 +- .../builds/allOf-readonly/models/Owner.ts | 2 +- .../builds/allOf-readonly/runtime.ts | 38 +- .../.openapi-generator-ignore | 23 + .../.openapi-generator/FILES | 8 + .../.openapi-generator/VERSION | 1 + .../date-library-date/apis/DefaultApi.ts | 173 +++++++ .../builds/date-library-date/apis/index.ts | 3 + .../date-library-date/docs/DefaultApi.md | 149 ++++++ .../builds/date-library-date/docs/Event.md | 38 ++ .../builds/date-library-date/index.ts | 5 + .../builds/date-library-date/models/Event.ts | 76 +++ .../builds/date-library-date/models/index.ts | 3 + .../builds/date-library-date/runtime.ts | 490 ++++++++++++++++++ .../.openapi-generator-ignore | 23 + .../.openapi-generator/FILES | 8 + .../.openapi-generator/VERSION | 1 + .../date-library-string/apis/DefaultApi.ts | 169 ++++++ .../builds/date-library-string/apis/index.ts | 3 + .../date-library-string/docs/DefaultApi.md | 149 ++++++ .../builds/date-library-string/docs/Event.md | 38 ++ .../builds/date-library-string/index.ts | 5 + .../date-library-string/models/Event.ts | 76 +++ .../date-library-string/models/index.ts | 3 + .../builds/date-library-string/runtime.ts | 466 +++++++++++++++++ .../builds/default-v3.0/apis/FakeApi.ts | 4 +- .../models/AdditionalPropertiesClass.ts | 2 +- .../default-v3.0/models/AllOfWithSingleRef.ts | 2 +- .../builds/default-v3.0/models/Animal.ts | 2 +- .../models/ArrayOfArrayOfNumberOnly.ts | 2 +- .../default-v3.0/models/ArrayOfNumberOnly.ts | 2 +- .../builds/default-v3.0/models/ArrayTest.ts | 2 +- .../default-v3.0/models/Capitalization.ts | 2 +- .../builds/default-v3.0/models/Cat.ts | 2 +- .../builds/default-v3.0/models/Category.ts | 2 +- .../default-v3.0/models/ChildWithNullable.ts | 2 +- .../builds/default-v3.0/models/ClassModel.ts | 2 +- .../builds/default-v3.0/models/Client.ts | 2 +- .../default-v3.0/models/DeprecatedObject.ts | 2 +- .../builds/default-v3.0/models/Dog.ts | 2 +- .../builds/default-v3.0/models/EnumArrays.ts | 2 +- .../builds/default-v3.0/models/EnumTest.ts | 2 +- .../models/FakeBigDecimalMap200Response.ts | 2 +- .../models/FileSchemaTestClass.ts | 2 +- .../builds/default-v3.0/models/Foo.ts | 2 +- .../models/FooGetDefaultResponse.ts | 2 +- .../builds/default-v3.0/models/FormatTest.ts | 10 +- .../default-v3.0/models/HasOnlyReadOnly.ts | 2 +- .../default-v3.0/models/HealthCheckResult.ts | 2 +- .../builds/default-v3.0/models/List.ts | 2 +- .../builds/default-v3.0/models/MapTest.ts | 2 +- ...dPropertiesAndAdditionalPropertiesClass.ts | 6 +- .../default-v3.0/models/Model200Response.ts | 2 +- .../default-v3.0/models/ModelApiResponse.ts | 2 +- .../builds/default-v3.0/models/ModelFile.ts | 2 +- .../builds/default-v3.0/models/Name.ts | 2 +- .../default-v3.0/models/NullableClass.ts | 10 +- .../builds/default-v3.0/models/NumberOnly.ts | 2 +- .../models/ObjectWithDeprecatedFields.ts | 2 +- .../builds/default-v3.0/models/Order.ts | 6 +- .../default-v3.0/models/OuterComposite.ts | 2 +- .../models/OuterObjectWithEnumProperty.ts | 2 +- .../default-v3.0/models/ParentWithNullable.ts | 2 +- .../builds/default-v3.0/models/Pet.ts | 2 +- .../default-v3.0/models/ReadOnlyFirst.ts | 2 +- .../builds/default-v3.0/models/Return.ts | 2 +- .../default-v3.0/models/SpecialModelName.ts | 2 +- .../builds/default-v3.0/models/Tag.ts | 2 +- ...lineFreeformAdditionalPropertiesRequest.ts | 2 +- .../builds/default-v3.0/models/User.ts | 2 +- .../builds/default-v3.0/runtime.ts | 38 +- .../builds/default/models/Category.ts | 2 +- .../builds/default/models/ModelApiResponse.ts | 2 +- .../builds/default/models/Order.ts | 6 +- .../builds/default/models/Pet.ts | 2 +- .../builds/default/models/Tag.ts | 2 +- .../builds/default/models/User.ts | 2 +- .../builds/default/runtime.ts | 38 +- .../builds/enum/models/EnumPatternObject.ts | 2 +- .../FakeEnumRequestGetInline200Response.ts | 2 +- .../typescript-fetch/builds/enum/runtime.ts | 38 +- .../builds/es6-target/src/models/Category.ts | 2 +- .../es6-target/src/models/ModelApiResponse.ts | 2 +- .../builds/es6-target/src/models/Order.ts | 6 +- .../builds/es6-target/src/models/Pet.ts | 2 +- .../builds/es6-target/src/models/Tag.ts | 2 +- .../builds/es6-target/src/models/User.ts | 2 +- .../builds/es6-target/src/runtime.ts | 38 +- .../builds/kebab-case/apis/fake-api.ts | 4 +- .../models/additional-properties-class.ts | 2 +- .../models/all-of-with-single-ref.ts | 2 +- .../builds/kebab-case/models/animal.ts | 2 +- .../models/array-of-array-of-number-only.ts | 2 +- .../kebab-case/models/array-of-number-only.ts | 2 +- .../builds/kebab-case/models/array-test.ts | 2 +- .../kebab-case/models/capitalization.ts | 2 +- .../builds/kebab-case/models/cat.ts | 2 +- .../builds/kebab-case/models/category.ts | 2 +- .../kebab-case/models/child-with-nullable.ts | 2 +- .../builds/kebab-case/models/class-model.ts | 2 +- .../builds/kebab-case/models/client.ts | 2 +- .../kebab-case/models/deprecated-object.ts | 2 +- .../builds/kebab-case/models/dog.ts | 2 +- .../builds/kebab-case/models/enum-arrays.ts | 2 +- .../builds/kebab-case/models/enum-test.ts | 2 +- .../fake-big-decimal-map200-response.ts | 2 +- .../models/file-schema-test-class.ts | 2 +- .../models/foo-get-default-response.ts | 2 +- .../builds/kebab-case/models/foo.ts | 2 +- .../builds/kebab-case/models/format-test.ts | 10 +- .../kebab-case/models/has-only-read-only.ts | 2 +- .../kebab-case/models/health-check-result.ts | 2 +- .../builds/kebab-case/models/list.ts | 2 +- .../builds/kebab-case/models/map-test.ts | 2 +- ...perties-and-additional-properties-class.ts | 6 +- .../kebab-case/models/model-api-response.ts | 2 +- .../builds/kebab-case/models/model-file.ts | 2 +- .../kebab-case/models/model200-response.ts | 2 +- .../builds/kebab-case/models/name.ts | 2 +- .../kebab-case/models/nullable-class.ts | 10 +- .../builds/kebab-case/models/number-only.ts | 2 +- .../models/object-with-deprecated-fields.ts | 2 +- .../builds/kebab-case/models/order.ts | 6 +- .../kebab-case/models/outer-composite.ts | 2 +- .../models/outer-object-with-enum-property.ts | 2 +- .../kebab-case/models/parent-with-nullable.ts | 2 +- .../builds/kebab-case/models/pet.ts | 2 +- .../kebab-case/models/read-only-first.ts | 2 +- .../builds/kebab-case/models/return.ts | 2 +- .../kebab-case/models/special-model-name.ts | 2 +- .../builds/kebab-case/models/tag.ts | 2 +- ...-freeform-additional-properties-request.ts | 2 +- .../builds/kebab-case/models/user.ts | 2 +- .../builds/kebab-case/runtime.ts | 38 +- .../multiple-parameters/models/Category.ts | 2 +- .../models/ModelApiResponse.ts | 2 +- .../multiple-parameters/models/Order.ts | 6 +- .../builds/multiple-parameters/models/Pet.ts | 2 +- .../builds/multiple-parameters/models/Tag.ts | 2 +- .../builds/multiple-parameters/models/User.ts | 2 +- .../builds/multiple-parameters/runtime.ts | 38 +- .../builds/oneOf/models/DashedOptionOne.ts | 2 +- .../builds/oneOf/models/DashedOptionTwo.ts | 2 +- .../oneOf/models/NumericSingletonEnumModel.ts | 2 +- .../builds/oneOf/models/OptionOne.ts | 2 +- .../builds/oneOf/models/OptionTwo.ts | 2 +- .../builds/oneOf/models/SnakeOptionOne.ts | 2 +- .../builds/oneOf/models/SnakeOptionTwo.ts | 2 +- .../builds/oneOf/models/TestA.ts | 2 +- .../builds/oneOf/models/TestArrayResponse.ts | 1 + .../builds/oneOf/models/TestB.ts | 2 +- .../models/TestDashedDiscriminatorResponse.ts | 1 + .../oneOf/models/TestDiscriminatorResponse.ts | 1 + .../builds/oneOf/models/TestResponse.ts | 1 + .../TestSnakeCaseDiscriminatorResponse.ts | 1 + .../typescript-fetch/builds/oneOf/runtime.ts | 38 +- .../src/models/Category.ts | 2 +- .../src/models/ModelApiResponse.ts | 2 +- .../src/models/Order.ts | 6 +- .../src/models/Pet.ts | 2 +- .../src/models/Tag.ts | 2 +- .../src/models/User.ts | 2 +- .../src/runtime.ts | 38 +- .../sagas-and-records/src/models/Category.ts | 2 +- .../src/models/DefaultMetaOnlyResponse.ts | 2 +- .../src/models/FindPetsByStatusResponse.ts | 2 +- .../src/models/FindPetsByUserResponse.ts | 2 +- .../models/GetBehaviorPermissionsResponse.ts | 2 +- .../src/models/GetBehaviorTypeResponse.ts | 2 +- .../src/models/GetMatchingPartsResponse.ts | 2 +- .../src/models/GetPetPartTypeResponse.ts | 2 +- .../sagas-and-records/src/models/ItemId.ts | 2 +- .../src/models/MatchingParts.ts | 2 +- .../src/models/ModelApiResponse.ts | 2 +- .../src/models/ModelError.ts | 2 +- .../sagas-and-records/src/models/Order.ts | 6 +- .../sagas-and-records/src/models/Part.ts | 2 +- .../sagas-and-records/src/models/Pet.ts | 2 +- .../src/models/PetRegionsResponse.ts | 2 +- .../src/models/ResponseMeta.ts | 2 +- .../sagas-and-records/src/models/Tag.ts | 2 +- .../sagas-and-records/src/models/User.ts | 2 +- .../builds/sagas-and-records/src/runtime.ts | 38 +- .../snakecase-discriminator/apis/FakeApi.ts | 4 +- .../models/AdditionalPropertiesClass.ts | 2 +- .../models/AllOfWithSingleRef.ts | 2 +- .../snakecase-discriminator/models/Animal.ts | 2 +- .../models/ArrayOfArrayOfNumberOnly.ts | 2 +- .../models/ArrayOfNumberOnly.ts | 2 +- .../models/ArrayTest.ts | 2 +- .../models/Capitalization.ts | 2 +- .../snakecase-discriminator/models/Cat.ts | 2 +- .../models/Category.ts | 2 +- .../models/ClassModel.ts | 2 +- .../snakecase-discriminator/models/Client.ts | 2 +- .../models/DeprecatedObject.ts | 2 +- .../snakecase-discriminator/models/Dog.ts | 2 +- .../models/EnumArrays.ts | 2 +- .../models/EnumTest.ts | 2 +- .../models/FakeBigDecimalMap200Response.ts | 2 +- .../models/FileSchemaTestClass.ts | 2 +- .../snakecase-discriminator/models/Foo.ts | 2 +- .../models/FooGetDefaultResponse.ts | 2 +- .../models/FormatTest.ts | 10 +- .../models/HasOnlyReadOnly.ts | 2 +- .../models/HealthCheckResult.ts | 2 +- .../snakecase-discriminator/models/List.ts | 2 +- .../snakecase-discriminator/models/MapTest.ts | 2 +- ...dPropertiesAndAdditionalPropertiesClass.ts | 6 +- .../models/Model200Response.ts | 2 +- .../models/ModelApiResponse.ts | 2 +- .../models/ModelFile.ts | 2 +- .../snakecase-discriminator/models/Name.ts | 2 +- .../models/NullableClass.ts | 10 +- .../models/NumberOnly.ts | 2 +- .../models/ObjectWithDeprecatedFields.ts | 2 +- .../snakecase-discriminator/models/Order.ts | 6 +- .../models/OuterComposite.ts | 2 +- .../models/OuterObjectWithEnumProperty.ts | 2 +- .../snakecase-discriminator/models/Pet.ts | 2 +- .../models/ReadOnlyFirst.ts | 2 +- .../snakecase-discriminator/models/Return.ts | 2 +- .../models/SpecialModelName.ts | 2 +- .../snakecase-discriminator/models/Tag.ts | 2 +- .../snakecase-discriminator/models/User.ts | 2 +- .../builds/snakecase-discriminator/runtime.ts | 38 +- .../validation-attributes/models/Category.ts | 2 +- .../models/ModelApiResponse.ts | 2 +- .../validation-attributes/models/Order.ts | 6 +- .../validation-attributes/models/Pet.ts | 2 +- .../validation-attributes/models/Tag.ts | 2 +- .../validation-attributes/models/User.ts | 2 +- .../builds/validation-attributes/runtime.ts | 38 +- .../builds/with-interfaces/models/Category.ts | 2 +- .../models/ModelApiResponse.ts | 2 +- .../builds/with-interfaces/models/Order.ts | 6 +- .../builds/with-interfaces/models/Pet.ts | 2 +- .../builds/with-interfaces/models/Tag.ts | 2 +- .../builds/with-interfaces/models/User.ts | 2 +- .../builds/with-interfaces/runtime.ts | 38 +- .../with-npm-version/src/models/Category.ts | 2 +- .../src/models/ModelApiResponse.ts | 2 +- .../with-npm-version/src/models/Order.ts | 6 +- .../builds/with-npm-version/src/models/Pet.ts | 2 +- .../builds/with-npm-version/src/models/Tag.ts | 2 +- .../with-npm-version/src/models/User.ts | 2 +- .../builds/with-npm-version/src/runtime.ts | 38 +- .../models/EnumPatternObject.ts | 2 +- .../FakeEnumRequestGetInline200Response.ts | 2 +- .../builds/with-string-enums/runtime.ts | 38 +- .../without-runtime-checks/src/runtime.ts | 14 +- 278 files changed, 3229 insertions(+), 312 deletions(-) create mode 100644 bin/configs/typescript-fetch-date-library-date.yaml create mode 100644 bin/configs/typescript-fetch-date-library-string.yaml create mode 100644 modules/openapi-generator/src/test/resources/3_0/typescript-fetch/date-handling.yaml create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-date/.openapi-generator-ignore create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-date/.openapi-generator/FILES create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-date/.openapi-generator/VERSION create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-date/apis/DefaultApi.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-date/apis/index.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-date/docs/DefaultApi.md create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-date/docs/Event.md create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-date/index.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-date/models/Event.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-date/models/index.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-date/runtime.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-string/.openapi-generator-ignore create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-string/.openapi-generator/FILES create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-string/.openapi-generator/VERSION create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-string/apis/DefaultApi.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-string/apis/index.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-string/docs/DefaultApi.md create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-string/docs/Event.md create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-string/index.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-string/models/Event.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-string/models/index.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-string/runtime.ts diff --git a/bin/configs/typescript-fetch-date-library-date.yaml b/bin/configs/typescript-fetch-date-library-date.yaml new file mode 100644 index 000000000000..9d8211cca853 --- /dev/null +++ b/bin/configs/typescript-fetch-date-library-date.yaml @@ -0,0 +1,6 @@ +generatorName: typescript-fetch +outputDir: samples/client/petstore/typescript-fetch/builds/date-library-date +inputSpec: modules/openapi-generator/src/test/resources/3_0/typescript-fetch/date-handling.yaml +templateDir: modules/openapi-generator/src/main/resources/typescript-fetch +additionalProperties: + dateLibrary: date diff --git a/bin/configs/typescript-fetch-date-library-string.yaml b/bin/configs/typescript-fetch-date-library-string.yaml new file mode 100644 index 000000000000..09299efa3cb9 --- /dev/null +++ b/bin/configs/typescript-fetch-date-library-string.yaml @@ -0,0 +1,6 @@ +generatorName: typescript-fetch +outputDir: samples/client/petstore/typescript-fetch/builds/date-library-string +inputSpec: modules/openapi-generator/src/test/resources/3_0/typescript-fetch/date-handling.yaml +templateDir: modules/openapi-generator/src/main/resources/typescript-fetch +additionalProperties: + dateLibrary: string diff --git a/docs/generators/typescript-fetch.md b/docs/generators/typescript-fetch.md index 37762fabc0d9..a51cfe50c40d 100644 --- a/docs/generators/typescript-fetch.md +++ b/docs/generators/typescript-fetch.md @@ -19,6 +19,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl | Option | Description | Values | Default | | ------ | ----------- | ------ | ------- | |allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false| +|dateLibrary|Option. Date library to use.|
**date**
Native Date. `format: date` and `format: date-time` are both mapped to Date and (de)serialized by the runtime.
**string**
Plain string. Values are passed through untouched, leaving date handling to the consumer.
|date| |disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|
**false**
The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
**true**
Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |enumNameSuffix|Suffix that will be appended to all enum names.| |Enum| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java index 5d9c7091ad49..d062caabd399 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java @@ -36,6 +36,8 @@ import org.openapitools.codegen.model.OperationsMap; import org.openapitools.codegen.templating.mustache.IndentedLambda; import org.openapitools.codegen.utils.ModelUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.util.*; @@ -52,11 +54,17 @@ *

Mustache templates are located in {@code src/main/resources/typescript-fetch/}. */ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodegen { + private final Logger LOGGER = LoggerFactory.getLogger(TypeScriptFetchClientCodegen.class); + public static final String NPM_REPOSITORY = "npmRepository"; public static final String WITH_INTERFACES = "withInterfaces"; public static final String USE_SINGLE_REQUEST_PARAMETER = "useSingleRequestParameter"; public static final String PREFIX_PARAMETER_INTERFACES = "prefixParameterInterfaces"; public static final String WITHOUT_RUNTIME_CHECKS = "withoutRuntimeChecks"; + public static final String DATE_LIBRARY = "dateLibrary"; + public static final String DATE_LIBRARY_DESC = "Option. Date library to use."; + public static final String DATE_LIBRARY_DATE = "date"; + public static final String DATE_LIBRARY_STRING = "string"; public static final String STRING_ENUMS = "stringEnums"; public static final String STRING_ENUMS_DESC = "Generate string enums instead of objects for enum values."; public static final String IMPORT_FILE_EXTENSION_SWITCH = "importFileExtension"; @@ -79,6 +87,7 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege protected boolean addedApiIndex = false; protected boolean addedModelIndex = false; protected boolean withoutRuntimeChecks = false; + protected String dateLibrary = DATE_LIBRARY_DATE; protected boolean stringEnums = false; protected String fileNaming = PASCAL_CASE; protected String apiDocPath = "docs"; @@ -134,6 +143,13 @@ public TypeScriptFetchClientCodegen() { this.cliOptions.add(new CliOption(CodegenConstants.USE_SINGLE_REQUEST_PARAMETER, CodegenConstants.USE_SINGLE_REQUEST_PARAMETER_DESC, SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.TRUE.toString())); this.cliOptions.add(new CliOption(PREFIX_PARAMETER_INTERFACES, "Setting this property to true will generate parameter interface declarations prefixed with API class name to avoid name conflicts.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(WITHOUT_RUNTIME_CHECKS, "Setting this property to true will remove any runtime checks on the request and response payloads. Payloads will be casted to their expected types.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); + + CliOption dateLibraryOption = new CliOption(DATE_LIBRARY, DATE_LIBRARY_DESC).defaultValue(this.getDateLibrary()); + Map dateOptions = new HashMap<>(); + dateOptions.put(DATE_LIBRARY_DATE, "Native Date. `format: date` and `format: date-time` are both mapped to Date and (de)serialized by the runtime."); + dateOptions.put(DATE_LIBRARY_STRING, "Plain string. Values are passed through untouched, leaving date handling to the consumer."); + dateLibraryOption.setEnum(dateOptions); + this.cliOptions.add(dateLibraryOption); this.cliOptions.add(new CliOption(SAGAS_AND_RECORDS, "Setting this property to true will generate additional files for use with redux-saga and immutablejs.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(STRING_ENUMS, STRING_ENUMS_DESC, SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(IMPORT_FILE_EXTENSION_SWITCH, IMPORT_FILE_EXTENSION_SWITCH_DESC).defaultValue("")); @@ -192,6 +208,14 @@ public void setWithoutRuntimeChecks(Boolean withoutRuntimeChecks) { this.withoutRuntimeChecks = withoutRuntimeChecks; } + public String getDateLibrary() { + return this.dateLibrary; + } + + public void setDateLibrary(String dateLibrary) { + this.dateLibrary = dateLibrary; + } + public Boolean getStringEnums() { return this.stringEnums; } @@ -306,11 +330,34 @@ public void processOpts() { this.setFileNaming(additionalProperties.get(FILE_NAMING).toString()); } + if (additionalProperties.containsKey(DATE_LIBRARY)) { + this.setDateLibrary(additionalProperties.get(DATE_LIBRARY).toString()); + } + if (!withoutRuntimeChecks) { this.modelTemplateFiles.put("models.mustache", ".ts"); + } + + // `date` needs the model (de)serialization to convert with, which + // withoutRuntimeChecks removes: the raw string would just be cast to Date. + if (withoutRuntimeChecks && DATE_LIBRARY_DATE.equals(this.dateLibrary)) { + if (additionalProperties.containsKey(DATE_LIBRARY)) { + LOGGER.warn("{}={} is not compatible with {}=true; falling back to {}={}.", + DATE_LIBRARY, DATE_LIBRARY_DATE, WITHOUT_RUNTIME_CHECKS, DATE_LIBRARY, DATE_LIBRARY_STRING); + } + this.dateLibrary = DATE_LIBRARY_STRING; + } + + if (DATE_LIBRARY_DATE.equals(this.dateLibrary)) { typeMapping.put("date", "Date"); typeMapping.put("DateTime", "Date"); + } else { + typeMapping.put("date", "string"); + typeMapping.put("DateTime", "string"); } + additionalProperties.put(DATE_LIBRARY, this.dateLibrary); + // Mustache cannot compare strings, so expose the selected library as a flag. + additionalProperties.put("isDateLibraryDate", DATE_LIBRARY_DATE.equals(this.dateLibrary)); if (additionalProperties.containsKey(SAGAS_AND_RECORDS)) { this.setSagasAndRecords(convertPropertyToBoolean(SAGAS_AND_RECORDS)); diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache index 97fb15df5253..d88cecad8505 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache @@ -272,9 +272,13 @@ export class {{classname}} extends runtime.BaseAPI { {{^isArray}} if (requestParameters['{{paramName}}'] != null) { {{#isDateTimeType}} - formParams.append('{{baseName}}', (requestParameters['{{paramName}}'] as any).toISOString()); + formParams.append('{{baseName}}', runtime.serializeDateTime(requestParameters['{{paramName}}'] as any)); {{/isDateTimeType}} {{^isDateTimeType}} + {{#isDateType}} + formParams.append('{{baseName}}', runtime.serializeDate(requestParameters['{{paramName}}'] as any)); + {{/isDateType}} + {{^isDateType}} {{#isPrimitiveType}} formParams.append('{{baseName}}', requestParameters['{{paramName}}'] as any); {{/isPrimitiveType}} @@ -295,6 +299,7 @@ export class {{classname}} extends runtime.BaseAPI { {{/withoutRuntimeChecks}} {{/isEnumRef}} {{/isPrimitiveType}} + {{/isDateType}} {{/isDateTimeType}} } @@ -306,7 +311,7 @@ export class {{classname}} extends runtime.BaseAPI { {{#pathParams}} {{#isDateTimeType}} if (requestParameters['{{paramName}}'] instanceof Date) { - urlPath = urlPath.replace({{=<< >>=}}'{<>}'<<={{ }}=>>, encodeURIComponent(requestParameters['{{paramName}}'].toISOString())); + urlPath = urlPath.replace({{=<< >>=}}'{<>}'<<={{ }}=>>, encodeURIComponent(runtime.serializeDateTime(requestParameters['{{paramName}}']))); } else { urlPath = urlPath.replace({{=<< >>=}}'{<>}'<<={{ }}=>>, encodeURIComponent(String(requestParameters['{{paramName}}']))); } @@ -314,7 +319,7 @@ export class {{classname}} extends runtime.BaseAPI { {{^isDateTimeType}} {{#isDateType}} if (requestParameters['{{paramName}}'] instanceof Date) { - urlPath = urlPath.replace({{=<< >>=}}'{<>}'<<={{ }}=>>, encodeURIComponent(requestParameters['{{paramName}}'].toISOString().substring(0,10))); + urlPath = urlPath.replace({{=<< >>=}}'{<>}'<<={{ }}=>>, encodeURIComponent(runtime.serializeDate(requestParameters['{{paramName}}']))); } else { urlPath = urlPath.replace({{=<< >>=}}'{<>}'<<={{ }}=>>, encodeURIComponent(String(requestParameters['{{paramName}}']))); } diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/apisAssignQueryParam.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/apisAssignQueryParam.mustache index 8da37374eea1..761528af2546 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/apisAssignQueryParam.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/apisAssignQueryParam.mustache @@ -1,10 +1,10 @@ {{! Assign query parameters based on their type }} {{#isDateTimeType}} - queryParameters['{{baseName}}'] = (requestParameters['{{paramName}}'] as any).toISOString(); + queryParameters['{{baseName}}'] = runtime.serializeDateTime(requestParameters['{{paramName}}'] as any); {{/isDateTimeType}} {{^isDateTimeType}} {{#isDateType}} - queryParameters['{{baseName}}'] = (requestParameters['{{paramName}}'] as any).toISOString().substring(0,10); + queryParameters['{{baseName}}'] = runtime.serializeDate(requestParameters['{{paramName}}'] as any); {{/isDateType}} {{^isDateType}} queryParameters['{{baseName}}'] = requestParameters['{{paramName}}']; diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache index 5f4c379724b1..179dd3abea2e 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache @@ -1,4 +1,4 @@ -import { mapValues } from '../runtime{{importFileExtension}}'; +import { mapValues{{#isDateLibraryDate}}, parseDate, parseDateTime, serializeDate, serializeDateTime{{/isDateLibraryDate}} } from '../runtime{{importFileExtension}}'; {{#hasImports}} {{#tsImports}} import type { {{{classname}}} } from './{{filename}}{{importFileExtension}}'; @@ -98,10 +98,10 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole {{/isArray}} {{^isArray}} {{#isDateType}} - '{{name}}': {{^required}}{{#isNullable}}json['{{baseName}}'] === undefined ? undefined : json['{{baseName}}'] === null ? null : {{/isNullable}}{{^isNullable}}json['{{baseName}}'] == null ? undefined : {{/isNullable}}{{/required}}({{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}{{/required}}new Date(json['{{baseName}}'])), + '{{name}}': {{^required}}{{#isNullable}}json['{{baseName}}'] === undefined ? undefined : json['{{baseName}}'] === null ? null : {{/isNullable}}{{^isNullable}}json['{{baseName}}'] == null ? undefined : {{/isNullable}}{{/required}}({{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}{{/required}}parseDate(json['{{baseName}}'])), {{/isDateType}} {{#isDateTimeType}} - '{{name}}': {{^required}}{{#isNullable}}json['{{baseName}}'] === undefined ? undefined : json['{{baseName}}'] === null ? null : {{/isNullable}}{{^isNullable}}json['{{baseName}}'] == null ? undefined : {{/isNullable}}{{/required}}({{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}{{/required}}new Date(json['{{baseName}}'])), + '{{name}}': {{^required}}{{#isNullable}}json['{{baseName}}'] === undefined ? undefined : json['{{baseName}}'] === null ? null : {{/isNullable}}{{^isNullable}}json['{{baseName}}'] == null ? undefined : {{/isNullable}}{{/required}}({{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}{{/required}}parseDateTime(json['{{baseName}}'])), {{/isDateTimeType}} {{^isDateType}} {{^isDateTimeType}} @@ -173,10 +173,10 @@ export function {{classname}}ToJSONTyped(value?: {{#hasReadOnly}}Omit<{{classnam {{^isReadOnly}} {{#isPrimitiveType}} {{#isDateType}} - '{{baseName}}': {{^required}}value['{{name}}'] == null ? value['{{name}}'] : {{/required}}{{#isNullable}}{{#required}}value['{{name}}'] == null ? value['{{name}}'] : {{/required}}{{/isNullable}}value['{{name}}'].toISOString().substring(0,10), + '{{baseName}}': {{^required}}value['{{name}}'] == null ? value['{{name}}'] : {{/required}}{{#isNullable}}{{#required}}value['{{name}}'] == null ? value['{{name}}'] : {{/required}}{{/isNullable}}serializeDate(value['{{name}}']), {{/isDateType}} {{#isDateTimeType}} - '{{baseName}}': {{^required}}value['{{name}}'] == null ? value['{{name}}'] : {{/required}}{{#isNullable}}{{#required}}value['{{name}}'] == null ? value['{{name}}'] : {{/required}}{{/isNullable}}value['{{name}}'].toISOString(), + '{{baseName}}': {{^required}}value['{{name}}'] == null ? value['{{name}}'] : {{/required}}{{#isNullable}}{{#required}}value['{{name}}'] == null ? value['{{name}}'] : {{/required}}{{/isNullable}}serializeDateTime(value['{{name}}']), {{/isDateTimeType}} {{#isArray}} '{{baseName}}': {{#uniqueItems}}{{^required}}value['{{name}}'] == null ? undefined : {{/required}}{{#required}}{{#isNullable}}value['{{name}}'] == null ? null : {{/isNullable}}{{/required}}Array.from(value['{{name}}'] as Set){{/uniqueItems}}{{^uniqueItems}}value['{{name}}']{{/uniqueItems}}, diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache index 7017451090f8..4d2f4ce40baa 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache @@ -1,3 +1,6 @@ +{{#isDateLibraryDate}} +import { parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime{{importFileExtension}}'; +{{/isDateLibraryDate}} {{#hasImports}} {{#oneOfArrays}} import type { {{{.}}} } from './{{.}}{{importFileExtension}}'; @@ -70,14 +73,14 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole {{#isDateType}} if (Array.isArray(json)) { if (json.every(item => !(isNaN(new Date(item).getTime())))) { - return json.map(value => new Date(value)); + return json.map(value => parseDate(value)); } } {{/isDateType}} {{#isDateTimeType}} if (Array.isArray(json)) { if (json.every(item => !(isNaN(new Date(item).getTime())))) { - return json.map(value => new Date(value)); + return json.map(value => parseDateTime(value)); } } {{/isDateTimeType}} @@ -116,13 +119,13 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole {{^isArray}} {{#isDateType}} if (!(isNaN(new Date(json).getTime()))) { - return {{^required}}json == null ? undefined : {{/required}}({{#required}}{{#isNullable}}json == null ? null : {{/isNullable}}{{/required}}new Date(json)); + return {{^required}}json == null ? undefined : {{/required}}({{#required}}{{#isNullable}}json == null ? null : {{/isNullable}}{{/required}}parseDate(json)); } {{/isDateType}} {{^isDateType}} {{#isDateTimeType}} if (!(isNaN(new Date(json).getTime()))) { - return {{^required}}json == null ? undefined : {{/required}}({{#required}}{{#isNullable}}json == null ? null : {{/isNullable}}{{/required}}new Date(json)); + return {{^required}}json == null ? undefined : {{/required}}({{#required}}{{#isNullable}}json == null ? null : {{/isNullable}}{{/required}}parseDateTime(json)); } {{/isDateTimeType}} {{/isDateType}} @@ -195,14 +198,14 @@ export function {{classname}}ToJSONTyped(value?: {{classname}} | null, ignoreDis {{#isDateType}} if (Array.isArray(value)) { if (value.every(item => item instanceof Date)) { - return value.map(value => value.toISOString().substring(0,10)); + return value.map(value => serializeDate(value)); } } {{/isDateType}} {{#isDateTimeType}} if (Array.isArray(value)) { if (value.every(item => item instanceof Date)) { - return value.map(item => item.toISOString()); + return value.map(item => serializeDateTime(item)); } } {{/isDateTimeType}} @@ -241,12 +244,12 @@ export function {{classname}}ToJSONTyped(value?: {{classname}} | null, ignoreDis {{^isArray}} {{#isDateType}} if (value instanceof Date) { - return ((value{{#isNullable}} as any{{/isNullable}}){{^required}}{{#isNullable}}?{{/isNullable}}{{/required}}.toISOString().substring(0,10)); + return (serializeDate(value{{#isNullable}} as any{{/isNullable}})); } {{/isDateType}} {{#isDateTimeType}} if (value instanceof Date) { - return {{^required}}{{#isNullable}}value === null ? null : {{/isNullable}}{{^isNullable}}value == null ? undefined : {{/isNullable}}{{/required}}((value{{#isNullable}} as any{{/isNullable}}){{^required}}{{#isNullable}}?{{/isNullable}}{{/required}}.toISOString()); + return {{^required}}{{#isNullable}}value === null ? null : {{/isNullable}}{{^isNullable}}value == null ? undefined : {{/isNullable}}{{/required}}(serializeDateTime(value{{#isNullable}} as any{{/isNullable}})); } {{/isDateTimeType}} {{#isNumeric}} diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache index 235458a2df2f..c924ce3d0092 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache @@ -336,7 +336,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -349,6 +349,44 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +{{#isDateLibraryDate}} +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} +{{/isDateLibraryDate}} + {{^withoutRuntimeChecks}} export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/TypeScriptFetchClientOptionsProvider.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/TypeScriptFetchClientOptionsProvider.java index a6bccce568cb..9b35b5074d35 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/TypeScriptFetchClientOptionsProvider.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/TypeScriptFetchClientOptionsProvider.java @@ -31,6 +31,7 @@ public class TypeScriptFetchClientOptionsProvider implements TypeScriptSharedCli public static final String SAGAS_AND_RECORDS = "false"; 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; @Override @@ -50,6 +51,7 @@ public Map createOptions() { .put(TypeScriptFetchClientCodegen.SAGAS_AND_RECORDS, SAGAS_AND_RECORDS) .put(TypeScriptFetchClientCodegen.IMPORT_FILE_EXTENSION_SWITCH, IMPORT_FILE_EXTENSION_VALUE) .put(TypeScriptFetchClientCodegen.FILE_NAMING, FILE_NAMING_VALUE) + .put(TypeScriptFetchClientCodegen.DATE_LIBRARY, DATE_LIBRARY_VALUE) .put(TypeScriptFetchClientCodegen.STRING_ENUMS, STRING_ENUMS) .put(TypeScriptFetchClientCodegen.USE_SQUARE_BRACKETS_IN_ARRAY_NAMES, Boolean.FALSE.toString()) .put(TypeScriptFetchClientCodegen.VALIDATION_ATTRIBUTES, Boolean.FALSE.toString()) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java index 0ba3cd8a5305..12039840eef3 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java @@ -765,6 +765,86 @@ private static File generate( ); } + @Test(description = "Verify dateLibrary=date (the default) maps date and date-time to Date and converts them through the runtime helpers") + public void testDateLibraryDateIsTheDefault() throws IOException { + File output = generate(new HashMap<>(), DATE_HANDLING_SPEC); + + Path event = Paths.get(output + "/models/Event.ts"); + TestUtils.assertFileContains(event, "startsOn: Date;"); + TestUtils.assertFileContains(event, "createdAt?: Date;"); + TestUtils.assertFileContains(event, "'startsOn': (parseDate(json['startsOn']))"); + TestUtils.assertFileContains(event, "'createdAt': json['createdAt'] == null ? undefined : (parseDateTime(json['createdAt']))"); + TestUtils.assertFileContains(event, "'startsOn': serializeDate(value['startsOn'])"); + + Path runtime = Paths.get(output + "/runtime.ts"); + TestUtils.assertFileContains(runtime, "export function parseDate("); + TestUtils.assertFileContains(runtime, "export function parseDateTime("); + } + + @Test(description = "Verify dateLibrary=string leaves date values untouched as strings") + public void testDateLibraryString() throws IOException { + Map properties = new HashMap<>(); + properties.put(TypeScriptFetchClientCodegen.DATE_LIBRARY, TypeScriptFetchClientCodegen.DATE_LIBRARY_STRING); + + File output = generate(properties, DATE_HANDLING_SPEC); + + Path event = Paths.get(output + "/models/Event.ts"); + TestUtils.assertFileContains(event, "startsOn: string;"); + TestUtils.assertFileContains(event, "createdAt?: string;"); + TestUtils.assertFileContains(event, "'startsOn': json['startsOn'],"); + TestUtils.assertFileNotContains(event, "parseDate"); + TestUtils.assertFileNotContains(event, "serializeDate"); + + // Only the helper querystring needs is emitted. + Path runtime = Paths.get(output + "/runtime.ts"); + TestUtils.assertFileNotContains(runtime, "export function parseDate("); + TestUtils.assertFileNotContains(runtime, "export function parseDateTime("); + TestUtils.assertFileNotContains(runtime, "export function serializeDate("); + TestUtils.assertFileContains(runtime, "export function serializeDateTime("); + } + + @Test(description = "Verify withoutRuntimeChecks forces dateLibrary=string, since there is no model code left to convert with") + public void testDateLibraryDateFallsBackToStringWithoutRuntimeChecks() throws IOException { + Map properties = new HashMap<>(); + properties.put(TypeScriptFetchClientCodegen.WITHOUT_RUNTIME_CHECKS, true); + properties.put(TypeScriptFetchClientCodegen.DATE_LIBRARY, TypeScriptFetchClientCodegen.DATE_LIBRARY_DATE); + + File output = generate(properties, DATE_HANDLING_SPEC); + + Path modelsIndex = Paths.get(output + "/models/index.ts"); + TestUtils.assertFileContains(modelsIndex, "startsOn: string;"); + TestUtils.assertFileNotContains(modelsIndex, "startsOn: Date;"); + } + + @Test(description = "Verify format: date is serialized as a calendar date in every parameter location, not as a date-time") + public void testDateFormatIsSerializedAsACalendarDate() throws IOException { + File output = generate(new HashMap<>(), DATE_HANDLING_SPEC); + + Path api = Paths.get(output + "/apis/DefaultApi.ts"); + TestUtils.assertFileContains(api, "urlPath.replace('{onDate}', encodeURIComponent(runtime.serializeDate(requestParameters['onDate'])))"); + TestUtils.assertFileContains(api, "queryParameters['from'] = runtime.serializeDate(requestParameters['from'] as any)"); + TestUtils.assertFileContains(api, "formParams.append('startsOn', runtime.serializeDate(requestParameters['startsOn'] as any))"); + // date-time keeps the full timestamp. + TestUtils.assertFileContains(api, "queryParameters['updatedSince'] = runtime.serializeDateTime(requestParameters['updatedSince'] as any)"); + TestUtils.assertFileContains(api, "formParams.append('createdAt', runtime.serializeDateTime(requestParameters['createdAt'] as any))"); + } + + @Test(description = "Verify a calendar date is (de)serialized against the local calendar, so it cannot shift by a day") + public void testDateFormatUsesTheLocalCalendar() throws IOException { + File output = generate(new HashMap<>(), DATE_HANDLING_SPEC); + + Path runtime = Paths.get(output + "/runtime.ts"); + // A calendar date is converted against the local calendar on both ends. + TestUtils.assertFileContains(runtime, "value.getFullYear()"); + TestUtils.assertFileContains(runtime, "value.getMonth() + 1"); + TestUtils.assertFileContains(runtime, "value.getDate()"); + TestUtils.assertFileContains(runtime, "new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3]))"); + // A date-time is a genuine instant and stays UTC. + TestUtils.assertFileContains(runtime, "export function serializeDateTime(value: Date): string {\n return value.toISOString();"); + } + + private static final String DATE_HANDLING_SPEC = "src/test/resources/3_0/typescript-fetch/date-handling.yaml"; + private static File generate( Map properties, String inputSpec diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientOptionsTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientOptionsTest.java index c44b33dbd4c1..711e09fcf993 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientOptionsTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientOptionsTest.java @@ -55,6 +55,7 @@ protected void verifyOptions() { verify(clientCodegen).setEnumUnknownDefaultCase(Boolean.parseBoolean(TypeScriptFetchClientOptionsProvider.ENUM_UNKNOWN_DEFAULT_CASE_VALUE)); verify(clientCodegen).setStringEnums(Boolean.parseBoolean(TypeScriptFetchClientOptionsProvider.STRING_ENUMS)); verify(clientCodegen).setFileNaming(TypeScriptFetchClientOptionsProvider.FILE_NAMING_VALUE); + verify(clientCodegen).setDateLibrary(TypeScriptFetchClientOptionsProvider.DATE_LIBRARY_VALUE); } @Test(description = "Verify if an exception is thrown when invalid values are used with fileNaming option") diff --git a/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/date-handling.yaml b/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/date-handling.yaml new file mode 100644 index 000000000000..13310dd54a98 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/date-handling.yaml @@ -0,0 +1,81 @@ +openapi: 3.0.3 +info: + title: Date handling + description: > + Covers every location a `format: date` or `format: date-time` value can appear in, + so the generated (de)serialization can be checked in one place. + version: 1.0.0 +paths: + /events/{onDate}: + get: + operationId: listEvents + parameters: + - name: onDate + in: path + required: true + schema: + type: string + format: date + - name: from + in: query + required: false + schema: + type: string + format: date + - name: updatedSince + in: query + required: false + schema: + type: string + format: date-time + responses: + '200': + description: matching events + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Event' + /events: + post: + operationId: createEvent + requestBody: + required: true + content: + application/x-www-form-urlencoded: + schema: + type: object + required: + - startsOn + properties: + startsOn: + type: string + format: date + createdAt: + type: string + format: date-time + responses: + '200': + description: the created event + content: + application/json: + schema: + $ref: '#/components/schemas/Event' +components: + schemas: + Event: + type: object + required: + - startsOn + properties: + startsOn: + type: string + format: date + endsOn: + type: string + format: date + nullable: true + createdAt: + type: string + format: date-time diff --git a/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/models/StructuredType.ts b/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/models/StructuredType.ts index 94b6f81cb4f8..c7f531833a02 100644 --- a/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/models/StructuredType.ts +++ b/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/models/StructuredType.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/runtime.ts b/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/runtime.ts index cc66cbfbb3af..e9933dda1ed6 100644 --- a/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/runtime.ts +++ b/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/others/typescript-fetch/infinite-recursion-issue/models/ExtendDto.ts b/samples/client/others/typescript-fetch/infinite-recursion-issue/models/ExtendDto.ts index bb02cb69bb26..8c0bee13c964 100644 --- a/samples/client/others/typescript-fetch/infinite-recursion-issue/models/ExtendDto.ts +++ b/samples/client/others/typescript-fetch/infinite-recursion-issue/models/ExtendDto.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { TestBaseDto } from './TestBaseDto'; import { TestBaseDtoFromJSON, diff --git a/samples/client/others/typescript-fetch/infinite-recursion-issue/models/TestBaseDto.ts b/samples/client/others/typescript-fetch/infinite-recursion-issue/models/TestBaseDto.ts index e2db40b1d1fb..9fa917190e0a 100644 --- a/samples/client/others/typescript-fetch/infinite-recursion-issue/models/TestBaseDto.ts +++ b/samples/client/others/typescript-fetch/infinite-recursion-issue/models/TestBaseDto.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { TestObjectType } from './TestObjectType'; import { TestObjectTypeFromJSON, diff --git a/samples/client/others/typescript-fetch/infinite-recursion-issue/runtime.ts b/samples/client/others/typescript-fetch/infinite-recursion-issue/runtime.ts index cc66cbfbb3af..e9933dda1ed6 100644 --- a/samples/client/others/typescript-fetch/infinite-recursion-issue/runtime.ts +++ b/samples/client/others/typescript-fetch/infinite-recursion-issue/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/others/typescript-fetch/multipart-file-array/runtime.ts b/samples/client/others/typescript-fetch/multipart-file-array/runtime.ts index a49c6563b888..1b967e470251 100644 --- a/samples/client/others/typescript-fetch/multipart-file-array/runtime.ts +++ b/samples/client/others/typescript-fetch/multipart-file-array/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/others/typescript-fetch/self-import-issue/models/AbstractUserDto.ts b/samples/client/others/typescript-fetch/self-import-issue/models/AbstractUserDto.ts index 23066259cb7f..927bc428edd3 100644 --- a/samples/client/others/typescript-fetch/self-import-issue/models/AbstractUserDto.ts +++ b/samples/client/others/typescript-fetch/self-import-issue/models/AbstractUserDto.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { BranchDto } from './BranchDto'; import { BranchDtoFromJSON, diff --git a/samples/client/others/typescript-fetch/self-import-issue/models/BranchDto.ts b/samples/client/others/typescript-fetch/self-import-issue/models/BranchDto.ts index 4d13f44c2bc1..ace44d0ae1e2 100644 --- a/samples/client/others/typescript-fetch/self-import-issue/models/BranchDto.ts +++ b/samples/client/others/typescript-fetch/self-import-issue/models/BranchDto.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/others/typescript-fetch/self-import-issue/models/InternalAuthenticatedUserDto.ts b/samples/client/others/typescript-fetch/self-import-issue/models/InternalAuthenticatedUserDto.ts index 7a8e69f01231..5a1ccee22848 100644 --- a/samples/client/others/typescript-fetch/self-import-issue/models/InternalAuthenticatedUserDto.ts +++ b/samples/client/others/typescript-fetch/self-import-issue/models/InternalAuthenticatedUserDto.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { BranchDto } from './BranchDto'; import { BranchDtoFromJSON, diff --git a/samples/client/others/typescript-fetch/self-import-issue/models/RemoteAuthenticatedUserDto.ts b/samples/client/others/typescript-fetch/self-import-issue/models/RemoteAuthenticatedUserDto.ts index 4fb8c1916e9d..f990ee3d4f11 100644 --- a/samples/client/others/typescript-fetch/self-import-issue/models/RemoteAuthenticatedUserDto.ts +++ b/samples/client/others/typescript-fetch/self-import-issue/models/RemoteAuthenticatedUserDto.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { BranchDto } from './BranchDto'; import { BranchDtoFromJSON, diff --git a/samples/client/others/typescript-fetch/self-import-issue/runtime.ts b/samples/client/others/typescript-fetch/self-import-issue/runtime.ts index 8aa237368f4f..cb20dffe2f40 100644 --- a/samples/client/others/typescript-fetch/self-import-issue/runtime.ts +++ b/samples/client/others/typescript-fetch/self-import-issue/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Club.ts b/samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Club.ts index 579fd800b866..beecc3937597 100644 --- a/samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Club.ts +++ b/samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Club.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Owner } from './Owner'; import { OwnerFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Owner.ts b/samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Owner.ts index 941eecf56afd..2408d376a530 100644 --- a/samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Owner.ts +++ b/samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Owner.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/allOf-nullable/runtime.ts b/samples/client/petstore/typescript-fetch/builds/allOf-nullable/runtime.ts index a9a8ee84339c..33828f4d6982 100644 --- a/samples/client/petstore/typescript-fetch/builds/allOf-nullable/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/allOf-nullable/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Club.ts b/samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Club.ts index c1b72486407c..e83ab530b58b 100644 --- a/samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Club.ts +++ b/samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Club.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Owner } from './Owner'; import { OwnerFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Owner.ts b/samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Owner.ts index 941eecf56afd..2408d376a530 100644 --- a/samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Owner.ts +++ b/samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Owner.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/allOf-readonly/runtime.ts b/samples/client/petstore/typescript-fetch/builds/allOf-readonly/runtime.ts index a9a8ee84339c..33828f4d6982 100644 --- a/samples/client/petstore/typescript-fetch/builds/allOf-readonly/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/allOf-readonly/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/.openapi-generator-ignore b/samples/client/petstore/typescript-fetch/builds/date-library-date/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/.openapi-generator/FILES b/samples/client/petstore/typescript-fetch/builds/date-library-date/.openapi-generator/FILES new file mode 100644 index 000000000000..354f25e5cfda --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/.openapi-generator/FILES @@ -0,0 +1,8 @@ +apis/DefaultApi.ts +apis/index.ts +docs/DefaultApi.md +docs/Event.md +index.ts +models/Event.ts +models/index.ts +runtime.ts diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/.openapi-generator/VERSION b/samples/client/petstore/typescript-fetch/builds/date-library-date/.openapi-generator/VERSION new file mode 100644 index 000000000000..8fc8df61083a --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.25.0-SNAPSHOT diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/apis/DefaultApi.ts b/samples/client/petstore/typescript-fetch/builds/date-library-date/apis/DefaultApi.ts new file mode 100644 index 000000000000..879209121093 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/apis/DefaultApi.ts @@ -0,0 +1,173 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Date handling + * Covers every location a `format: date` or `format: date-time` value can appear in, so the generated (de)serialization can be checked in one place. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import * as runtime from '../runtime'; +import { + type Event, + EventFromJSON, + EventToJSON, +} from '../models/Event'; + +export interface CreateEventRequest { + /** + * + */ + startsOn: Date; + /** + * + */ + createdAt?: Date; +} + +export interface ListEventsRequest { + /** + * + */ + onDate: Date; + /** + * + */ + from?: Date; + /** + * + */ + updatedSince?: Date; +} + +/** + * + */ +export class DefaultApi extends runtime.BaseAPI { + + /** + * Creates request options for createEvent without sending the request + */ + async createEventRequestOpts(requestParameters: CreateEventRequest): Promise { + if (requestParameters['startsOn'] == null) { + throw new runtime.RequiredError( + 'startsOn', + 'Required parameter "startsOn" was null or undefined when calling createEvent().' + ); + } + + const queryParameters: any = {}; + + const headerParameters: runtime.HTTPHeaders = {}; + + const consumes: runtime.Consume[] = [ + { contentType: 'application/x-www-form-urlencoded' }, + ]; + // @ts-ignore: canConsumeForm may be unused + const canConsumeForm = runtime.canConsumeForm(consumes); + + let formParams: { append(param: string, value: any): any }; + let useForm = false; + if (useForm) { + formParams = new FormData(); + } else { + formParams = new URLSearchParams(); + } + + if (requestParameters['startsOn'] != null) { + formParams.append('startsOn', runtime.serializeDate(requestParameters['startsOn'] as any)); + } + + if (requestParameters['createdAt'] != null) { + formParams.append('createdAt', runtime.serializeDateTime(requestParameters['createdAt'] as any)); + } + + + let urlPath = `/events`; + + return { + path: urlPath, + method: 'POST', + headers: headerParameters, + query: queryParameters, + body: formParams, + }; + } + + /** + */ + async createEventRaw(requestParameters: CreateEventRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { + const requestOptions = await this.createEventRequestOpts(requestParameters); + const response = await this.request(requestOptions, initOverrides); + + return new runtime.JSONApiResponse(response, (jsonValue) => EventFromJSON(jsonValue)); + } + + /** + */ + async createEvent(requestParameters: CreateEventRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { + const response = await this.createEventRaw(requestParameters, initOverrides); + return await response.value(); + } + + /** + * Creates request options for listEvents without sending the request + */ + async listEventsRequestOpts(requestParameters: ListEventsRequest): Promise { + if (requestParameters['onDate'] == null) { + throw new runtime.RequiredError( + 'onDate', + 'Required parameter "onDate" was null or undefined when calling listEvents().' + ); + } + + const queryParameters: any = {}; + + if (requestParameters['from'] != null) { + queryParameters['from'] = runtime.serializeDate(requestParameters['from'] as any); + } + + if (requestParameters['updatedSince'] != null) { + queryParameters['updatedSince'] = runtime.serializeDateTime(requestParameters['updatedSince'] as any); + } + + const headerParameters: runtime.HTTPHeaders = {}; + + + let urlPath = `/events/{onDate}`; + if (requestParameters['onDate'] instanceof Date) { + urlPath = urlPath.replace('{onDate}', encodeURIComponent(runtime.serializeDate(requestParameters['onDate']))); + } else { + urlPath = urlPath.replace('{onDate}', encodeURIComponent(String(requestParameters['onDate']))); + } + + return { + path: urlPath, + method: 'GET', + headers: headerParameters, + query: queryParameters, + }; + } + + /** + */ + async listEventsRaw(requestParameters: ListEventsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise>> { + const requestOptions = await this.listEventsRequestOpts(requestParameters); + const response = await this.request(requestOptions, initOverrides); + + return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map(EventFromJSON)); + } + + /** + */ + async listEvents(requestParameters: ListEventsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { + const response = await this.listEventsRaw(requestParameters, initOverrides); + return await response.value(); + } + +} diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/apis/index.ts b/samples/client/petstore/typescript-fetch/builds/date-library-date/apis/index.ts new file mode 100644 index 000000000000..69c44c00fa0d --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/apis/index.ts @@ -0,0 +1,3 @@ +/* tslint:disable */ +/* eslint-disable */ +export * from './DefaultApi'; diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/docs/DefaultApi.md b/samples/client/petstore/typescript-fetch/builds/date-library-date/docs/DefaultApi.md new file mode 100644 index 000000000000..a2462430db73 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/docs/DefaultApi.md @@ -0,0 +1,149 @@ +# DefaultApi + +All URIs are relative to *http://localhost* + +| Method | HTTP request | Description | +|------------- | ------------- | -------------| +| [**createEvent**](DefaultApi.md#createevent) | **POST** /events | | +| [**listEvents**](DefaultApi.md#listevents) | **GET** /events/{onDate} | | + + + +## createEvent + +> Event createEvent(startsOn, createdAt) + + + +### Example + +```ts +import { + Configuration, + DefaultApi, +} from ''; +import type { CreateEventRequest } from ''; + +async function example() { + console.log("🚀 Testing SDK..."); + const api = new DefaultApi(); + + const body = { + // Date + startsOn: 2013-10-20, + // Date (optional) + createdAt: 2013-10-20T19:20:30+01:00, + } satisfies CreateEventRequest; + + try { + const data = await api.createEvent(body); + console.log(data); + } catch (error) { + console.error(error); + } +} + +// Run the test +example().catch(console.error); +``` + +### Parameters + + +| Name | Type | Description | Notes | +|------------- | ------------- | ------------- | -------------| +| **startsOn** | `Date` | | [Defaults to `undefined`] | +| **createdAt** | `Date` | | [Optional] [Defaults to `undefined`] | + +### Return type + +[**Event**](Event.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/x-www-form-urlencoded` +- **Accept**: `application/json` + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | the created event | - | + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + +## listEvents + +> Array<Event> listEvents(onDate, from, updatedSince) + + + +### Example + +```ts +import { + Configuration, + DefaultApi, +} from ''; +import type { ListEventsRequest } from ''; + +async function example() { + console.log("🚀 Testing SDK..."); + const api = new DefaultApi(); + + const body = { + // Date + onDate: 2013-10-20, + // Date (optional) + from: 2013-10-20, + // Date (optional) + updatedSince: 2013-10-20T19:20:30+01:00, + } satisfies ListEventsRequest; + + try { + const data = await api.listEvents(body); + console.log(data); + } catch (error) { + console.error(error); + } +} + +// Run the test +example().catch(console.error); +``` + +### Parameters + + +| Name | Type | Description | Notes | +|------------- | ------------- | ------------- | -------------| +| **onDate** | `Date` | | [Defaults to `undefined`] | +| **from** | `Date` | | [Optional] [Defaults to `undefined`] | +| **updatedSince** | `Date` | | [Optional] [Defaults to `undefined`] | + +### Return type + +[**Array<Event>**](Event.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: `application/json` + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | matching events | - | + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/docs/Event.md b/samples/client/petstore/typescript-fetch/builds/date-library-date/docs/Event.md new file mode 100644 index 000000000000..90869c4e773f --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/docs/Event.md @@ -0,0 +1,38 @@ + +# Event + + +## Properties + +Name | Type +------------ | ------------- +`startsOn` | Date +`endsOn` | Date +`createdAt` | Date + +## Example + +```typescript +import type { Event } from '' + +// TODO: Update the object below with actual values +const example = { + "startsOn": null, + "endsOn": null, + "createdAt": null, +} satisfies Event + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as Event +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/index.ts b/samples/client/petstore/typescript-fetch/builds/date-library-date/index.ts new file mode 100644 index 000000000000..bebe8bbbe206 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/index.ts @@ -0,0 +1,5 @@ +/* tslint:disable */ +/* eslint-disable */ +export * from './runtime'; +export * from './apis/index'; +export * from './models/index'; diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/models/Event.ts b/samples/client/petstore/typescript-fetch/builds/date-library-date/models/Event.ts new file mode 100644 index 000000000000..6cdf9c513772 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/models/Event.ts @@ -0,0 +1,76 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Date handling + * Covers every location a `format: date` or `format: date-time` value can appear in, so the generated (de)serialization can be checked in one place. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +/** + * + * @export + * @interface Event + */ +export interface Event { + /** + * + */ + startsOn: Date; + /** + * + */ + endsOn?: Date | null; + /** + * + */ + createdAt?: Date; +} + +/** + * Check if a given object implements the Event interface. + */ +export function instanceOfEvent(value: object): value is Event { + if (!('startsOn' in value) || value['startsOn'] === undefined) return false; + return true; +} + +export function EventFromJSON(json: any): Event { + return EventFromJSONTyped(json, false); +} + +export function EventFromJSONTyped(json: any, ignoreDiscriminator: boolean): Event { + if (json == null) { + return json; + } + return { + + 'startsOn': (parseDate(json['startsOn'])), + 'endsOn': json['endsOn'] === undefined ? undefined : json['endsOn'] === null ? null : (parseDate(json['endsOn'])), + 'createdAt': json['createdAt'] == null ? undefined : (parseDateTime(json['createdAt'])), + }; +} + +export function EventToJSON(json: any): Event { + return EventToJSONTyped(json, false); +} + +export function EventToJSONTyped(value?: Event | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'startsOn': serializeDate(value['startsOn']), + 'endsOn': value['endsOn'] == null ? value['endsOn'] : serializeDate(value['endsOn']), + 'createdAt': value['createdAt'] == null ? value['createdAt'] : serializeDateTime(value['createdAt']), + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/models/index.ts b/samples/client/petstore/typescript-fetch/builds/date-library-date/models/index.ts new file mode 100644 index 000000000000..309b5bb56aa3 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/models/index.ts @@ -0,0 +1,3 @@ +/* tslint:disable */ +/* eslint-disable */ +export * from './Event'; diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/runtime.ts b/samples/client/petstore/typescript-fetch/builds/date-library-date/runtime.ts new file mode 100644 index 000000000000..e4c71201833c --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/runtime.ts @@ -0,0 +1,490 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Date handling + * Covers every location a `format: date` or `format: date-time` value can appear in, so the generated (de)serialization can be checked in one place. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +export const BASE_PATH = "http://localhost".replace(/\/+$/, ""); + +export interface ConfigurationParameters { + basePath?: string; // override base path + fetchApi?: FetchAPI; // override for fetch implementation + middleware?: Middleware[]; // middleware to apply before/after fetch requests + queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings + username?: string; // parameter for basic security + password?: string; // parameter for basic security + apiKey?: string | Promise | ((name: string) => string | Promise); // parameter for apiKey security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security + headers?: HTTPHeaders; //header params we want to use on every request + credentials?: RequestCredentials; //value for the credentials param we want to use on each request +} + +export class Configuration { + constructor(private configuration: ConfigurationParameters = {}) {} + + set config(configuration: Configuration) { + this.configuration = configuration; + } + + get basePath(): string { + return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH; + } + + get fetchApi(): FetchAPI | undefined { + return this.configuration.fetchApi; + } + + get middleware(): Middleware[] { + return this.configuration.middleware || []; + } + + get queryParamsStringify(): (params: HTTPQuery) => string { + return this.configuration.queryParamsStringify || querystring; + } + + get username(): string | undefined { + return this.configuration.username; + } + + get password(): string | undefined { + return this.configuration.password; + } + + get apiKey(): ((name: string) => string | Promise) | undefined { + const apiKey = this.configuration.apiKey; + if (apiKey) { + return typeof apiKey === 'function' ? apiKey : () => apiKey; + } + return undefined; + } + + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { + const accessToken = this.configuration.accessToken; + if (accessToken) { + return typeof accessToken === 'function' ? accessToken : async () => accessToken; + } + return undefined; + } + + get headers(): HTTPHeaders | undefined { + return this.configuration.headers; + } + + get credentials(): RequestCredentials | undefined { + return this.configuration.credentials; + } +} + +export const DefaultConfig = new Configuration(); + +/** + * This is the base class for all generated API classes. + */ +export class BaseAPI { + + private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; + private middleware: Middleware[]; + + constructor(protected configuration = DefaultConfig) { + this.middleware = configuration.middleware; + } + + withMiddleware(this: T, ...middlewares: Middleware[]) { + const next = this.clone(); + next.middleware = next.middleware.concat(...middlewares); + return next; + } + + withPreMiddleware(this: T, ...preMiddlewares: Array) { + const middlewares = preMiddlewares.map((pre) => ({ pre })); + return this.withMiddleware(...middlewares); + } + + withPostMiddleware(this: T, ...postMiddlewares: Array) { + const middlewares = postMiddlewares.map((post) => ({ post })); + return this.withMiddleware(...middlewares); + } + + /** + * Check if the given MIME is a JSON MIME. + * JSON MIME examples: + * application/json + * application/json; charset=UTF8 + * APPLICATION/JSON + * application/vnd.company+json + * @param mime - MIME (Multipurpose Internet Mail Extensions) + * @return True if the given MIME is JSON, false otherwise. + */ + protected isJsonMime(mime: string | null | undefined): boolean { + if (!mime) { + return false; + } + return BaseAPI.jsonRegex.test(mime); + } + + protected async request(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction): Promise { + const { url, init } = await this.createFetchParams(context, initOverrides); + const response = await this.fetchApi(url, init); + if (response && (response.status >= 200 && response.status < 300)) { + return response; + } + throw new ResponseError(response, 'Response returned an error code'); + } + + private async createFetchParams(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction) { + let url = this.configuration.basePath + context.path; + if (context.query !== undefined && Object.keys(context.query).length !== 0) { + // only add the querystring to the URL if there are query parameters. + // this is done to avoid urls ending with a "?" character which buggy webservers + // do not handle correctly sometimes. + url += '?' + this.configuration.queryParamsStringify(context.query); + } + + const headers = Object.assign({}, this.configuration.headers, context.headers); + Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {}); + + const initOverrideFn = + typeof initOverrides === "function" + ? initOverrides + : async () => initOverrides; + + const initParams = { + method: context.method, + headers, + body: context.body, + credentials: this.configuration.credentials, + }; + + const overriddenInit: RequestInit = { + ...initParams, + ...(await initOverrideFn({ + init: initParams, + context, + })) + }; + + let body: any; + if (isFormData(overriddenInit.body) + || (overriddenInit.body instanceof URLSearchParams) + || isBlob(overriddenInit.body)) { + body = overriddenInit.body; + } else if (this.isJsonMime(headers['Content-Type'])) { + body = JSON.stringify(overriddenInit.body); + } else { + body = overriddenInit.body; + } + + const init: RequestInit = { + ...overriddenInit, + body + }; + + return { url, init }; + } + + private fetchApi = async (url: string, init: RequestInit) => { + let fetchParams = { url, init }; + for (const middleware of this.middleware) { + if (middleware.pre) { + fetchParams = await middleware.pre({ + fetch: this.fetchApi, + ...fetchParams, + }) || fetchParams; + } + } + let response: Response | undefined = undefined; + try { + response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); + } catch (e) { + for (const middleware of this.middleware) { + if (middleware.onError) { + response = await middleware.onError({ + fetch: this.fetchApi, + url: fetchParams.url, + init: fetchParams.init, + error: e, + response: response ? response.clone() : undefined, + }) || response; + } + } + if (response === undefined) { + if (e instanceof Error) { + throw new FetchError(e, 'The request failed and the interceptors did not return an alternative response'); + } else { + throw e; + } + } + } + for (const middleware of this.middleware) { + if (middleware.post) { + response = await middleware.post({ + fetch: this.fetchApi, + url: fetchParams.url, + init: fetchParams.init, + response: response.clone(), + }) || response; + } + } + return response; + } + + /** + * Create a shallow clone of `this` by constructing a new instance + * and then shallow cloning data members. + */ + private clone(this: T): T { + const constructor = this.constructor as any; + const next = new constructor(this.configuration); + next.middleware = this.middleware.slice(); + return next; + } +}; + +function isBlob(value: any): value is Blob { + return typeof Blob !== 'undefined' && value instanceof Blob; +} + +function isFormData(value: any): value is FormData { + return typeof FormData !== "undefined" && value instanceof FormData; +} + +export class ResponseError extends Error { + override name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + + // restore prototype chain + const actualProto = new.target.prototype; + if (Object.setPrototypeOf) { + Object.setPrototypeOf(this, actualProto); + } + } +} + +export class FetchError extends Error { + override name: "FetchError" = "FetchError"; + constructor(public cause: Error, msg?: string) { + super(msg); + + // restore prototype chain + const actualProto = new.target.prototype; + if (Object.setPrototypeOf) { + Object.setPrototypeOf(this, actualProto); + } + } +} + +export class RequiredError extends Error { + override name: "RequiredError" = "RequiredError"; + constructor(public field: string, msg?: string) { + super(msg); + + // restore prototype chain + const actualProto = new.target.prototype; + if (Object.setPrototypeOf) { + Object.setPrototypeOf(this, actualProto); + } + } +} + +export const COLLECTION_FORMATS = { + csv: ",", + ssv: " ", + tsv: "\t", + pipes: "|", +}; + +export type FetchAPI = WindowOrWorkerGlobalScope['fetch']; + +export type Json = any; +export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD'; +export type HTTPHeaders = { [key: string]: string }; +export type HTTPQuery = { [key: string]: string | number | null | boolean | Array | Set | HTTPQuery }; +export type HTTPBody = Json | FormData | URLSearchParams; +export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody }; +export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original'; + +export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise + +export interface FetchParams { + url: string; + init: RequestInit; +} + +export interface RequestOpts { + path: string; + method: HTTPMethod; + headers: HTTPHeaders; + query?: HTTPQuery; + body?: HTTPBody; +} + +export function querystring(params: HTTPQuery, prefix: string = ''): string { + return Object.keys(params) + .map(key => querystringSingleKey(key, params[key], prefix)) + .filter(part => part.length > 0) + .join('&'); +} + +function querystringSingleKey(key: string, value: string | number | null | undefined | boolean | Array | Set | HTTPQuery, keyPrefix: string = ''): string { + const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key); + if (value instanceof Array) { + const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue))) + .join(`&${encodeURIComponent(fullKey)}=`); + return `${encodeURIComponent(fullKey)}=${multiValue}`; + } + if (value instanceof Set) { + const valueAsArray = Array.from(value); + return querystringSingleKey(key, valueAsArray, keyPrefix); + } + if (value instanceof Date) { + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; + } + if (value instanceof Object) { + return querystring(value as HTTPQuery, fullKey); + } + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`; +} + +export function exists(json: any, key: string) { + const value = json[key]; + return value !== null && value !== undefined; +} + +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + +export function mapValues(data: any, fn: (item: any) => any) { + const result: { [key: string]: any } = {}; + for (const key of Object.keys(data)) { + result[key] = fn(data[key]); + } + return result; +} + +// Pass-through serializer for `any`-typed properties in form data. See #1877. +export function anyToJSON(value: any): any { + return value; +} + +export function canConsumeForm(consumes: Consume[]): boolean { + for (const consume of consumes) { + if (consume.contentType?.startsWith('multipart/form-data') == true) { + return true; + } + } + return false; +} + +export interface Consume { + contentType: string; +} + +export interface RequestContext { + fetch: FetchAPI; + url: string; + init: RequestInit; +} + +export interface ResponseContext { + fetch: FetchAPI; + url: string; + init: RequestInit; + response: Response; +} + +export interface ErrorContext { + fetch: FetchAPI; + url: string; + init: RequestInit; + error: unknown; + response?: Response; +} + +export interface Middleware { + pre?(context: RequestContext): Promise; + post?(context: ResponseContext): Promise; + onError?(context: ErrorContext): Promise; +} + +export interface ApiResponse { + raw: Response; + value(): Promise; +} + +export interface ResponseTransformer { + (json: any): T; +} + +export class JSONApiResponse { + constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + + async value(): Promise { + return this.transformer(await this.raw.json()); + } +} + +export class VoidApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return undefined; + } +} + +export class BlobApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return await this.raw.blob(); + }; +} + +export class TextApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return await this.raw.text(); + }; +} diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-string/.openapi-generator-ignore b/samples/client/petstore/typescript-fetch/builds/date-library-string/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-string/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-string/.openapi-generator/FILES b/samples/client/petstore/typescript-fetch/builds/date-library-string/.openapi-generator/FILES new file mode 100644 index 000000000000..354f25e5cfda --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-string/.openapi-generator/FILES @@ -0,0 +1,8 @@ +apis/DefaultApi.ts +apis/index.ts +docs/DefaultApi.md +docs/Event.md +index.ts +models/Event.ts +models/index.ts +runtime.ts diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-string/.openapi-generator/VERSION b/samples/client/petstore/typescript-fetch/builds/date-library-string/.openapi-generator/VERSION new file mode 100644 index 000000000000..8fc8df61083a --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-string/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.25.0-SNAPSHOT diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-string/apis/DefaultApi.ts b/samples/client/petstore/typescript-fetch/builds/date-library-string/apis/DefaultApi.ts new file mode 100644 index 000000000000..a7a38480f8f9 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-string/apis/DefaultApi.ts @@ -0,0 +1,169 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Date handling + * Covers every location a `format: date` or `format: date-time` value can appear in, so the generated (de)serialization can be checked in one place. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import * as runtime from '../runtime'; +import { + type Event, + EventFromJSON, + EventToJSON, +} from '../models/Event'; + +export interface CreateEventRequest { + /** + * + */ + startsOn: string; + /** + * + */ + createdAt?: string; +} + +export interface ListEventsRequest { + /** + * + */ + onDate: string; + /** + * + */ + from?: string; + /** + * + */ + updatedSince?: string; +} + +/** + * + */ +export class DefaultApi extends runtime.BaseAPI { + + /** + * Creates request options for createEvent without sending the request + */ + async createEventRequestOpts(requestParameters: CreateEventRequest): Promise { + if (requestParameters['startsOn'] == null) { + throw new runtime.RequiredError( + 'startsOn', + 'Required parameter "startsOn" was null or undefined when calling createEvent().' + ); + } + + const queryParameters: any = {}; + + const headerParameters: runtime.HTTPHeaders = {}; + + const consumes: runtime.Consume[] = [ + { contentType: 'application/x-www-form-urlencoded' }, + ]; + // @ts-ignore: canConsumeForm may be unused + const canConsumeForm = runtime.canConsumeForm(consumes); + + let formParams: { append(param: string, value: any): any }; + let useForm = false; + if (useForm) { + formParams = new FormData(); + } else { + formParams = new URLSearchParams(); + } + + if (requestParameters['startsOn'] != null) { + formParams.append('startsOn', requestParameters['startsOn'] as any); + } + + if (requestParameters['createdAt'] != null) { + formParams.append('createdAt', requestParameters['createdAt'] as any); + } + + + let urlPath = `/events`; + + return { + path: urlPath, + method: 'POST', + headers: headerParameters, + query: queryParameters, + body: formParams, + }; + } + + /** + */ + async createEventRaw(requestParameters: CreateEventRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { + const requestOptions = await this.createEventRequestOpts(requestParameters); + const response = await this.request(requestOptions, initOverrides); + + return new runtime.JSONApiResponse(response, (jsonValue) => EventFromJSON(jsonValue)); + } + + /** + */ + async createEvent(requestParameters: CreateEventRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { + const response = await this.createEventRaw(requestParameters, initOverrides); + return await response.value(); + } + + /** + * Creates request options for listEvents without sending the request + */ + async listEventsRequestOpts(requestParameters: ListEventsRequest): Promise { + if (requestParameters['onDate'] == null) { + throw new runtime.RequiredError( + 'onDate', + 'Required parameter "onDate" was null or undefined when calling listEvents().' + ); + } + + const queryParameters: any = {}; + + if (requestParameters['from'] != null) { + queryParameters['from'] = requestParameters['from']; + } + + if (requestParameters['updatedSince'] != null) { + queryParameters['updatedSince'] = requestParameters['updatedSince']; + } + + const headerParameters: runtime.HTTPHeaders = {}; + + + let urlPath = `/events/{onDate}`; + urlPath = urlPath.replace('{onDate}', encodeURIComponent(String(requestParameters['onDate']))); + + return { + path: urlPath, + method: 'GET', + headers: headerParameters, + query: queryParameters, + }; + } + + /** + */ + async listEventsRaw(requestParameters: ListEventsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise>> { + const requestOptions = await this.listEventsRequestOpts(requestParameters); + const response = await this.request(requestOptions, initOverrides); + + return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map(EventFromJSON)); + } + + /** + */ + async listEvents(requestParameters: ListEventsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { + const response = await this.listEventsRaw(requestParameters, initOverrides); + return await response.value(); + } + +} diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-string/apis/index.ts b/samples/client/petstore/typescript-fetch/builds/date-library-string/apis/index.ts new file mode 100644 index 000000000000..69c44c00fa0d --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-string/apis/index.ts @@ -0,0 +1,3 @@ +/* tslint:disable */ +/* eslint-disable */ +export * from './DefaultApi'; diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-string/docs/DefaultApi.md b/samples/client/petstore/typescript-fetch/builds/date-library-string/docs/DefaultApi.md new file mode 100644 index 000000000000..d853cc5ad399 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-string/docs/DefaultApi.md @@ -0,0 +1,149 @@ +# DefaultApi + +All URIs are relative to *http://localhost* + +| Method | HTTP request | Description | +|------------- | ------------- | -------------| +| [**createEvent**](DefaultApi.md#createevent) | **POST** /events | | +| [**listEvents**](DefaultApi.md#listevents) | **GET** /events/{onDate} | | + + + +## createEvent + +> Event createEvent(startsOn, createdAt) + + + +### Example + +```ts +import { + Configuration, + DefaultApi, +} from ''; +import type { CreateEventRequest } from ''; + +async function example() { + console.log("🚀 Testing SDK..."); + const api = new DefaultApi(); + + const body = { + // string + startsOn: 2013-10-20, + // string (optional) + createdAt: 2013-10-20T19:20:30+01:00, + } satisfies CreateEventRequest; + + try { + const data = await api.createEvent(body); + console.log(data); + } catch (error) { + console.error(error); + } +} + +// Run the test +example().catch(console.error); +``` + +### Parameters + + +| Name | Type | Description | Notes | +|------------- | ------------- | ------------- | -------------| +| **startsOn** | `string` | | [Defaults to `undefined`] | +| **createdAt** | `string` | | [Optional] [Defaults to `undefined`] | + +### Return type + +[**Event**](Event.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: `application/x-www-form-urlencoded` +- **Accept**: `application/json` + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | the created event | - | + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + +## listEvents + +> Array<Event> listEvents(onDate, from, updatedSince) + + + +### Example + +```ts +import { + Configuration, + DefaultApi, +} from ''; +import type { ListEventsRequest } from ''; + +async function example() { + console.log("🚀 Testing SDK..."); + const api = new DefaultApi(); + + const body = { + // string + onDate: 2013-10-20, + // string (optional) + from: 2013-10-20, + // string (optional) + updatedSince: 2013-10-20T19:20:30+01:00, + } satisfies ListEventsRequest; + + try { + const data = await api.listEvents(body); + console.log(data); + } catch (error) { + console.error(error); + } +} + +// Run the test +example().catch(console.error); +``` + +### Parameters + + +| Name | Type | Description | Notes | +|------------- | ------------- | ------------- | -------------| +| **onDate** | `string` | | [Defaults to `undefined`] | +| **from** | `string` | | [Optional] [Defaults to `undefined`] | +| **updatedSince** | `string` | | [Optional] [Defaults to `undefined`] | + +### Return type + +[**Array<Event>**](Event.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: `application/json` + + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | matching events | - | + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-string/docs/Event.md b/samples/client/petstore/typescript-fetch/builds/date-library-string/docs/Event.md new file mode 100644 index 000000000000..4e009ab2a252 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-string/docs/Event.md @@ -0,0 +1,38 @@ + +# Event + + +## Properties + +Name | Type +------------ | ------------- +`startsOn` | string +`endsOn` | string +`createdAt` | string + +## Example + +```typescript +import type { Event } from '' + +// TODO: Update the object below with actual values +const example = { + "startsOn": null, + "endsOn": null, + "createdAt": null, +} satisfies Event + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as Event +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-string/index.ts b/samples/client/petstore/typescript-fetch/builds/date-library-string/index.ts new file mode 100644 index 000000000000..bebe8bbbe206 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-string/index.ts @@ -0,0 +1,5 @@ +/* tslint:disable */ +/* eslint-disable */ +export * from './runtime'; +export * from './apis/index'; +export * from './models/index'; diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-string/models/Event.ts b/samples/client/petstore/typescript-fetch/builds/date-library-string/models/Event.ts new file mode 100644 index 000000000000..1a9bd5a58641 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-string/models/Event.ts @@ -0,0 +1,76 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Date handling + * Covers every location a `format: date` or `format: date-time` value can appear in, so the generated (de)serialization can be checked in one place. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { mapValues } from '../runtime'; +/** + * + * @export + * @interface Event + */ +export interface Event { + /** + * + */ + startsOn: string; + /** + * + */ + endsOn?: string | null; + /** + * + */ + createdAt?: string; +} + +/** + * Check if a given object implements the Event interface. + */ +export function instanceOfEvent(value: object): value is Event { + if (!('startsOn' in value) || value['startsOn'] === undefined) return false; + return true; +} + +export function EventFromJSON(json: any): Event { + return EventFromJSONTyped(json, false); +} + +export function EventFromJSONTyped(json: any, ignoreDiscriminator: boolean): Event { + if (json == null) { + return json; + } + return { + + 'startsOn': json['startsOn'], + 'endsOn': json['endsOn'] === undefined ? undefined : json['endsOn'] === null ? null : json['endsOn'], + 'createdAt': json['createdAt'] == null ? undefined : json['createdAt'], + }; +} + +export function EventToJSON(json: any): Event { + return EventToJSONTyped(json, false); +} + +export function EventToJSONTyped(value?: Event | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'startsOn': value['startsOn'], + 'endsOn': value['endsOn'], + 'createdAt': value['createdAt'], + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-string/models/index.ts b/samples/client/petstore/typescript-fetch/builds/date-library-string/models/index.ts new file mode 100644 index 000000000000..309b5bb56aa3 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-string/models/index.ts @@ -0,0 +1,3 @@ +/* tslint:disable */ +/* eslint-disable */ +export * from './Event'; diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-string/runtime.ts b/samples/client/petstore/typescript-fetch/builds/date-library-string/runtime.ts new file mode 100644 index 000000000000..2535518eb0ca --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-string/runtime.ts @@ -0,0 +1,466 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Date handling + * Covers every location a `format: date` or `format: date-time` value can appear in, so the generated (de)serialization can be checked in one place. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +export const BASE_PATH = "http://localhost".replace(/\/+$/, ""); + +export interface ConfigurationParameters { + basePath?: string; // override base path + fetchApi?: FetchAPI; // override for fetch implementation + middleware?: Middleware[]; // middleware to apply before/after fetch requests + queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings + username?: string; // parameter for basic security + password?: string; // parameter for basic security + apiKey?: string | Promise | ((name: string) => string | Promise); // parameter for apiKey security + accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string | Promise); // parameter for oauth2 security + headers?: HTTPHeaders; //header params we want to use on every request + credentials?: RequestCredentials; //value for the credentials param we want to use on each request +} + +export class Configuration { + constructor(private configuration: ConfigurationParameters = {}) {} + + set config(configuration: Configuration) { + this.configuration = configuration; + } + + get basePath(): string { + return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH; + } + + get fetchApi(): FetchAPI | undefined { + return this.configuration.fetchApi; + } + + get middleware(): Middleware[] { + return this.configuration.middleware || []; + } + + get queryParamsStringify(): (params: HTTPQuery) => string { + return this.configuration.queryParamsStringify || querystring; + } + + get username(): string | undefined { + return this.configuration.username; + } + + get password(): string | undefined { + return this.configuration.password; + } + + get apiKey(): ((name: string) => string | Promise) | undefined { + const apiKey = this.configuration.apiKey; + if (apiKey) { + return typeof apiKey === 'function' ? apiKey : () => apiKey; + } + return undefined; + } + + get accessToken(): ((name?: string, scopes?: string[]) => string | Promise) | undefined { + const accessToken = this.configuration.accessToken; + if (accessToken) { + return typeof accessToken === 'function' ? accessToken : async () => accessToken; + } + return undefined; + } + + get headers(): HTTPHeaders | undefined { + return this.configuration.headers; + } + + get credentials(): RequestCredentials | undefined { + return this.configuration.credentials; + } +} + +export const DefaultConfig = new Configuration(); + +/** + * This is the base class for all generated API classes. + */ +export class BaseAPI { + + private static readonly jsonRegex = /^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$/i; + private middleware: Middleware[]; + + constructor(protected configuration = DefaultConfig) { + this.middleware = configuration.middleware; + } + + withMiddleware(this: T, ...middlewares: Middleware[]) { + const next = this.clone(); + next.middleware = next.middleware.concat(...middlewares); + return next; + } + + withPreMiddleware(this: T, ...preMiddlewares: Array) { + const middlewares = preMiddlewares.map((pre) => ({ pre })); + return this.withMiddleware(...middlewares); + } + + withPostMiddleware(this: T, ...postMiddlewares: Array) { + const middlewares = postMiddlewares.map((post) => ({ post })); + return this.withMiddleware(...middlewares); + } + + /** + * Check if the given MIME is a JSON MIME. + * JSON MIME examples: + * application/json + * application/json; charset=UTF8 + * APPLICATION/JSON + * application/vnd.company+json + * @param mime - MIME (Multipurpose Internet Mail Extensions) + * @return True if the given MIME is JSON, false otherwise. + */ + protected isJsonMime(mime: string | null | undefined): boolean { + if (!mime) { + return false; + } + return BaseAPI.jsonRegex.test(mime); + } + + protected async request(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction): Promise { + const { url, init } = await this.createFetchParams(context, initOverrides); + const response = await this.fetchApi(url, init); + if (response && (response.status >= 200 && response.status < 300)) { + return response; + } + throw new ResponseError(response, 'Response returned an error code'); + } + + private async createFetchParams(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction) { + let url = this.configuration.basePath + context.path; + if (context.query !== undefined && Object.keys(context.query).length !== 0) { + // only add the querystring to the URL if there are query parameters. + // this is done to avoid urls ending with a "?" character which buggy webservers + // do not handle correctly sometimes. + url += '?' + this.configuration.queryParamsStringify(context.query); + } + + const headers = Object.assign({}, this.configuration.headers, context.headers); + Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {}); + + const initOverrideFn = + typeof initOverrides === "function" + ? initOverrides + : async () => initOverrides; + + const initParams = { + method: context.method, + headers, + body: context.body, + credentials: this.configuration.credentials, + }; + + const overriddenInit: RequestInit = { + ...initParams, + ...(await initOverrideFn({ + init: initParams, + context, + })) + }; + + let body: any; + if (isFormData(overriddenInit.body) + || (overriddenInit.body instanceof URLSearchParams) + || isBlob(overriddenInit.body)) { + body = overriddenInit.body; + } else if (this.isJsonMime(headers['Content-Type'])) { + body = JSON.stringify(overriddenInit.body); + } else { + body = overriddenInit.body; + } + + const init: RequestInit = { + ...overriddenInit, + body + }; + + return { url, init }; + } + + private fetchApi = async (url: string, init: RequestInit) => { + let fetchParams = { url, init }; + for (const middleware of this.middleware) { + if (middleware.pre) { + fetchParams = await middleware.pre({ + fetch: this.fetchApi, + ...fetchParams, + }) || fetchParams; + } + } + let response: Response | undefined = undefined; + try { + response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); + } catch (e) { + for (const middleware of this.middleware) { + if (middleware.onError) { + response = await middleware.onError({ + fetch: this.fetchApi, + url: fetchParams.url, + init: fetchParams.init, + error: e, + response: response ? response.clone() : undefined, + }) || response; + } + } + if (response === undefined) { + if (e instanceof Error) { + throw new FetchError(e, 'The request failed and the interceptors did not return an alternative response'); + } else { + throw e; + } + } + } + for (const middleware of this.middleware) { + if (middleware.post) { + response = await middleware.post({ + fetch: this.fetchApi, + url: fetchParams.url, + init: fetchParams.init, + response: response.clone(), + }) || response; + } + } + return response; + } + + /** + * Create a shallow clone of `this` by constructing a new instance + * and then shallow cloning data members. + */ + private clone(this: T): T { + const constructor = this.constructor as any; + const next = new constructor(this.configuration); + next.middleware = this.middleware.slice(); + return next; + } +}; + +function isBlob(value: any): value is Blob { + return typeof Blob !== 'undefined' && value instanceof Blob; +} + +function isFormData(value: any): value is FormData { + return typeof FormData !== "undefined" && value instanceof FormData; +} + +export class ResponseError extends Error { + override name: "ResponseError" = "ResponseError"; + constructor(public response: Response, msg?: string) { + super(msg); + + // restore prototype chain + const actualProto = new.target.prototype; + if (Object.setPrototypeOf) { + Object.setPrototypeOf(this, actualProto); + } + } +} + +export class FetchError extends Error { + override name: "FetchError" = "FetchError"; + constructor(public cause: Error, msg?: string) { + super(msg); + + // restore prototype chain + const actualProto = new.target.prototype; + if (Object.setPrototypeOf) { + Object.setPrototypeOf(this, actualProto); + } + } +} + +export class RequiredError extends Error { + override name: "RequiredError" = "RequiredError"; + constructor(public field: string, msg?: string) { + super(msg); + + // restore prototype chain + const actualProto = new.target.prototype; + if (Object.setPrototypeOf) { + Object.setPrototypeOf(this, actualProto); + } + } +} + +export const COLLECTION_FORMATS = { + csv: ",", + ssv: " ", + tsv: "\t", + pipes: "|", +}; + +export type FetchAPI = WindowOrWorkerGlobalScope['fetch']; + +export type Json = any; +export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD'; +export type HTTPHeaders = { [key: string]: string }; +export type HTTPQuery = { [key: string]: string | number | null | boolean | Array | Set | HTTPQuery }; +export type HTTPBody = Json | FormData | URLSearchParams; +export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody }; +export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original'; + +export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise + +export interface FetchParams { + url: string; + init: RequestInit; +} + +export interface RequestOpts { + path: string; + method: HTTPMethod; + headers: HTTPHeaders; + query?: HTTPQuery; + body?: HTTPBody; +} + +export function querystring(params: HTTPQuery, prefix: string = ''): string { + return Object.keys(params) + .map(key => querystringSingleKey(key, params[key], prefix)) + .filter(part => part.length > 0) + .join('&'); +} + +function querystringSingleKey(key: string, value: string | number | null | undefined | boolean | Array | Set | HTTPQuery, keyPrefix: string = ''): string { + const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key); + if (value instanceof Array) { + const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue))) + .join(`&${encodeURIComponent(fullKey)}=`); + return `${encodeURIComponent(fullKey)}=${multiValue}`; + } + if (value instanceof Set) { + const valueAsArray = Array.from(value); + return querystringSingleKey(key, valueAsArray, keyPrefix); + } + if (value instanceof Date) { + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; + } + if (value instanceof Object) { + return querystring(value as HTTPQuery, fullKey); + } + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`; +} + +export function exists(json: any, key: string) { + const value = json[key]; + return value !== null && value !== undefined; +} + +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + + +export function mapValues(data: any, fn: (item: any) => any) { + const result: { [key: string]: any } = {}; + for (const key of Object.keys(data)) { + result[key] = fn(data[key]); + } + return result; +} + +// Pass-through serializer for `any`-typed properties in form data. See #1877. +export function anyToJSON(value: any): any { + return value; +} + +export function canConsumeForm(consumes: Consume[]): boolean { + for (const consume of consumes) { + if (consume.contentType?.startsWith('multipart/form-data') == true) { + return true; + } + } + return false; +} + +export interface Consume { + contentType: string; +} + +export interface RequestContext { + fetch: FetchAPI; + url: string; + init: RequestInit; +} + +export interface ResponseContext { + fetch: FetchAPI; + url: string; + init: RequestInit; + response: Response; +} + +export interface ErrorContext { + fetch: FetchAPI; + url: string; + init: RequestInit; + error: unknown; + response?: Response; +} + +export interface Middleware { + pre?(context: RequestContext): Promise; + post?(context: ResponseContext): Promise; + onError?(context: ErrorContext): Promise; +} + +export interface ApiResponse { + raw: Response; + value(): Promise; +} + +export interface ResponseTransformer { + (json: any): T; +} + +export class JSONApiResponse { + constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + + async value(): Promise { + return this.transformer(await this.raw.json()); + } +} + +export class VoidApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return undefined; + } +} + +export class BlobApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return await this.raw.blob(); + }; +} + +export class TextApiResponse { + constructor(public raw: Response) {} + + async value(): Promise { + return await this.raw.text(); + }; +} diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/apis/FakeApi.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/apis/FakeApi.ts index e54629f53eca..26b4e14eb660 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/apis/FakeApi.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/apis/FakeApi.ts @@ -1045,11 +1045,11 @@ export class FakeApi extends runtime.BaseAPI { } if (requestParameters['date'] != null) { - formParams.append('date', requestParameters['date'] as any); + formParams.append('date', runtime.serializeDate(requestParameters['date'] as any)); } if (requestParameters['dateTime'] != null) { - formParams.append('dateTime', (requestParameters['dateTime'] as any).toISOString()); + formParams.append('dateTime', runtime.serializeDateTime(requestParameters['dateTime'] as any)); } if (requestParameters['password'] != null) { diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AdditionalPropertiesClass.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AdditionalPropertiesClass.ts index 1db920000504..f2dc71ebdaf6 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AdditionalPropertiesClass.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AdditionalPropertiesClass.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AllOfWithSingleRef.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AllOfWithSingleRef.ts index 743b9141a1af..48d511219088 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AllOfWithSingleRef.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AllOfWithSingleRef.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { SingleRefType } from './SingleRefType'; import { SingleRefTypeFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Animal.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Animal.ts index 2a8b126041f7..86520b9e608e 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Animal.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Animal.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import { type Cat, CatFromJSONTyped, CatToJSON, CatToJSONTyped } from './Cat'; import { type Dog, DogFromJSONTyped, DogToJSON, DogToJSONTyped } from './Dog'; /** diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfArrayOfNumberOnly.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfArrayOfNumberOnly.ts index bce79e8d3b63..eb46a92a17f4 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfArrayOfNumberOnly.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfArrayOfNumberOnly.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfNumberOnly.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfNumberOnly.ts index 8640a0d74aa5..58a124c4d597 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfNumberOnly.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfNumberOnly.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayTest.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayTest.ts index 002052b417d3..209bc6d83544 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayTest.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayTest.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { ReadOnlyFirst } from './ReadOnlyFirst'; import { ReadOnlyFirstFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Capitalization.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Capitalization.ts index de75ac5926d6..e1ae19d0722d 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Capitalization.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Capitalization.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Cat.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Cat.ts index 33efae9ddcf9..6744be5087c2 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Cat.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Cat.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Animal } from './Animal'; import { AnimalFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Category.ts index 04cd593f2dce..f5c1719da512 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ChildWithNullable.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ChildWithNullable.ts index aa6dc996a500..2c415f0b05b9 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ChildWithNullable.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ChildWithNullable.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { ParentWithNullable } from './ParentWithNullable'; import { ParentWithNullableFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ClassModel.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ClassModel.ts index cef4c58640ce..39f27a81ee3a 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ClassModel.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ClassModel.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Model for testing model with "_class" property * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Client.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Client.ts index 7f353720b90d..39f16473b2db 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Client.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Client.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/DeprecatedObject.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/DeprecatedObject.ts index 14623160e258..5264e69b1e0b 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/DeprecatedObject.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/DeprecatedObject.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Dog.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Dog.ts index 967f5cf772f2..cec03d19fee0 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Dog.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Dog.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Animal } from './Animal'; import { AnimalFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumArrays.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumArrays.ts index 84cd87dd1408..88d2b45098c5 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumArrays.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumArrays.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumTest.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumTest.ts index 4c27767e593c..58374a3bc6cf 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumTest.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumTest.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { OuterEnum } from './OuterEnum'; import { OuterEnumFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FakeBigDecimalMap200Response.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FakeBigDecimalMap200Response.ts index ed87ea529d3d..097fae0be926 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FakeBigDecimalMap200Response.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FakeBigDecimalMap200Response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FileSchemaTestClass.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FileSchemaTestClass.ts index 4dcd0b2ed2c4..9f5f785effe6 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FileSchemaTestClass.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FileSchemaTestClass.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Foo.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Foo.ts index 843b44d30811..265c8bb9a8d7 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Foo.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Foo.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FooGetDefaultResponse.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FooGetDefaultResponse.ts index d12c4924c2f3..cdf9c480ebc7 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FooGetDefaultResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FooGetDefaultResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Foo } from './Foo'; import { FooFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FormatTest.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FormatTest.ts index 047bde78c359..aa1f8c7f1518 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FormatTest.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FormatTest.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export @@ -116,8 +116,8 @@ export function FormatTestFromJSONTyped(json: any, ignoreDiscriminator: boolean) 'string': json['string'] == null ? undefined : json['string'], '_byte': json['byte'], 'binary': json['binary'] == null ? undefined : json['binary'], - 'date': (new Date(json['date'])), - 'dateTime': json['dateTime'] == null ? undefined : (new Date(json['dateTime'])), + 'date': (parseDate(json['date'])), + 'dateTime': json['dateTime'] == null ? undefined : (parseDateTime(json['dateTime'])), 'uuid': json['uuid'] == null ? undefined : json['uuid'], 'password': json['password'], 'patternWithDigits': json['pattern_with_digits'] == null ? undefined : json['pattern_with_digits'], @@ -146,8 +146,8 @@ export function FormatTestToJSONTyped(value?: FormatTest | null, ignoreDiscrimin 'string': value['string'], 'byte': value['_byte'], 'binary': value['binary'], - 'date': value['date'].toISOString().substring(0,10), - 'dateTime': value['dateTime'] == null ? value['dateTime'] : value['dateTime'].toISOString(), + 'date': serializeDate(value['date']), + 'dateTime': value['dateTime'] == null ? value['dateTime'] : serializeDateTime(value['dateTime']), 'uuid': value['uuid'], 'password': value['password'], 'pattern_with_digits': value['patternWithDigits'], diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/HasOnlyReadOnly.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/HasOnlyReadOnly.ts index b81e989b86d4..93656b13dc8f 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/HasOnlyReadOnly.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/HasOnlyReadOnly.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/HealthCheckResult.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/HealthCheckResult.ts index 520e91e780bd..01c77603870f 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/HealthCheckResult.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/HealthCheckResult.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model. * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/List.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/List.ts index a51be9f76c2c..4f585b061668 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/List.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/List.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MapTest.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MapTest.ts index 18ea456c8951..f7a65d7e8822 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MapTest.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MapTest.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MixedPropertiesAndAdditionalPropertiesClass.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MixedPropertiesAndAdditionalPropertiesClass.ts index cb7a2989f0c9..29e136055639 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MixedPropertiesAndAdditionalPropertiesClass.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MixedPropertiesAndAdditionalPropertiesClass.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Animal } from './Animal'; import { AnimalFromJSON, @@ -59,7 +59,7 @@ export function MixedPropertiesAndAdditionalPropertiesClassFromJSONTyped(json: a return { 'uuid': json['uuid'] == null ? undefined : json['uuid'], - 'dateTime': json['dateTime'] == null ? undefined : (new Date(json['dateTime'])), + 'dateTime': json['dateTime'] == null ? undefined : (parseDateTime(json['dateTime'])), 'map': json['map'] == null ? undefined : (mapValues(json['map'], AnimalFromJSON)), }; } @@ -76,7 +76,7 @@ export function MixedPropertiesAndAdditionalPropertiesClassToJSONTyped(value?: M return { 'uuid': value['uuid'], - 'dateTime': value['dateTime'] == null ? value['dateTime'] : value['dateTime'].toISOString(), + 'dateTime': value['dateTime'] == null ? value['dateTime'] : serializeDateTime(value['dateTime']), 'map': value['map'] == null ? undefined : (mapValues(value['map'], AnimalToJSON)), }; } diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Model200Response.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Model200Response.ts index 62f11d4d4e5a..98089b550456 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Model200Response.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Model200Response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Model for testing model name starting with number * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ModelApiResponse.ts index 8e8b92dc4228..4650d81f3a85 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ModelFile.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ModelFile.ts index e823e6cd03cc..2eaf8fd20162 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ModelFile.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ModelFile.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Must be named `File` for test. * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Name.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Name.ts index 4b7ed42911fb..cedfa4b67db8 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Name.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Name.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Model for testing model name same as property name * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/NullableClass.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/NullableClass.ts index 2899b9f6f3d6..e917dc5109d3 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/NullableClass.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/NullableClass.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export @@ -92,8 +92,8 @@ export function NullableClassFromJSONTyped(json: any, ignoreDiscriminator: boole 'numberProp': json['number_prop'] === undefined ? undefined : json['number_prop'] === null ? null : json['number_prop'], 'booleanProp': json['boolean_prop'] === undefined ? undefined : json['boolean_prop'] === null ? null : json['boolean_prop'], 'stringProp': json['string_prop'] === undefined ? undefined : json['string_prop'] === null ? null : json['string_prop'], - 'dateProp': json['date_prop'] === undefined ? undefined : json['date_prop'] === null ? null : (new Date(json['date_prop'])), - 'datetimeProp': json['datetime_prop'] === undefined ? undefined : json['datetime_prop'] === null ? null : (new Date(json['datetime_prop'])), + 'dateProp': json['date_prop'] === undefined ? undefined : json['date_prop'] === null ? null : (parseDate(json['date_prop'])), + 'datetimeProp': json['datetime_prop'] === undefined ? undefined : json['datetime_prop'] === null ? null : (parseDateTime(json['datetime_prop'])), 'arrayNullableProp': json['array_nullable_prop'] === undefined ? undefined : json['array_nullable_prop'] === null ? null : json['array_nullable_prop'], 'arrayAndItemsNullableProp': json['array_and_items_nullable_prop'] === undefined ? undefined : json['array_and_items_nullable_prop'] === null ? null : json['array_and_items_nullable_prop'], 'arrayItemsNullable': json['array_items_nullable'] == null ? undefined : json['array_items_nullable'], @@ -119,8 +119,8 @@ export function NullableClassToJSONTyped(value?: NullableClass | null, ignoreDis 'number_prop': value['numberProp'], 'boolean_prop': value['booleanProp'], 'string_prop': value['stringProp'], - 'date_prop': value['dateProp'] == null ? value['dateProp'] : value['dateProp'].toISOString().substring(0,10), - 'datetime_prop': value['datetimeProp'] == null ? value['datetimeProp'] : value['datetimeProp'].toISOString(), + 'date_prop': value['dateProp'] == null ? value['dateProp'] : serializeDate(value['dateProp']), + 'datetime_prop': value['datetimeProp'] == null ? value['datetimeProp'] : serializeDateTime(value['datetimeProp']), 'array_nullable_prop': value['arrayNullableProp'], 'array_and_items_nullable_prop': value['arrayAndItemsNullableProp'], 'array_items_nullable': value['arrayItemsNullable'], diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/NumberOnly.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/NumberOnly.ts index b899ac447f22..bab9610104f4 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/NumberOnly.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/NumberOnly.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ObjectWithDeprecatedFields.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ObjectWithDeprecatedFields.ts index 73a8eb403427..d17040b0b56e 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ObjectWithDeprecatedFields.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ObjectWithDeprecatedFields.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { DeprecatedObject } from './DeprecatedObject'; import { DeprecatedObjectFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Order.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Order.ts index 1d32da2609f6..8cb7d0bb68bb 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Order.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Order.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export @@ -77,7 +77,7 @@ export function OrderFromJSONTyped(json: any, ignoreDiscriminator: boolean): Ord 'id': json['id'] == null ? undefined : json['id'], 'petId': json['petId'] == null ? undefined : json['petId'], 'quantity': json['quantity'] == null ? undefined : json['quantity'], - 'shipDate': json['shipDate'] == null ? undefined : (new Date(json['shipDate'])), + 'shipDate': json['shipDate'] == null ? undefined : (parseDateTime(json['shipDate'])), 'status': json['status'] == null ? undefined : json['status'], 'complete': json['complete'] == null ? undefined : json['complete'], }; @@ -97,7 +97,7 @@ export function OrderToJSONTyped(value?: Order | null, ignoreDiscriminator: bool 'id': value['id'], 'petId': value['petId'], 'quantity': value['quantity'], - 'shipDate': value['shipDate'] == null ? value['shipDate'] : value['shipDate'].toISOString(), + 'shipDate': value['shipDate'] == null ? value['shipDate'] : serializeDateTime(value['shipDate']), 'status': value['status'], 'complete': value['complete'], }; diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterComposite.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterComposite.ts index f3375c3124f7..bde6e9963ef6 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterComposite.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterComposite.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterObjectWithEnumProperty.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterObjectWithEnumProperty.ts index 420c964cd78b..5ea61247a3ed 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterObjectWithEnumProperty.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterObjectWithEnumProperty.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { OuterEnumInteger } from './OuterEnumInteger'; import { OuterEnumIntegerFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ParentWithNullable.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ParentWithNullable.ts index 0eedf046f63c..b59604b5d13b 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ParentWithNullable.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ParentWithNullable.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import { type ChildWithNullable, ChildWithNullableFromJSONTyped, ChildWithNullableToJSON, ChildWithNullableToJSONTyped } from './ChildWithNullable'; /** * diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts index 20d21e2f1aad..d90d4d1cf971 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ReadOnlyFirst.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ReadOnlyFirst.ts index 3a80d04b6d6d..99d7deac013e 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ReadOnlyFirst.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ReadOnlyFirst.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Return.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Return.ts index c0b3275a6ed8..652fabd69106 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Return.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Return.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Model for testing reserved words * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/SpecialModelName.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/SpecialModelName.ts index d13618509744..763e45b6ee39 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/SpecialModelName.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/SpecialModelName.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Tag.ts index a0caf8140a38..55fc45e2c9a5 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/TestInlineFreeformAdditionalPropertiesRequest.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/TestInlineFreeformAdditionalPropertiesRequest.ts index b11489089d02..5e453f9ea286 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/TestInlineFreeformAdditionalPropertiesRequest.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/TestInlineFreeformAdditionalPropertiesRequest.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/User.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/User.ts index 207ad34596fc..d09fd6f21295 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts index e52a36947b03..9a57ab110acb 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/default/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/default/models/Category.ts index cdffe07db910..d4ff2b5e4d9a 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A category for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/default/models/ModelApiResponse.ts index f89423073868..71da44967c79 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Describes the result of uploading an image resource * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default/models/Order.ts b/samples/client/petstore/typescript-fetch/builds/default/models/Order.ts index cb6b5c016de6..e47ffdb65be7 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/models/Order.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/models/Order.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * An order for a pets from the pet store * @export @@ -77,7 +77,7 @@ export function OrderFromJSONTyped(json: any, ignoreDiscriminator: boolean): Ord 'id': json['id'] == null ? undefined : json['id'], 'petId': json['petId'] == null ? undefined : json['petId'], 'quantity': json['quantity'] == null ? undefined : json['quantity'], - 'shipDate': json['shipDate'] == null ? undefined : (new Date(json['shipDate'])), + 'shipDate': json['shipDate'] == null ? undefined : (parseDateTime(json['shipDate'])), 'status': json['status'] == null ? undefined : json['status'], 'complete': json['complete'] == null ? undefined : json['complete'], }; @@ -97,7 +97,7 @@ export function OrderToJSONTyped(value?: Order | null, ignoreDiscriminator: bool 'id': value['id'], 'petId': value['petId'], 'quantity': value['quantity'], - 'shipDate': value['shipDate'] == null ? value['shipDate'] : value['shipDate'].toISOString(), + 'shipDate': value['shipDate'] == null ? value['shipDate'] : serializeDateTime(value['shipDate']), 'status': value['status'], 'complete': value['complete'], }; diff --git a/samples/client/petstore/typescript-fetch/builds/default/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/default/models/Pet.ts index 4c0cb6e73685..8230f3435432 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/default/models/Tag.ts index 80126e24919e..83b9ad7dcb3f 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A tag for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default/models/User.ts b/samples/client/petstore/typescript-fetch/builds/default/models/User.ts index 68e240e4afb3..59dfa0baec26 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A User who is purchasing from the pet store * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts index 3389e4beb1cc..7d4323ad5e99 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/enum/models/EnumPatternObject.ts b/samples/client/petstore/typescript-fetch/builds/enum/models/EnumPatternObject.ts index 0ad7eb19c7df..c686f79ca418 100644 --- a/samples/client/petstore/typescript-fetch/builds/enum/models/EnumPatternObject.ts +++ b/samples/client/petstore/typescript-fetch/builds/enum/models/EnumPatternObject.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { NumberEnum } from './NumberEnum'; import { NumberEnumFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/enum/models/FakeEnumRequestGetInline200Response.ts b/samples/client/petstore/typescript-fetch/builds/enum/models/FakeEnumRequestGetInline200Response.ts index 50912880cb8f..edc214ae5c51 100644 --- a/samples/client/petstore/typescript-fetch/builds/enum/models/FakeEnumRequestGetInline200Response.ts +++ b/samples/client/petstore/typescript-fetch/builds/enum/models/FakeEnumRequestGetInline200Response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts b/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts index 2d2f267ce4a8..5a2edca34dd6 100644 --- a/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Category.ts index cdffe07db910..d4ff2b5e4d9a 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A category for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/ModelApiResponse.ts index f89423073868..71da44967c79 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Describes the result of uploading an image resource * @export diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Order.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Order.ts index cb6b5c016de6..e47ffdb65be7 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Order.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Order.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * An order for a pets from the pet store * @export @@ -77,7 +77,7 @@ export function OrderFromJSONTyped(json: any, ignoreDiscriminator: boolean): Ord 'id': json['id'] == null ? undefined : json['id'], 'petId': json['petId'] == null ? undefined : json['petId'], 'quantity': json['quantity'] == null ? undefined : json['quantity'], - 'shipDate': json['shipDate'] == null ? undefined : (new Date(json['shipDate'])), + 'shipDate': json['shipDate'] == null ? undefined : (parseDateTime(json['shipDate'])), 'status': json['status'] == null ? undefined : json['status'], 'complete': json['complete'] == null ? undefined : json['complete'], }; @@ -97,7 +97,7 @@ export function OrderToJSONTyped(value?: Order | null, ignoreDiscriminator: bool 'id': value['id'], 'petId': value['petId'], 'quantity': value['quantity'], - 'shipDate': value['shipDate'] == null ? value['shipDate'] : value['shipDate'].toISOString(), + 'shipDate': value['shipDate'] == null ? value['shipDate'] : serializeDateTime(value['shipDate']), 'status': value['status'], 'complete': value['complete'], }; diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Pet.ts index 4c0cb6e73685..8230f3435432 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Tag.ts index 80126e24919e..83b9ad7dcb3f 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A tag for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/User.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/User.ts index 68e240e4afb3..59dfa0baec26 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A User who is purchasing from the pet store * @export diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts index 3389e4beb1cc..7d4323ad5e99 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/apis/fake-api.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/apis/fake-api.ts index f62eb520f8d1..f5a36c962c75 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/apis/fake-api.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/apis/fake-api.ts @@ -1045,11 +1045,11 @@ export class FakeApi extends runtime.BaseAPI { } if (requestParameters['date'] != null) { - formParams.append('date', requestParameters['date'] as any); + formParams.append('date', runtime.serializeDate(requestParameters['date'] as any)); } if (requestParameters['dateTime'] != null) { - formParams.append('dateTime', (requestParameters['dateTime'] as any).toISOString()); + formParams.append('dateTime', runtime.serializeDateTime(requestParameters['dateTime'] as any)); } if (requestParameters['password'] != null) { diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/additional-properties-class.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/additional-properties-class.ts index 1db920000504..f2dc71ebdaf6 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/additional-properties-class.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/additional-properties-class.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/all-of-with-single-ref.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/all-of-with-single-ref.ts index aa782062bc3d..d46434597e44 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/all-of-with-single-ref.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/all-of-with-single-ref.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { SingleRefType } from './single-ref-type'; import { SingleRefTypeFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/animal.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/animal.ts index 2a8b126041f7..86520b9e608e 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/animal.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/animal.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import { type Cat, CatFromJSONTyped, CatToJSON, CatToJSONTyped } from './Cat'; import { type Dog, DogFromJSONTyped, DogToJSON, DogToJSONTyped } from './Dog'; /** diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-of-array-of-number-only.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-of-array-of-number-only.ts index bce79e8d3b63..eb46a92a17f4 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-of-array-of-number-only.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-of-array-of-number-only.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-of-number-only.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-of-number-only.ts index 8640a0d74aa5..58a124c4d597 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-of-number-only.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-of-number-only.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-test.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-test.ts index a41776f9d876..1aec9d9d532b 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-test.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-test.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { ReadOnlyFirst } from './read-only-first'; import { ReadOnlyFirstFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/capitalization.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/capitalization.ts index de75ac5926d6..e1ae19d0722d 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/capitalization.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/capitalization.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/cat.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/cat.ts index 05327a0a2074..1543026b61cf 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/cat.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/cat.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Animal } from './animal'; import { AnimalFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/category.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/category.ts index 04cd593f2dce..f5c1719da512 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/category.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/child-with-nullable.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/child-with-nullable.ts index 0581ad6f5e92..a0f2256d9c1b 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/child-with-nullable.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/child-with-nullable.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { ParentWithNullable } from './parent-with-nullable'; import { ParentWithNullableFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/class-model.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/class-model.ts index cef4c58640ce..39f27a81ee3a 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/class-model.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/class-model.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Model for testing model with "_class" property * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/client.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/client.ts index 7f353720b90d..39f16473b2db 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/client.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/client.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/deprecated-object.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/deprecated-object.ts index 14623160e258..5264e69b1e0b 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/deprecated-object.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/deprecated-object.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/dog.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/dog.ts index 8eae2e8bd755..6b8e43b30a8f 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/dog.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/dog.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Animal } from './animal'; import { AnimalFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-arrays.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-arrays.ts index 84cd87dd1408..88d2b45098c5 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-arrays.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-arrays.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-test.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-test.ts index ebfff184b281..e211560bed95 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-test.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-test.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { OuterEnum } from './outer-enum'; import { OuterEnumFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/fake-big-decimal-map200-response.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/fake-big-decimal-map200-response.ts index ed87ea529d3d..097fae0be926 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/fake-big-decimal-map200-response.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/fake-big-decimal-map200-response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/file-schema-test-class.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/file-schema-test-class.ts index 4dcd0b2ed2c4..9f5f785effe6 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/file-schema-test-class.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/file-schema-test-class.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/foo-get-default-response.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/foo-get-default-response.ts index 010ffd4b422f..1891c0a8e371 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/foo-get-default-response.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/foo-get-default-response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Foo } from './foo'; import { FooFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/foo.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/foo.ts index 843b44d30811..265c8bb9a8d7 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/foo.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/foo.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/format-test.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/format-test.ts index 047bde78c359..aa1f8c7f1518 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/format-test.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/format-test.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export @@ -116,8 +116,8 @@ export function FormatTestFromJSONTyped(json: any, ignoreDiscriminator: boolean) 'string': json['string'] == null ? undefined : json['string'], '_byte': json['byte'], 'binary': json['binary'] == null ? undefined : json['binary'], - 'date': (new Date(json['date'])), - 'dateTime': json['dateTime'] == null ? undefined : (new Date(json['dateTime'])), + 'date': (parseDate(json['date'])), + 'dateTime': json['dateTime'] == null ? undefined : (parseDateTime(json['dateTime'])), 'uuid': json['uuid'] == null ? undefined : json['uuid'], 'password': json['password'], 'patternWithDigits': json['pattern_with_digits'] == null ? undefined : json['pattern_with_digits'], @@ -146,8 +146,8 @@ export function FormatTestToJSONTyped(value?: FormatTest | null, ignoreDiscrimin 'string': value['string'], 'byte': value['_byte'], 'binary': value['binary'], - 'date': value['date'].toISOString().substring(0,10), - 'dateTime': value['dateTime'] == null ? value['dateTime'] : value['dateTime'].toISOString(), + 'date': serializeDate(value['date']), + 'dateTime': value['dateTime'] == null ? value['dateTime'] : serializeDateTime(value['dateTime']), 'uuid': value['uuid'], 'password': value['password'], 'pattern_with_digits': value['patternWithDigits'], diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/has-only-read-only.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/has-only-read-only.ts index b81e989b86d4..93656b13dc8f 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/has-only-read-only.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/has-only-read-only.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/health-check-result.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/health-check-result.ts index 520e91e780bd..01c77603870f 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/health-check-result.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/health-check-result.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model. * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/list.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/list.ts index a51be9f76c2c..4f585b061668 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/list.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/list.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/map-test.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/map-test.ts index 18ea456c8951..f7a65d7e8822 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/map-test.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/map-test.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/mixed-properties-and-additional-properties-class.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/mixed-properties-and-additional-properties-class.ts index 71e0fa8b1ff9..7b5468177b35 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/mixed-properties-and-additional-properties-class.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/mixed-properties-and-additional-properties-class.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Animal } from './animal'; import { AnimalFromJSON, @@ -59,7 +59,7 @@ export function MixedPropertiesAndAdditionalPropertiesClassFromJSONTyped(json: a return { 'uuid': json['uuid'] == null ? undefined : json['uuid'], - 'dateTime': json['dateTime'] == null ? undefined : (new Date(json['dateTime'])), + 'dateTime': json['dateTime'] == null ? undefined : (parseDateTime(json['dateTime'])), 'map': json['map'] == null ? undefined : (mapValues(json['map'], AnimalFromJSON)), }; } @@ -76,7 +76,7 @@ export function MixedPropertiesAndAdditionalPropertiesClassToJSONTyped(value?: M return { 'uuid': value['uuid'], - 'dateTime': value['dateTime'] == null ? value['dateTime'] : value['dateTime'].toISOString(), + 'dateTime': value['dateTime'] == null ? value['dateTime'] : serializeDateTime(value['dateTime']), 'map': value['map'] == null ? undefined : (mapValues(value['map'], AnimalToJSON)), }; } diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model-api-response.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model-api-response.ts index 8e8b92dc4228..4650d81f3a85 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model-api-response.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model-api-response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model-file.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model-file.ts index e823e6cd03cc..2eaf8fd20162 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model-file.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model-file.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Must be named `File` for test. * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model200-response.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model200-response.ts index 62f11d4d4e5a..98089b550456 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model200-response.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model200-response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Model for testing model name starting with number * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/name.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/name.ts index 4b7ed42911fb..cedfa4b67db8 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/name.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/name.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Model for testing model name same as property name * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/nullable-class.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/nullable-class.ts index 2899b9f6f3d6..e917dc5109d3 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/nullable-class.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/nullable-class.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export @@ -92,8 +92,8 @@ export function NullableClassFromJSONTyped(json: any, ignoreDiscriminator: boole 'numberProp': json['number_prop'] === undefined ? undefined : json['number_prop'] === null ? null : json['number_prop'], 'booleanProp': json['boolean_prop'] === undefined ? undefined : json['boolean_prop'] === null ? null : json['boolean_prop'], 'stringProp': json['string_prop'] === undefined ? undefined : json['string_prop'] === null ? null : json['string_prop'], - 'dateProp': json['date_prop'] === undefined ? undefined : json['date_prop'] === null ? null : (new Date(json['date_prop'])), - 'datetimeProp': json['datetime_prop'] === undefined ? undefined : json['datetime_prop'] === null ? null : (new Date(json['datetime_prop'])), + 'dateProp': json['date_prop'] === undefined ? undefined : json['date_prop'] === null ? null : (parseDate(json['date_prop'])), + 'datetimeProp': json['datetime_prop'] === undefined ? undefined : json['datetime_prop'] === null ? null : (parseDateTime(json['datetime_prop'])), 'arrayNullableProp': json['array_nullable_prop'] === undefined ? undefined : json['array_nullable_prop'] === null ? null : json['array_nullable_prop'], 'arrayAndItemsNullableProp': json['array_and_items_nullable_prop'] === undefined ? undefined : json['array_and_items_nullable_prop'] === null ? null : json['array_and_items_nullable_prop'], 'arrayItemsNullable': json['array_items_nullable'] == null ? undefined : json['array_items_nullable'], @@ -119,8 +119,8 @@ export function NullableClassToJSONTyped(value?: NullableClass | null, ignoreDis 'number_prop': value['numberProp'], 'boolean_prop': value['booleanProp'], 'string_prop': value['stringProp'], - 'date_prop': value['dateProp'] == null ? value['dateProp'] : value['dateProp'].toISOString().substring(0,10), - 'datetime_prop': value['datetimeProp'] == null ? value['datetimeProp'] : value['datetimeProp'].toISOString(), + 'date_prop': value['dateProp'] == null ? value['dateProp'] : serializeDate(value['dateProp']), + 'datetime_prop': value['datetimeProp'] == null ? value['datetimeProp'] : serializeDateTime(value['datetimeProp']), 'array_nullable_prop': value['arrayNullableProp'], 'array_and_items_nullable_prop': value['arrayAndItemsNullableProp'], 'array_items_nullable': value['arrayItemsNullable'], diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/number-only.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/number-only.ts index b899ac447f22..bab9610104f4 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/number-only.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/number-only.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/object-with-deprecated-fields.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/object-with-deprecated-fields.ts index 1491b14913df..6b0b8f88c2f5 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/object-with-deprecated-fields.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/object-with-deprecated-fields.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { DeprecatedObject } from './deprecated-object'; import { DeprecatedObjectFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/order.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/order.ts index 1d32da2609f6..8cb7d0bb68bb 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/order.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/order.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export @@ -77,7 +77,7 @@ export function OrderFromJSONTyped(json: any, ignoreDiscriminator: boolean): Ord 'id': json['id'] == null ? undefined : json['id'], 'petId': json['petId'] == null ? undefined : json['petId'], 'quantity': json['quantity'] == null ? undefined : json['quantity'], - 'shipDate': json['shipDate'] == null ? undefined : (new Date(json['shipDate'])), + 'shipDate': json['shipDate'] == null ? undefined : (parseDateTime(json['shipDate'])), 'status': json['status'] == null ? undefined : json['status'], 'complete': json['complete'] == null ? undefined : json['complete'], }; @@ -97,7 +97,7 @@ export function OrderToJSONTyped(value?: Order | null, ignoreDiscriminator: bool 'id': value['id'], 'petId': value['petId'], 'quantity': value['quantity'], - 'shipDate': value['shipDate'] == null ? value['shipDate'] : value['shipDate'].toISOString(), + 'shipDate': value['shipDate'] == null ? value['shipDate'] : serializeDateTime(value['shipDate']), 'status': value['status'], 'complete': value['complete'], }; diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/outer-composite.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/outer-composite.ts index f3375c3124f7..bde6e9963ef6 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/outer-composite.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/outer-composite.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/outer-object-with-enum-property.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/outer-object-with-enum-property.ts index 1ebc71806729..bc604a7827b3 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/outer-object-with-enum-property.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/outer-object-with-enum-property.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { OuterEnumInteger } from './outer-enum-integer'; import { OuterEnumIntegerFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/parent-with-nullable.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/parent-with-nullable.ts index 0eedf046f63c..b59604b5d13b 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/parent-with-nullable.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/parent-with-nullable.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import { type ChildWithNullable, ChildWithNullableFromJSONTyped, ChildWithNullableToJSON, ChildWithNullableToJSONTyped } from './ChildWithNullable'; /** * diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/pet.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/pet.ts index add649416353..f29f7917399c 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Category } from './category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/read-only-first.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/read-only-first.ts index 3a80d04b6d6d..99d7deac013e 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/read-only-first.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/read-only-first.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/return.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/return.ts index c0b3275a6ed8..652fabd69106 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/return.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/return.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Model for testing reserved words * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/special-model-name.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/special-model-name.ts index d13618509744..763e45b6ee39 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/special-model-name.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/special-model-name.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/tag.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/tag.ts index a0caf8140a38..55fc45e2c9a5 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/test-inline-freeform-additional-properties-request.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/test-inline-freeform-additional-properties-request.ts index b11489089d02..5e453f9ea286 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/test-inline-freeform-additional-properties-request.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/test-inline-freeform-additional-properties-request.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/user.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/user.ts index 207ad34596fc..d09fd6f21295 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/user.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/user.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/runtime.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/runtime.ts index e52a36947b03..9a57ab110acb 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Category.ts index cdffe07db910..d4ff2b5e4d9a 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A category for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/ModelApiResponse.ts index f89423073868..71da44967c79 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Describes the result of uploading an image resource * @export diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Order.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Order.ts index cb6b5c016de6..e47ffdb65be7 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Order.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Order.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * An order for a pets from the pet store * @export @@ -77,7 +77,7 @@ export function OrderFromJSONTyped(json: any, ignoreDiscriminator: boolean): Ord 'id': json['id'] == null ? undefined : json['id'], 'petId': json['petId'] == null ? undefined : json['petId'], 'quantity': json['quantity'] == null ? undefined : json['quantity'], - 'shipDate': json['shipDate'] == null ? undefined : (new Date(json['shipDate'])), + 'shipDate': json['shipDate'] == null ? undefined : (parseDateTime(json['shipDate'])), 'status': json['status'] == null ? undefined : json['status'], 'complete': json['complete'] == null ? undefined : json['complete'], }; @@ -97,7 +97,7 @@ export function OrderToJSONTyped(value?: Order | null, ignoreDiscriminator: bool 'id': value['id'], 'petId': value['petId'], 'quantity': value['quantity'], - 'shipDate': value['shipDate'] == null ? value['shipDate'] : value['shipDate'].toISOString(), + 'shipDate': value['shipDate'] == null ? value['shipDate'] : serializeDateTime(value['shipDate']), 'status': value['status'], 'complete': value['complete'], }; diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Pet.ts index 4c0cb6e73685..8230f3435432 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Tag.ts index 80126e24919e..83b9ad7dcb3f 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A tag for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/User.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/User.ts index 68e240e4afb3..59dfa0baec26 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A User who is purchasing from the pet store * @export diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts index 3389e4beb1cc..7d4323ad5e99 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/DashedOptionOne.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/DashedOptionOne.ts index 42b09a797522..159a8eeaddcd 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/DashedOptionOne.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/DashedOptionOne.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/DashedOptionTwo.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/DashedOptionTwo.ts index a7f16917f6de..d3f6103f6de7 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/DashedOptionTwo.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/DashedOptionTwo.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/NumericSingletonEnumModel.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/NumericSingletonEnumModel.ts index 45551ae6a917..bd4facf17ec7 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/NumericSingletonEnumModel.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/NumericSingletonEnumModel.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/OptionOne.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/OptionOne.ts index ccfc53dfe05e..5327fef74811 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/OptionOne.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/OptionOne.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/OptionTwo.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/OptionTwo.ts index ff75902cb6fd..492a0f9b33a7 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/OptionTwo.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/OptionTwo.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/SnakeOptionOne.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/SnakeOptionOne.ts index d738d4d73a15..a6c376e6fe94 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/SnakeOptionOne.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/SnakeOptionOne.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/SnakeOptionTwo.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/SnakeOptionTwo.ts index c8b1f9451572..c1b5976c26be 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/SnakeOptionTwo.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/SnakeOptionTwo.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestA.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestA.ts index fe0962f260bb..d4f52060df5b 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestA.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestA.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestArrayResponse.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestArrayResponse.ts index e496b66889d1..af3bbd2a6269 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestArrayResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestArrayResponse.ts @@ -12,6 +12,7 @@ * Do not edit the class manually. */ +import { parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { TestA } from './TestA'; import { instanceOfTestA, diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestB.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestB.ts index ec828078dec6..2bcd659b825d 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestB.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestB.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestDashedDiscriminatorResponse.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestDashedDiscriminatorResponse.ts index 260fb9107164..6f59236379f1 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestDashedDiscriminatorResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestDashedDiscriminatorResponse.ts @@ -12,6 +12,7 @@ * Do not edit the class manually. */ +import { parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { DashedOptionOne } from './DashedOptionOne'; import { instanceOfDashedOptionOne, diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestDiscriminatorResponse.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestDiscriminatorResponse.ts index ae5af3d46ba8..8ebcc75e7186 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestDiscriminatorResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestDiscriminatorResponse.ts @@ -12,6 +12,7 @@ * Do not edit the class manually. */ +import { parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { OptionOne } from './OptionOne'; import { instanceOfOptionOne, diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestResponse.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestResponse.ts index 031d545e20bc..ca45996d992e 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestResponse.ts @@ -12,6 +12,7 @@ * Do not edit the class manually. */ +import { parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { TestA } from './TestA'; import { instanceOfTestA, diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestSnakeCaseDiscriminatorResponse.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestSnakeCaseDiscriminatorResponse.ts index 34a297e86d47..dfba021f0bbb 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestSnakeCaseDiscriminatorResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestSnakeCaseDiscriminatorResponse.ts @@ -12,6 +12,7 @@ * Do not edit the class manually. */ +import { parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { SnakeOptionOne } from './SnakeOptionOne'; import { instanceOfSnakeOptionOne, diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/runtime.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/runtime.ts index 8c8a505df958..96f7409806d3 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Category.ts index cdffe07db910..d4ff2b5e4d9a 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A category for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/ModelApiResponse.ts index f89423073868..71da44967c79 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Describes the result of uploading an image resource * @export diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Order.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Order.ts index cb6b5c016de6..e47ffdb65be7 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Order.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Order.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * An order for a pets from the pet store * @export @@ -77,7 +77,7 @@ export function OrderFromJSONTyped(json: any, ignoreDiscriminator: boolean): Ord 'id': json['id'] == null ? undefined : json['id'], 'petId': json['petId'] == null ? undefined : json['petId'], 'quantity': json['quantity'] == null ? undefined : json['quantity'], - 'shipDate': json['shipDate'] == null ? undefined : (new Date(json['shipDate'])), + 'shipDate': json['shipDate'] == null ? undefined : (parseDateTime(json['shipDate'])), 'status': json['status'] == null ? undefined : json['status'], 'complete': json['complete'] == null ? undefined : json['complete'], }; @@ -97,7 +97,7 @@ export function OrderToJSONTyped(value?: Order | null, ignoreDiscriminator: bool 'id': value['id'], 'petId': value['petId'], 'quantity': value['quantity'], - 'shipDate': value['shipDate'] == null ? value['shipDate'] : value['shipDate'].toISOString(), + 'shipDate': value['shipDate'] == null ? value['shipDate'] : serializeDateTime(value['shipDate']), 'status': value['status'], 'complete': value['complete'], }; diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Pet.ts index 4c0cb6e73685..8230f3435432 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Tag.ts index 80126e24919e..83b9ad7dcb3f 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A tag for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/User.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/User.ts index 68e240e4afb3..59dfa0baec26 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A User who is purchasing from the pet store * @export diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts index 3389e4beb1cc..7d4323ad5e99 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Category.ts index cdffe07db910..d4ff2b5e4d9a 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A category for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/DefaultMetaOnlyResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/DefaultMetaOnlyResponse.ts index 032fabdfc4b0..eb2f43d628c6 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/DefaultMetaOnlyResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/DefaultMetaOnlyResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { ResponseMeta } from './ResponseMeta'; import { ResponseMetaFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/FindPetsByStatusResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/FindPetsByStatusResponse.ts index 3dd03e912526..fee211391474 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/FindPetsByStatusResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/FindPetsByStatusResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { ResponseMeta } from './ResponseMeta'; import { ResponseMetaFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/FindPetsByUserResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/FindPetsByUserResponse.ts index 575ab1f0413e..daf85cacbcc9 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/FindPetsByUserResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/FindPetsByUserResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { User } from './User'; import { UserFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetBehaviorPermissionsResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetBehaviorPermissionsResponse.ts index 3fbab7b0499f..6ed81a22fac9 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetBehaviorPermissionsResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetBehaviorPermissionsResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { ResponseMeta } from './ResponseMeta'; import { ResponseMetaFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetBehaviorTypeResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetBehaviorTypeResponse.ts index a7ac60073220..c21ba3be783d 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetBehaviorTypeResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetBehaviorTypeResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { BehaviorType } from './BehaviorType'; import { BehaviorTypeFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetMatchingPartsResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetMatchingPartsResponse.ts index 1545eb7cb80a..fae2fa423428 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetMatchingPartsResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetMatchingPartsResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { ResponseMeta } from './ResponseMeta'; import { ResponseMetaFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetPetPartTypeResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetPetPartTypeResponse.ts index d70ad8ee64d9..3cd20a38a830 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetPetPartTypeResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetPetPartTypeResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { ResponseMeta } from './ResponseMeta'; import { ResponseMetaFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ItemId.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ItemId.ts index 18103ba2ee18..865c9e48c685 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ItemId.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ItemId.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Simplified identifier of an item * @export diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/MatchingParts.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/MatchingParts.ts index d323c477e85d..892e52ea29d0 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/MatchingParts.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/MatchingParts.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Part } from './Part'; import { PartFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ModelApiResponse.ts index f89423073868..71da44967c79 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Describes the result of uploading an image resource * @export diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ModelError.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ModelError.ts index 6dae6855c8a5..ec5fbfb8d8fa 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ModelError.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ModelError.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { ItemId } from './ItemId'; import { ItemIdFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Order.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Order.ts index cb6b5c016de6..e47ffdb65be7 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Order.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Order.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * An order for a pets from the pet store * @export @@ -77,7 +77,7 @@ export function OrderFromJSONTyped(json: any, ignoreDiscriminator: boolean): Ord 'id': json['id'] == null ? undefined : json['id'], 'petId': json['petId'] == null ? undefined : json['petId'], 'quantity': json['quantity'] == null ? undefined : json['quantity'], - 'shipDate': json['shipDate'] == null ? undefined : (new Date(json['shipDate'])), + 'shipDate': json['shipDate'] == null ? undefined : (parseDateTime(json['shipDate'])), 'status': json['status'] == null ? undefined : json['status'], 'complete': json['complete'] == null ? undefined : json['complete'], }; @@ -97,7 +97,7 @@ export function OrderToJSONTyped(value?: Order | null, ignoreDiscriminator: bool 'id': value['id'], 'petId': value['petId'], 'quantity': value['quantity'], - 'shipDate': value['shipDate'] == null ? value['shipDate'] : value['shipDate'].toISOString(), + 'shipDate': value['shipDate'] == null ? value['shipDate'] : serializeDateTime(value['shipDate']), 'status': value['status'], 'complete': value['complete'], }; diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Part.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Part.ts index 043bbec9d1cc..ef1223205b87 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Part.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Part.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Contains all the info about a pet part * @export diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Pet.ts index 3d20dc56c6c8..56994baf4bb1 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/PetRegionsResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/PetRegionsResponse.ts index c769237d5e3a..1a17bc156581 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/PetRegionsResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/PetRegionsResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { ResponseMeta } from './ResponseMeta'; import { ResponseMetaFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ResponseMeta.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ResponseMeta.ts index df38da1be6e4..a56ded1b063f 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ResponseMeta.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ResponseMeta.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { ErrorCode } from './ErrorCode'; import { ErrorCodeFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Tag.ts index 80126e24919e..83b9ad7dcb3f 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A tag for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/User.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/User.ts index ce78194e47f1..83108d636c33 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A User who is purchasing from the pet store * @export diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts index 3389e4beb1cc..7d4323ad5e99 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/apis/FakeApi.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/apis/FakeApi.ts index 9514b1d2ab5a..168fee1b1454 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/apis/FakeApi.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/apis/FakeApi.ts @@ -959,11 +959,11 @@ export class FakeApi extends runtime.BaseAPI { } if (requestParameters['date'] != null) { - formParams.append('date', requestParameters['date'] as any); + formParams.append('date', runtime.serializeDate(requestParameters['date'] as any)); } if (requestParameters['dateTime'] != null) { - formParams.append('dateTime', (requestParameters['dateTime'] as any).toISOString()); + formParams.append('dateTime', runtime.serializeDateTime(requestParameters['dateTime'] as any)); } if (requestParameters['password'] != null) { diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/AdditionalPropertiesClass.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/AdditionalPropertiesClass.ts index 1db920000504..f2dc71ebdaf6 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/AdditionalPropertiesClass.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/AdditionalPropertiesClass.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/AllOfWithSingleRef.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/AllOfWithSingleRef.ts index 743b9141a1af..48d511219088 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/AllOfWithSingleRef.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/AllOfWithSingleRef.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { SingleRefType } from './SingleRefType'; import { SingleRefTypeFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Animal.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Animal.ts index 3b1b2fcdc204..577770de18a9 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Animal.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Animal.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import { type Cat, CatFromJSONTyped, CatToJSON, CatToJSONTyped } from './Cat'; import { type Dog, DogFromJSONTyped, DogToJSON, DogToJSONTyped } from './Dog'; /** diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayOfArrayOfNumberOnly.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayOfArrayOfNumberOnly.ts index bce79e8d3b63..eb46a92a17f4 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayOfArrayOfNumberOnly.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayOfArrayOfNumberOnly.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayOfNumberOnly.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayOfNumberOnly.ts index 8640a0d74aa5..58a124c4d597 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayOfNumberOnly.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayOfNumberOnly.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayTest.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayTest.ts index 002052b417d3..209bc6d83544 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayTest.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayTest.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { ReadOnlyFirst } from './ReadOnlyFirst'; import { ReadOnlyFirstFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Capitalization.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Capitalization.ts index de75ac5926d6..e1ae19d0722d 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Capitalization.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Capitalization.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Cat.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Cat.ts index 33efae9ddcf9..6744be5087c2 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Cat.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Cat.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Animal } from './Animal'; import { AnimalFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Category.ts index 04cd593f2dce..f5c1719da512 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ClassModel.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ClassModel.ts index cef4c58640ce..39f27a81ee3a 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ClassModel.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ClassModel.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Model for testing model with "_class" property * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Client.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Client.ts index 7f353720b90d..39f16473b2db 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Client.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Client.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/DeprecatedObject.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/DeprecatedObject.ts index 14623160e258..5264e69b1e0b 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/DeprecatedObject.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/DeprecatedObject.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Dog.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Dog.ts index 967f5cf772f2..cec03d19fee0 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Dog.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Dog.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Animal } from './Animal'; import { AnimalFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumArrays.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumArrays.ts index 84cd87dd1408..88d2b45098c5 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumArrays.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumArrays.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumTest.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumTest.ts index 4c27767e593c..58374a3bc6cf 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumTest.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumTest.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { OuterEnum } from './OuterEnum'; import { OuterEnumFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FakeBigDecimalMap200Response.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FakeBigDecimalMap200Response.ts index ed87ea529d3d..097fae0be926 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FakeBigDecimalMap200Response.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FakeBigDecimalMap200Response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FileSchemaTestClass.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FileSchemaTestClass.ts index 4dcd0b2ed2c4..9f5f785effe6 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FileSchemaTestClass.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FileSchemaTestClass.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Foo.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Foo.ts index 843b44d30811..265c8bb9a8d7 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Foo.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Foo.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FooGetDefaultResponse.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FooGetDefaultResponse.ts index d12c4924c2f3..cdf9c480ebc7 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FooGetDefaultResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FooGetDefaultResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Foo } from './Foo'; import { FooFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FormatTest.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FormatTest.ts index 047bde78c359..aa1f8c7f1518 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FormatTest.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FormatTest.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export @@ -116,8 +116,8 @@ export function FormatTestFromJSONTyped(json: any, ignoreDiscriminator: boolean) 'string': json['string'] == null ? undefined : json['string'], '_byte': json['byte'], 'binary': json['binary'] == null ? undefined : json['binary'], - 'date': (new Date(json['date'])), - 'dateTime': json['dateTime'] == null ? undefined : (new Date(json['dateTime'])), + 'date': (parseDate(json['date'])), + 'dateTime': json['dateTime'] == null ? undefined : (parseDateTime(json['dateTime'])), 'uuid': json['uuid'] == null ? undefined : json['uuid'], 'password': json['password'], 'patternWithDigits': json['pattern_with_digits'] == null ? undefined : json['pattern_with_digits'], @@ -146,8 +146,8 @@ export function FormatTestToJSONTyped(value?: FormatTest | null, ignoreDiscrimin 'string': value['string'], 'byte': value['_byte'], 'binary': value['binary'], - 'date': value['date'].toISOString().substring(0,10), - 'dateTime': value['dateTime'] == null ? value['dateTime'] : value['dateTime'].toISOString(), + 'date': serializeDate(value['date']), + 'dateTime': value['dateTime'] == null ? value['dateTime'] : serializeDateTime(value['dateTime']), 'uuid': value['uuid'], 'password': value['password'], 'pattern_with_digits': value['patternWithDigits'], diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/HasOnlyReadOnly.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/HasOnlyReadOnly.ts index b81e989b86d4..93656b13dc8f 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/HasOnlyReadOnly.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/HasOnlyReadOnly.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/HealthCheckResult.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/HealthCheckResult.ts index 520e91e780bd..01c77603870f 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/HealthCheckResult.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/HealthCheckResult.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model. * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/List.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/List.ts index a51be9f76c2c..4f585b061668 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/List.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/List.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/MapTest.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/MapTest.ts index 18ea456c8951..f7a65d7e8822 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/MapTest.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/MapTest.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/MixedPropertiesAndAdditionalPropertiesClass.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/MixedPropertiesAndAdditionalPropertiesClass.ts index cb7a2989f0c9..29e136055639 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/MixedPropertiesAndAdditionalPropertiesClass.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/MixedPropertiesAndAdditionalPropertiesClass.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Animal } from './Animal'; import { AnimalFromJSON, @@ -59,7 +59,7 @@ export function MixedPropertiesAndAdditionalPropertiesClassFromJSONTyped(json: a return { 'uuid': json['uuid'] == null ? undefined : json['uuid'], - 'dateTime': json['dateTime'] == null ? undefined : (new Date(json['dateTime'])), + 'dateTime': json['dateTime'] == null ? undefined : (parseDateTime(json['dateTime'])), 'map': json['map'] == null ? undefined : (mapValues(json['map'], AnimalFromJSON)), }; } @@ -76,7 +76,7 @@ export function MixedPropertiesAndAdditionalPropertiesClassToJSONTyped(value?: M return { 'uuid': value['uuid'], - 'dateTime': value['dateTime'] == null ? value['dateTime'] : value['dateTime'].toISOString(), + 'dateTime': value['dateTime'] == null ? value['dateTime'] : serializeDateTime(value['dateTime']), 'map': value['map'] == null ? undefined : (mapValues(value['map'], AnimalToJSON)), }; } diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Model200Response.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Model200Response.ts index 62f11d4d4e5a..98089b550456 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Model200Response.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Model200Response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Model for testing model name starting with number * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ModelApiResponse.ts index 8e8b92dc4228..4650d81f3a85 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ModelFile.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ModelFile.ts index e823e6cd03cc..2eaf8fd20162 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ModelFile.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ModelFile.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Must be named `File` for test. * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Name.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Name.ts index 4b7ed42911fb..cedfa4b67db8 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Name.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Name.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Model for testing model name same as property name * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/NullableClass.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/NullableClass.ts index 2899b9f6f3d6..e917dc5109d3 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/NullableClass.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/NullableClass.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export @@ -92,8 +92,8 @@ export function NullableClassFromJSONTyped(json: any, ignoreDiscriminator: boole 'numberProp': json['number_prop'] === undefined ? undefined : json['number_prop'] === null ? null : json['number_prop'], 'booleanProp': json['boolean_prop'] === undefined ? undefined : json['boolean_prop'] === null ? null : json['boolean_prop'], 'stringProp': json['string_prop'] === undefined ? undefined : json['string_prop'] === null ? null : json['string_prop'], - 'dateProp': json['date_prop'] === undefined ? undefined : json['date_prop'] === null ? null : (new Date(json['date_prop'])), - 'datetimeProp': json['datetime_prop'] === undefined ? undefined : json['datetime_prop'] === null ? null : (new Date(json['datetime_prop'])), + 'dateProp': json['date_prop'] === undefined ? undefined : json['date_prop'] === null ? null : (parseDate(json['date_prop'])), + 'datetimeProp': json['datetime_prop'] === undefined ? undefined : json['datetime_prop'] === null ? null : (parseDateTime(json['datetime_prop'])), 'arrayNullableProp': json['array_nullable_prop'] === undefined ? undefined : json['array_nullable_prop'] === null ? null : json['array_nullable_prop'], 'arrayAndItemsNullableProp': json['array_and_items_nullable_prop'] === undefined ? undefined : json['array_and_items_nullable_prop'] === null ? null : json['array_and_items_nullable_prop'], 'arrayItemsNullable': json['array_items_nullable'] == null ? undefined : json['array_items_nullable'], @@ -119,8 +119,8 @@ export function NullableClassToJSONTyped(value?: NullableClass | null, ignoreDis 'number_prop': value['numberProp'], 'boolean_prop': value['booleanProp'], 'string_prop': value['stringProp'], - 'date_prop': value['dateProp'] == null ? value['dateProp'] : value['dateProp'].toISOString().substring(0,10), - 'datetime_prop': value['datetimeProp'] == null ? value['datetimeProp'] : value['datetimeProp'].toISOString(), + 'date_prop': value['dateProp'] == null ? value['dateProp'] : serializeDate(value['dateProp']), + 'datetime_prop': value['datetimeProp'] == null ? value['datetimeProp'] : serializeDateTime(value['datetimeProp']), 'array_nullable_prop': value['arrayNullableProp'], 'array_and_items_nullable_prop': value['arrayAndItemsNullableProp'], 'array_items_nullable': value['arrayItemsNullable'], diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/NumberOnly.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/NumberOnly.ts index b899ac447f22..bab9610104f4 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/NumberOnly.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/NumberOnly.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ObjectWithDeprecatedFields.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ObjectWithDeprecatedFields.ts index 73a8eb403427..d17040b0b56e 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ObjectWithDeprecatedFields.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ObjectWithDeprecatedFields.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { DeprecatedObject } from './DeprecatedObject'; import { DeprecatedObjectFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Order.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Order.ts index 1d32da2609f6..8cb7d0bb68bb 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Order.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Order.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export @@ -77,7 +77,7 @@ export function OrderFromJSONTyped(json: any, ignoreDiscriminator: boolean): Ord 'id': json['id'] == null ? undefined : json['id'], 'petId': json['petId'] == null ? undefined : json['petId'], 'quantity': json['quantity'] == null ? undefined : json['quantity'], - 'shipDate': json['shipDate'] == null ? undefined : (new Date(json['shipDate'])), + 'shipDate': json['shipDate'] == null ? undefined : (parseDateTime(json['shipDate'])), 'status': json['status'] == null ? undefined : json['status'], 'complete': json['complete'] == null ? undefined : json['complete'], }; @@ -97,7 +97,7 @@ export function OrderToJSONTyped(value?: Order | null, ignoreDiscriminator: bool 'id': value['id'], 'petId': value['petId'], 'quantity': value['quantity'], - 'shipDate': value['shipDate'] == null ? value['shipDate'] : value['shipDate'].toISOString(), + 'shipDate': value['shipDate'] == null ? value['shipDate'] : serializeDateTime(value['shipDate']), 'status': value['status'], 'complete': value['complete'], }; diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterComposite.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterComposite.ts index f3375c3124f7..bde6e9963ef6 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterComposite.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterComposite.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterObjectWithEnumProperty.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterObjectWithEnumProperty.ts index 420c964cd78b..5ea61247a3ed 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterObjectWithEnumProperty.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterObjectWithEnumProperty.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { OuterEnumInteger } from './OuterEnumInteger'; import { OuterEnumIntegerFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Pet.ts index 20d21e2f1aad..d90d4d1cf971 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ReadOnlyFirst.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ReadOnlyFirst.ts index 3a80d04b6d6d..99d7deac013e 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ReadOnlyFirst.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ReadOnlyFirst.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Return.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Return.ts index c0b3275a6ed8..652fabd69106 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Return.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Return.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Model for testing reserved words * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/SpecialModelName.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/SpecialModelName.ts index d13618509744..763e45b6ee39 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/SpecialModelName.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/SpecialModelName.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Tag.ts index a0caf8140a38..55fc45e2c9a5 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/User.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/User.ts index 207ad34596fc..d09fd6f21295 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/runtime.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/runtime.ts index e52a36947b03..9a57ab110acb 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Category.ts index 7a5fb6a636ea..31d9e8d6dfdf 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A category for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/ModelApiResponse.ts index 94dbefb8376a..4809607b702c 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Describes the result of uploading an image resource * @export diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Order.ts b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Order.ts index 0ad9b3725c98..cbe0a8b71b0e 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Order.ts +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Order.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * An order for a pets from the pet store * @export @@ -103,7 +103,7 @@ export function OrderFromJSONTyped(json: any, ignoreDiscriminator: boolean): Ord 'id': json['id'] == null ? undefined : json['id'], 'petId': json['petId'] == null ? undefined : json['petId'], 'quantity': json['quantity'] == null ? undefined : json['quantity'], - 'shipDate': json['shipDate'] == null ? undefined : (new Date(json['shipDate'])), + 'shipDate': json['shipDate'] == null ? undefined : (parseDateTime(json['shipDate'])), 'status': json['status'] == null ? undefined : json['status'], 'complete': json['complete'] == null ? undefined : json['complete'], }; @@ -124,7 +124,7 @@ export function OrderToJSONTyped(value?: Order | null, ignoreDiscriminator: bool 'id': value['id'], 'petId': value['petId'], 'quantity': value['quantity'], - 'shipDate': value['shipDate'] == null ? value['shipDate'] : value['shipDate'].toISOString(), + 'shipDate': value['shipDate'] == null ? value['shipDate'] : serializeDateTime(value['shipDate']), 'status': value['status'], 'complete': value['complete'], }; diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Pet.ts index cde0e7b42de0..383e5475fbcd 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Tag.ts index b6222ddd699c..452ea74fb49c 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A tag for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/User.ts b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/User.ts index af745c1ee60e..1263e9173f30 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A User who is purchasing from the pet store * @export diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/runtime.ts b/samples/client/petstore/typescript-fetch/builds/validation-attributes/runtime.ts index 3389e4beb1cc..7d4323ad5e99 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Category.ts index cdffe07db910..d4ff2b5e4d9a 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A category for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/ModelApiResponse.ts index f89423073868..71da44967c79 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Describes the result of uploading an image resource * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Order.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Order.ts index cb6b5c016de6..e47ffdb65be7 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Order.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Order.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * An order for a pets from the pet store * @export @@ -77,7 +77,7 @@ export function OrderFromJSONTyped(json: any, ignoreDiscriminator: boolean): Ord 'id': json['id'] == null ? undefined : json['id'], 'petId': json['petId'] == null ? undefined : json['petId'], 'quantity': json['quantity'] == null ? undefined : json['quantity'], - 'shipDate': json['shipDate'] == null ? undefined : (new Date(json['shipDate'])), + 'shipDate': json['shipDate'] == null ? undefined : (parseDateTime(json['shipDate'])), 'status': json['status'] == null ? undefined : json['status'], 'complete': json['complete'] == null ? undefined : json['complete'], }; @@ -97,7 +97,7 @@ export function OrderToJSONTyped(value?: Order | null, ignoreDiscriminator: bool 'id': value['id'], 'petId': value['petId'], 'quantity': value['quantity'], - 'shipDate': value['shipDate'] == null ? value['shipDate'] : value['shipDate'].toISOString(), + 'shipDate': value['shipDate'] == null ? value['shipDate'] : serializeDateTime(value['shipDate']), 'status': value['status'], 'complete': value['complete'], }; diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Pet.ts index 4c0cb6e73685..8230f3435432 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Tag.ts index 80126e24919e..83b9ad7dcb3f 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A tag for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/User.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/User.ts index 68e240e4afb3..59dfa0baec26 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A User who is purchasing from the pet store * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts index 3389e4beb1cc..7d4323ad5e99 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Category.ts index cdffe07db910..d4ff2b5e4d9a 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A category for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/ModelApiResponse.ts index f89423073868..71da44967c79 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * Describes the result of uploading an image resource * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Order.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Order.ts index cb6b5c016de6..e47ffdb65be7 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Order.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Order.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * An order for a pets from the pet store * @export @@ -77,7 +77,7 @@ export function OrderFromJSONTyped(json: any, ignoreDiscriminator: boolean): Ord 'id': json['id'] == null ? undefined : json['id'], 'petId': json['petId'] == null ? undefined : json['petId'], 'quantity': json['quantity'] == null ? undefined : json['quantity'], - 'shipDate': json['shipDate'] == null ? undefined : (new Date(json['shipDate'])), + 'shipDate': json['shipDate'] == null ? undefined : (parseDateTime(json['shipDate'])), 'status': json['status'] == null ? undefined : json['status'], 'complete': json['complete'] == null ? undefined : json['complete'], }; @@ -97,7 +97,7 @@ export function OrderToJSONTyped(value?: Order | null, ignoreDiscriminator: bool 'id': value['id'], 'petId': value['petId'], 'quantity': value['quantity'], - 'shipDate': value['shipDate'] == null ? value['shipDate'] : value['shipDate'].toISOString(), + 'shipDate': value['shipDate'] == null ? value['shipDate'] : serializeDateTime(value['shipDate']), 'status': value['status'], 'complete': value['complete'], }; diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Pet.ts index 4c0cb6e73685..8230f3435432 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Tag.ts index 80126e24919e..83b9ad7dcb3f 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A tag for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/User.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/User.ts index 68e240e4afb3..59dfa0baec26 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * A User who is purchasing from the pet store * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts index 3389e4beb1cc..7d4323ad5e99 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/EnumPatternObject.ts b/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/EnumPatternObject.ts index 0ad7eb19c7df..c686f79ca418 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/EnumPatternObject.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/EnumPatternObject.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; import type { NumberEnum } from './NumberEnum'; import { NumberEnumFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/FakeEnumRequestGetInline200Response.ts b/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/FakeEnumRequestGetInline200Response.ts index caf1f20c75b4..1beee2564028 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/FakeEnumRequestGetInline200Response.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/FakeEnumRequestGetInline200Response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues } from '../runtime'; +import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-string-enums/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-string-enums/runtime.ts index 2d2f267ce4a8..5a2edca34dd6 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-string-enums/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-string-enums/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,42 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + +export function serializeDate(value: Date): string { + const year = String(value.getFullYear()).padStart(4, '0'); + const month = String(value.getMonth() + 1).padStart(2, '0'); + const day = String(value.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} + + +export function parseDate(value: any): Date { + if (value instanceof Date) { + return value; + } + // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. + // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); + if (fullDate) { + return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + } + return new Date(value); +} + +export function parseDateTime(value: any): Date { + return new Date(value); +} + export function mapValues(data: any, fn: (item: any) => any) { const result: { [key: string]: any } = {}; for (const key of Object.keys(data)) { diff --git a/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts index 45dfc650f077..56e2e516c01a 100644 --- a/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts @@ -346,7 +346,7 @@ function querystringSingleKey(key: string, value: string | number | null | undef return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { - return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; + return `${encodeURIComponent(fullKey)}=${encodeURIComponent(serializeDateTime(value))}`; } if (value instanceof Object) { return querystring(value as HTTPQuery, fullKey); @@ -359,6 +359,18 @@ export function exists(json: any, key: string) { return value !== null && value !== undefined; } +/** + * Every generated date call site routes through these. + * + * `format: date` is a calendar date, with no time and no offset, so it is converted + * against the local calendar on both ends: they have to agree or the date shifts by + * a day. `format: date-time` is an instant and uses UTC. + */ +export function serializeDateTime(value: Date): string { + return value.toISOString(); +} + + export function canConsumeForm(consumes: Consume[]): boolean { for (const consume of consumes) { From f83ab68e40acd6f21a2b6406111f1c331258e4fa Mon Sep 17 00:00:00 2001 From: Nicolas Medda Date: Fri, 7 Aug 2026 17:15:19 +0200 Subject: [PATCH 2/2] [typescript-fetch] address review: ES6 target, year 0-99, invalid dates, unused imports - serializeDate no longer uses padStart, which is ES2017: the es6-target sample did not compile against its own tsconfig. - parseDate builds the local date with setFullYear, so years 0000-0099 keep their century instead of picking up the multi-argument Date constructor's 1900 offset ("0045-08-05" was parsed as 1945). - parseDate rejects components that roll over, so an out-of-range date or a day the local zone skipped returns Invalid Date rather than a plausible wrong one. Previously "2026-13-45" became 2027-02-14. - serializeDate throws RangeError on an invalid Date instead of emitting "0NaN-NaN-NaN", matching serializeDateTime. - Models without a date property no longer import the date helpers, via a new x-hasDateVars extension mirroring the template's own branches. This reverts most of the sample churn from the previous commit. Drops testDateFormatUsesTheLocalCalendar: runtime.ts is identical for every spec, so asserting its body only restated the template. The per-build tsconfig typecheck covers the ES6 regression properly. --- .../TypeScriptFetchClientCodegen.java | 7 +++ .../typescript-fetch/modelGeneric.mustache | 2 +- .../typescript-fetch/runtime.mustache | 26 ++++++-- .../TypeScriptFetchClientCodegenTest.java | 18 ++---- .../3_0/typescript-fetch/date-handling.yaml | 6 ++ .../models/StructuredType.ts | 2 +- .../runtime.ts | 26 ++++++-- .../models/ExtendDto.ts | 2 +- .../models/TestBaseDto.ts | 2 +- .../infinite-recursion-issue/runtime.ts | 26 ++++++-- .../multipart-file-array/runtime.ts | 26 ++++++-- .../models/AbstractUserDto.ts | 2 +- .../self-import-issue/models/BranchDto.ts | 2 +- .../models/InternalAuthenticatedUserDto.ts | 2 +- .../models/RemoteAuthenticatedUserDto.ts | 2 +- .../self-import-issue/runtime.ts | 26 ++++++-- .../builds/allOf-nullable/models/Club.ts | 2 +- .../builds/allOf-nullable/models/Owner.ts | 2 +- .../builds/allOf-nullable/runtime.ts | 26 ++++++-- .../builds/allOf-readonly/models/Club.ts | 2 +- .../builds/allOf-readonly/models/Owner.ts | 2 +- .../builds/allOf-readonly/runtime.ts | 26 ++++++-- .../.openapi-generator/FILES | 2 + .../builds/date-library-date/docs/Venue.md | 35 +++++++++++ .../builds/date-library-date/models/Venue.ts | 63 +++++++++++++++++++ .../builds/date-library-date/models/index.ts | 1 + .../builds/date-library-date/runtime.ts | 26 ++++++-- .../.openapi-generator/FILES | 2 + .../builds/date-library-string/docs/Venue.md | 35 +++++++++++ .../date-library-string/models/Venue.ts | 63 +++++++++++++++++++ .../date-library-string/models/index.ts | 1 + .../models/AdditionalPropertiesClass.ts | 2 +- .../default-v3.0/models/AllOfWithSingleRef.ts | 2 +- .../builds/default-v3.0/models/Animal.ts | 2 +- .../models/ArrayOfArrayOfNumberOnly.ts | 2 +- .../default-v3.0/models/ArrayOfNumberOnly.ts | 2 +- .../builds/default-v3.0/models/ArrayTest.ts | 2 +- .../default-v3.0/models/Capitalization.ts | 2 +- .../builds/default-v3.0/models/Cat.ts | 2 +- .../builds/default-v3.0/models/Category.ts | 2 +- .../default-v3.0/models/ChildWithNullable.ts | 2 +- .../builds/default-v3.0/models/ClassModel.ts | 2 +- .../builds/default-v3.0/models/Client.ts | 2 +- .../default-v3.0/models/DeprecatedObject.ts | 2 +- .../builds/default-v3.0/models/Dog.ts | 2 +- .../builds/default-v3.0/models/EnumArrays.ts | 2 +- .../builds/default-v3.0/models/EnumTest.ts | 2 +- .../models/FakeBigDecimalMap200Response.ts | 2 +- .../models/FileSchemaTestClass.ts | 2 +- .../builds/default-v3.0/models/Foo.ts | 2 +- .../models/FooGetDefaultResponse.ts | 2 +- .../default-v3.0/models/HasOnlyReadOnly.ts | 2 +- .../default-v3.0/models/HealthCheckResult.ts | 2 +- .../builds/default-v3.0/models/List.ts | 2 +- .../builds/default-v3.0/models/MapTest.ts | 2 +- .../default-v3.0/models/Model200Response.ts | 2 +- .../default-v3.0/models/ModelApiResponse.ts | 2 +- .../builds/default-v3.0/models/ModelFile.ts | 2 +- .../builds/default-v3.0/models/Name.ts | 2 +- .../builds/default-v3.0/models/NumberOnly.ts | 2 +- .../models/ObjectWithDeprecatedFields.ts | 2 +- .../default-v3.0/models/OuterComposite.ts | 2 +- .../models/OuterObjectWithEnumProperty.ts | 2 +- .../default-v3.0/models/ParentWithNullable.ts | 2 +- .../builds/default-v3.0/models/Pet.ts | 2 +- .../default-v3.0/models/ReadOnlyFirst.ts | 2 +- .../builds/default-v3.0/models/Return.ts | 2 +- .../default-v3.0/models/SpecialModelName.ts | 2 +- .../builds/default-v3.0/models/Tag.ts | 2 +- ...lineFreeformAdditionalPropertiesRequest.ts | 2 +- .../builds/default-v3.0/models/User.ts | 2 +- .../builds/default-v3.0/runtime.ts | 26 ++++++-- .../builds/default/models/Category.ts | 2 +- .../builds/default/models/ModelApiResponse.ts | 2 +- .../builds/default/models/Pet.ts | 2 +- .../builds/default/models/Tag.ts | 2 +- .../builds/default/models/User.ts | 2 +- .../builds/default/runtime.ts | 26 ++++++-- .../builds/enum/models/EnumPatternObject.ts | 2 +- .../FakeEnumRequestGetInline200Response.ts | 2 +- .../typescript-fetch/builds/enum/runtime.ts | 26 ++++++-- .../builds/es6-target/src/models/Category.ts | 2 +- .../es6-target/src/models/ModelApiResponse.ts | 2 +- .../builds/es6-target/src/models/Pet.ts | 2 +- .../builds/es6-target/src/models/Tag.ts | 2 +- .../builds/es6-target/src/models/User.ts | 2 +- .../builds/es6-target/src/runtime.ts | 26 ++++++-- .../models/additional-properties-class.ts | 2 +- .../models/all-of-with-single-ref.ts | 2 +- .../builds/kebab-case/models/animal.ts | 2 +- .../models/array-of-array-of-number-only.ts | 2 +- .../kebab-case/models/array-of-number-only.ts | 2 +- .../builds/kebab-case/models/array-test.ts | 2 +- .../kebab-case/models/capitalization.ts | 2 +- .../builds/kebab-case/models/cat.ts | 2 +- .../builds/kebab-case/models/category.ts | 2 +- .../kebab-case/models/child-with-nullable.ts | 2 +- .../builds/kebab-case/models/class-model.ts | 2 +- .../builds/kebab-case/models/client.ts | 2 +- .../kebab-case/models/deprecated-object.ts | 2 +- .../builds/kebab-case/models/dog.ts | 2 +- .../builds/kebab-case/models/enum-arrays.ts | 2 +- .../builds/kebab-case/models/enum-test.ts | 2 +- .../fake-big-decimal-map200-response.ts | 2 +- .../models/file-schema-test-class.ts | 2 +- .../models/foo-get-default-response.ts | 2 +- .../builds/kebab-case/models/foo.ts | 2 +- .../kebab-case/models/has-only-read-only.ts | 2 +- .../kebab-case/models/health-check-result.ts | 2 +- .../builds/kebab-case/models/list.ts | 2 +- .../builds/kebab-case/models/map-test.ts | 2 +- .../kebab-case/models/model-api-response.ts | 2 +- .../builds/kebab-case/models/model-file.ts | 2 +- .../kebab-case/models/model200-response.ts | 2 +- .../builds/kebab-case/models/name.ts | 2 +- .../builds/kebab-case/models/number-only.ts | 2 +- .../models/object-with-deprecated-fields.ts | 2 +- .../kebab-case/models/outer-composite.ts | 2 +- .../models/outer-object-with-enum-property.ts | 2 +- .../kebab-case/models/parent-with-nullable.ts | 2 +- .../builds/kebab-case/models/pet.ts | 2 +- .../kebab-case/models/read-only-first.ts | 2 +- .../builds/kebab-case/models/return.ts | 2 +- .../kebab-case/models/special-model-name.ts | 2 +- .../builds/kebab-case/models/tag.ts | 2 +- ...-freeform-additional-properties-request.ts | 2 +- .../builds/kebab-case/models/user.ts | 2 +- .../builds/kebab-case/runtime.ts | 26 ++++++-- .../multiple-parameters/models/Category.ts | 2 +- .../models/ModelApiResponse.ts | 2 +- .../builds/multiple-parameters/models/Pet.ts | 2 +- .../builds/multiple-parameters/models/Tag.ts | 2 +- .../builds/multiple-parameters/models/User.ts | 2 +- .../builds/multiple-parameters/runtime.ts | 26 ++++++-- .../builds/oneOf/models/DashedOptionOne.ts | 2 +- .../builds/oneOf/models/DashedOptionTwo.ts | 2 +- .../oneOf/models/NumericSingletonEnumModel.ts | 2 +- .../builds/oneOf/models/OptionOne.ts | 2 +- .../builds/oneOf/models/OptionTwo.ts | 2 +- .../builds/oneOf/models/SnakeOptionOne.ts | 2 +- .../builds/oneOf/models/SnakeOptionTwo.ts | 2 +- .../builds/oneOf/models/TestA.ts | 2 +- .../builds/oneOf/models/TestB.ts | 2 +- .../typescript-fetch/builds/oneOf/runtime.ts | 26 ++++++-- .../src/models/Category.ts | 2 +- .../src/models/ModelApiResponse.ts | 2 +- .../src/models/Pet.ts | 2 +- .../src/models/Tag.ts | 2 +- .../src/models/User.ts | 2 +- .../src/runtime.ts | 26 ++++++-- .../sagas-and-records/src/models/Category.ts | 2 +- .../src/models/DefaultMetaOnlyResponse.ts | 2 +- .../src/models/FindPetsByStatusResponse.ts | 2 +- .../src/models/FindPetsByUserResponse.ts | 2 +- .../models/GetBehaviorPermissionsResponse.ts | 2 +- .../src/models/GetBehaviorTypeResponse.ts | 2 +- .../src/models/GetMatchingPartsResponse.ts | 2 +- .../src/models/GetPetPartTypeResponse.ts | 2 +- .../sagas-and-records/src/models/ItemId.ts | 2 +- .../src/models/MatchingParts.ts | 2 +- .../src/models/ModelApiResponse.ts | 2 +- .../src/models/ModelError.ts | 2 +- .../sagas-and-records/src/models/Part.ts | 2 +- .../sagas-and-records/src/models/Pet.ts | 2 +- .../src/models/PetRegionsResponse.ts | 2 +- .../src/models/ResponseMeta.ts | 2 +- .../sagas-and-records/src/models/Tag.ts | 2 +- .../sagas-and-records/src/models/User.ts | 2 +- .../builds/sagas-and-records/src/runtime.ts | 26 ++++++-- .../models/AdditionalPropertiesClass.ts | 2 +- .../models/AllOfWithSingleRef.ts | 2 +- .../snakecase-discriminator/models/Animal.ts | 2 +- .../models/ArrayOfArrayOfNumberOnly.ts | 2 +- .../models/ArrayOfNumberOnly.ts | 2 +- .../models/ArrayTest.ts | 2 +- .../models/Capitalization.ts | 2 +- .../snakecase-discriminator/models/Cat.ts | 2 +- .../models/Category.ts | 2 +- .../models/ClassModel.ts | 2 +- .../snakecase-discriminator/models/Client.ts | 2 +- .../models/DeprecatedObject.ts | 2 +- .../snakecase-discriminator/models/Dog.ts | 2 +- .../models/EnumArrays.ts | 2 +- .../models/EnumTest.ts | 2 +- .../models/FakeBigDecimalMap200Response.ts | 2 +- .../models/FileSchemaTestClass.ts | 2 +- .../snakecase-discriminator/models/Foo.ts | 2 +- .../models/FooGetDefaultResponse.ts | 2 +- .../models/HasOnlyReadOnly.ts | 2 +- .../models/HealthCheckResult.ts | 2 +- .../snakecase-discriminator/models/List.ts | 2 +- .../snakecase-discriminator/models/MapTest.ts | 2 +- .../models/Model200Response.ts | 2 +- .../models/ModelApiResponse.ts | 2 +- .../models/ModelFile.ts | 2 +- .../snakecase-discriminator/models/Name.ts | 2 +- .../models/NumberOnly.ts | 2 +- .../models/ObjectWithDeprecatedFields.ts | 2 +- .../models/OuterComposite.ts | 2 +- .../models/OuterObjectWithEnumProperty.ts | 2 +- .../snakecase-discriminator/models/Pet.ts | 2 +- .../models/ReadOnlyFirst.ts | 2 +- .../snakecase-discriminator/models/Return.ts | 2 +- .../models/SpecialModelName.ts | 2 +- .../snakecase-discriminator/models/Tag.ts | 2 +- .../snakecase-discriminator/models/User.ts | 2 +- .../builds/snakecase-discriminator/runtime.ts | 26 ++++++-- .../validation-attributes/models/Category.ts | 2 +- .../models/ModelApiResponse.ts | 2 +- .../validation-attributes/models/Pet.ts | 2 +- .../validation-attributes/models/Tag.ts | 2 +- .../validation-attributes/models/User.ts | 2 +- .../builds/validation-attributes/runtime.ts | 26 ++++++-- .../builds/with-interfaces/models/Category.ts | 2 +- .../models/ModelApiResponse.ts | 2 +- .../builds/with-interfaces/models/Pet.ts | 2 +- .../builds/with-interfaces/models/Tag.ts | 2 +- .../builds/with-interfaces/models/User.ts | 2 +- .../builds/with-interfaces/runtime.ts | 26 ++++++-- .../with-npm-version/src/models/Category.ts | 2 +- .../src/models/ModelApiResponse.ts | 2 +- .../builds/with-npm-version/src/models/Pet.ts | 2 +- .../builds/with-npm-version/src/models/Tag.ts | 2 +- .../with-npm-version/src/models/User.ts | 2 +- .../builds/with-npm-version/src/runtime.ts | 26 ++++++-- .../models/EnumPatternObject.ts | 2 +- .../FakeEnumRequestGetInline200Response.ts | 2 +- .../builds/with-string-enums/runtime.ts | 26 ++++++-- 228 files changed, 876 insertions(+), 319 deletions(-) create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-date/docs/Venue.md create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-date/models/Venue.ts create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-string/docs/Venue.md create mode 100644 samples/client/petstore/typescript-fetch/builds/date-library-string/models/Venue.ts diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java index d062caabd399..21ce334aabd6 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java @@ -105,6 +105,7 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege private static final String X_OPERATION_RETURN_PASSTHROUGH = "x-operationReturnPassthrough"; private static final String X_KEEP_AS_JS_OBJECT = "x-keepAsJSObject"; private static final String X_TYPESCRIPT_FETCH_API_EXAMPLE = "x-typescriptFetchApiExample"; + private static final String X_HAS_DATE_VARS = "x-hasDateVars"; private static final String BLOB_API_EXAMPLE = "new Blob(['example file content'], { type: 'application/octet-stream' })"; protected boolean sagasAndRecords = false; @@ -454,6 +455,12 @@ public ModelsMap postProcessModels(ModelsMap objs) { ExtendedCodegenModel cm = (ExtendedCodegenModel) mo.getModel(); cm.imports = new TreeSet<>(cm.imports); this.processCodeGenModel(cm); + // Mirrors the branches in modelGeneric.mustache that call the date helpers, so a + // model without dates does not import them. + cm.vendorExtensions.put(X_HAS_DATE_VARS, cm.vars.stream() + .filter(ExtendedCodegenProperty.class::isInstance) + .map(ExtendedCodegenProperty.class::cast) + .anyMatch(v -> v.isPrimitiveType && !v.isArray && (v.isDateType() || v.isDateTimeType()))); } // Add supporting file only if we plan to generate files in /models diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache index 179dd3abea2e..2e511274a4fa 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache @@ -1,4 +1,4 @@ -import { mapValues{{#isDateLibraryDate}}, parseDate, parseDateTime, serializeDate, serializeDateTime{{/isDateLibraryDate}} } from '../runtime{{importFileExtension}}'; +import { mapValues{{#isDateLibraryDate}}{{#vendorExtensions.x-hasDateVars}}, parseDate, parseDateTime, serializeDate, serializeDateTime{{/vendorExtensions.x-hasDateVars}}{{/isDateLibraryDate}} } from '../runtime{{importFileExtension}}'; {{#hasImports}} {{#tsImports}} import type { {{{classname}}} } from './{{filename}}{{importFileExtension}}'; diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache index c924ce3d0092..9dfa41c5774b 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache @@ -362,9 +362,13 @@ export function serializeDateTime(value: Date): string { {{#isDateLibraryDate}} export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -374,10 +378,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java index 12039840eef3..7ca392559a83 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java @@ -779,6 +779,10 @@ public void testDateLibraryDateIsTheDefault() throws IOException { Path runtime = Paths.get(output + "/runtime.ts"); TestUtils.assertFileContains(runtime, "export function parseDate("); TestUtils.assertFileContains(runtime, "export function parseDateTime("); + + // A model without a date must not import the helpers it cannot use. + Path venue = Paths.get(output + "/models/Venue.ts"); + TestUtils.assertFileContains(venue, "import { mapValues } from '../runtime';"); } @Test(description = "Verify dateLibrary=string leaves date values untouched as strings") @@ -829,20 +833,6 @@ public void testDateFormatIsSerializedAsACalendarDate() throws IOException { TestUtils.assertFileContains(api, "formParams.append('createdAt', runtime.serializeDateTime(requestParameters['createdAt'] as any))"); } - @Test(description = "Verify a calendar date is (de)serialized against the local calendar, so it cannot shift by a day") - public void testDateFormatUsesTheLocalCalendar() throws IOException { - File output = generate(new HashMap<>(), DATE_HANDLING_SPEC); - - Path runtime = Paths.get(output + "/runtime.ts"); - // A calendar date is converted against the local calendar on both ends. - TestUtils.assertFileContains(runtime, "value.getFullYear()"); - TestUtils.assertFileContains(runtime, "value.getMonth() + 1"); - TestUtils.assertFileContains(runtime, "value.getDate()"); - TestUtils.assertFileContains(runtime, "new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3]))"); - // A date-time is a genuine instant and stays UTC. - TestUtils.assertFileContains(runtime, "export function serializeDateTime(value: Date): string {\n return value.toISOString();"); - } - private static final String DATE_HANDLING_SPEC = "src/test/resources/3_0/typescript-fetch/date-handling.yaml"; private static File generate( diff --git a/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/date-handling.yaml b/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/date-handling.yaml index 13310dd54a98..3ede69f87f75 100644 --- a/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/date-handling.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/date-handling.yaml @@ -79,3 +79,9 @@ components: createdAt: type: string format: date-time + Venue: + description: Has no date of any kind, so it must not import the date helpers. + type: object + properties: + name: + type: string diff --git a/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/models/StructuredType.ts b/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/models/StructuredType.ts index c7f531833a02..94b6f81cb4f8 100644 --- a/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/models/StructuredType.ts +++ b/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/models/StructuredType.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/runtime.ts b/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/runtime.ts index e9933dda1ed6..52194da6fd93 100644 --- a/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/runtime.ts +++ b/samples/client/others/typescript-fetch/additional-properties-in-multipart-issue/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/others/typescript-fetch/infinite-recursion-issue/models/ExtendDto.ts b/samples/client/others/typescript-fetch/infinite-recursion-issue/models/ExtendDto.ts index 8c0bee13c964..bb02cb69bb26 100644 --- a/samples/client/others/typescript-fetch/infinite-recursion-issue/models/ExtendDto.ts +++ b/samples/client/others/typescript-fetch/infinite-recursion-issue/models/ExtendDto.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { TestBaseDto } from './TestBaseDto'; import { TestBaseDtoFromJSON, diff --git a/samples/client/others/typescript-fetch/infinite-recursion-issue/models/TestBaseDto.ts b/samples/client/others/typescript-fetch/infinite-recursion-issue/models/TestBaseDto.ts index 9fa917190e0a..e2db40b1d1fb 100644 --- a/samples/client/others/typescript-fetch/infinite-recursion-issue/models/TestBaseDto.ts +++ b/samples/client/others/typescript-fetch/infinite-recursion-issue/models/TestBaseDto.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { TestObjectType } from './TestObjectType'; import { TestObjectTypeFromJSON, diff --git a/samples/client/others/typescript-fetch/infinite-recursion-issue/runtime.ts b/samples/client/others/typescript-fetch/infinite-recursion-issue/runtime.ts index e9933dda1ed6..52194da6fd93 100644 --- a/samples/client/others/typescript-fetch/infinite-recursion-issue/runtime.ts +++ b/samples/client/others/typescript-fetch/infinite-recursion-issue/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/others/typescript-fetch/multipart-file-array/runtime.ts b/samples/client/others/typescript-fetch/multipart-file-array/runtime.ts index 1b967e470251..c7da03948db3 100644 --- a/samples/client/others/typescript-fetch/multipart-file-array/runtime.ts +++ b/samples/client/others/typescript-fetch/multipart-file-array/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/others/typescript-fetch/self-import-issue/models/AbstractUserDto.ts b/samples/client/others/typescript-fetch/self-import-issue/models/AbstractUserDto.ts index 927bc428edd3..23066259cb7f 100644 --- a/samples/client/others/typescript-fetch/self-import-issue/models/AbstractUserDto.ts +++ b/samples/client/others/typescript-fetch/self-import-issue/models/AbstractUserDto.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { BranchDto } from './BranchDto'; import { BranchDtoFromJSON, diff --git a/samples/client/others/typescript-fetch/self-import-issue/models/BranchDto.ts b/samples/client/others/typescript-fetch/self-import-issue/models/BranchDto.ts index ace44d0ae1e2..4d13f44c2bc1 100644 --- a/samples/client/others/typescript-fetch/self-import-issue/models/BranchDto.ts +++ b/samples/client/others/typescript-fetch/self-import-issue/models/BranchDto.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/others/typescript-fetch/self-import-issue/models/InternalAuthenticatedUserDto.ts b/samples/client/others/typescript-fetch/self-import-issue/models/InternalAuthenticatedUserDto.ts index 5a1ccee22848..7a8e69f01231 100644 --- a/samples/client/others/typescript-fetch/self-import-issue/models/InternalAuthenticatedUserDto.ts +++ b/samples/client/others/typescript-fetch/self-import-issue/models/InternalAuthenticatedUserDto.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { BranchDto } from './BranchDto'; import { BranchDtoFromJSON, diff --git a/samples/client/others/typescript-fetch/self-import-issue/models/RemoteAuthenticatedUserDto.ts b/samples/client/others/typescript-fetch/self-import-issue/models/RemoteAuthenticatedUserDto.ts index f990ee3d4f11..4fb8c1916e9d 100644 --- a/samples/client/others/typescript-fetch/self-import-issue/models/RemoteAuthenticatedUserDto.ts +++ b/samples/client/others/typescript-fetch/self-import-issue/models/RemoteAuthenticatedUserDto.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { BranchDto } from './BranchDto'; import { BranchDtoFromJSON, diff --git a/samples/client/others/typescript-fetch/self-import-issue/runtime.ts b/samples/client/others/typescript-fetch/self-import-issue/runtime.ts index cb20dffe2f40..54d1f049f19c 100644 --- a/samples/client/others/typescript-fetch/self-import-issue/runtime.ts +++ b/samples/client/others/typescript-fetch/self-import-issue/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Club.ts b/samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Club.ts index beecc3937597..579fd800b866 100644 --- a/samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Club.ts +++ b/samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Club.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Owner } from './Owner'; import { OwnerFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Owner.ts b/samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Owner.ts index 2408d376a530..941eecf56afd 100644 --- a/samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Owner.ts +++ b/samples/client/petstore/typescript-fetch/builds/allOf-nullable/models/Owner.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/allOf-nullable/runtime.ts b/samples/client/petstore/typescript-fetch/builds/allOf-nullable/runtime.ts index 33828f4d6982..3ceb3d69ab0e 100644 --- a/samples/client/petstore/typescript-fetch/builds/allOf-nullable/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/allOf-nullable/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Club.ts b/samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Club.ts index e83ab530b58b..c1b72486407c 100644 --- a/samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Club.ts +++ b/samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Club.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Owner } from './Owner'; import { OwnerFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Owner.ts b/samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Owner.ts index 2408d376a530..941eecf56afd 100644 --- a/samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Owner.ts +++ b/samples/client/petstore/typescript-fetch/builds/allOf-readonly/models/Owner.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/allOf-readonly/runtime.ts b/samples/client/petstore/typescript-fetch/builds/allOf-readonly/runtime.ts index 33828f4d6982..3ceb3d69ab0e 100644 --- a/samples/client/petstore/typescript-fetch/builds/allOf-readonly/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/allOf-readonly/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/.openapi-generator/FILES b/samples/client/petstore/typescript-fetch/builds/date-library-date/.openapi-generator/FILES index 354f25e5cfda..865383789a36 100644 --- a/samples/client/petstore/typescript-fetch/builds/date-library-date/.openapi-generator/FILES +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/.openapi-generator/FILES @@ -2,7 +2,9 @@ apis/DefaultApi.ts apis/index.ts docs/DefaultApi.md docs/Event.md +docs/Venue.md index.ts models/Event.ts +models/Venue.ts models/index.ts runtime.ts diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/docs/Venue.md b/samples/client/petstore/typescript-fetch/builds/date-library-date/docs/Venue.md new file mode 100644 index 000000000000..9fd3be456ae0 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/docs/Venue.md @@ -0,0 +1,35 @@ + +# Venue + +Has no date of any kind, so it must not import the date helpers. + +## Properties + +Name | Type +------------ | ------------- +`name` | string + +## Example + +```typescript +import type { Venue } from '' + +// TODO: Update the object below with actual values +const example = { + "name": null, +} satisfies Venue + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as Venue +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/models/Venue.ts b/samples/client/petstore/typescript-fetch/builds/date-library-date/models/Venue.ts new file mode 100644 index 000000000000..1a97a56452f1 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/models/Venue.ts @@ -0,0 +1,63 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Date handling + * Covers every location a `format: date` or `format: date-time` value can appear in, so the generated (de)serialization can be checked in one place. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { mapValues } from '../runtime'; +/** + * Has no date of any kind, so it must not import the date helpers. + * @export + * @interface Venue + */ +export interface Venue { + /** + * + */ + name?: string; +} + +/** + * Check if a given object implements the Venue interface. + */ +export function instanceOfVenue(value: object): value is Venue { + return true; +} + +export function VenueFromJSON(json: any): Venue { + return VenueFromJSONTyped(json, false); +} + +export function VenueFromJSONTyped(json: any, ignoreDiscriminator: boolean): Venue { + if (json == null) { + return json; + } + return { + + 'name': json['name'] == null ? undefined : json['name'], + }; +} + +export function VenueToJSON(json: any): Venue { + return VenueToJSONTyped(json, false); +} + +export function VenueToJSONTyped(value?: Venue | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'name': value['name'], + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/models/index.ts b/samples/client/petstore/typescript-fetch/builds/date-library-date/models/index.ts index 309b5bb56aa3..e8e143b24a97 100644 --- a/samples/client/petstore/typescript-fetch/builds/date-library-date/models/index.ts +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/models/index.ts @@ -1,3 +1,4 @@ /* tslint:disable */ /* eslint-disable */ export * from './Event'; +export * from './Venue'; diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-date/runtime.ts b/samples/client/petstore/typescript-fetch/builds/date-library-date/runtime.ts index e4c71201833c..96f93d3e3f13 100644 --- a/samples/client/petstore/typescript-fetch/builds/date-library-date/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/date-library-date/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-string/.openapi-generator/FILES b/samples/client/petstore/typescript-fetch/builds/date-library-string/.openapi-generator/FILES index 354f25e5cfda..865383789a36 100644 --- a/samples/client/petstore/typescript-fetch/builds/date-library-string/.openapi-generator/FILES +++ b/samples/client/petstore/typescript-fetch/builds/date-library-string/.openapi-generator/FILES @@ -2,7 +2,9 @@ apis/DefaultApi.ts apis/index.ts docs/DefaultApi.md docs/Event.md +docs/Venue.md index.ts models/Event.ts +models/Venue.ts models/index.ts runtime.ts diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-string/docs/Venue.md b/samples/client/petstore/typescript-fetch/builds/date-library-string/docs/Venue.md new file mode 100644 index 000000000000..9fd3be456ae0 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-string/docs/Venue.md @@ -0,0 +1,35 @@ + +# Venue + +Has no date of any kind, so it must not import the date helpers. + +## Properties + +Name | Type +------------ | ------------- +`name` | string + +## Example + +```typescript +import type { Venue } from '' + +// TODO: Update the object below with actual values +const example = { + "name": null, +} satisfies Venue + +console.log(example) + +// Convert the instance to a JSON string +const exampleJSON: string = JSON.stringify(example) +console.log(exampleJSON) + +// Parse the JSON string back to an object +const exampleParsed = JSON.parse(exampleJSON) as Venue +console.log(exampleParsed) +``` + +[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-string/models/Venue.ts b/samples/client/petstore/typescript-fetch/builds/date-library-string/models/Venue.ts new file mode 100644 index 000000000000..1a97a56452f1 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/date-library-string/models/Venue.ts @@ -0,0 +1,63 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Date handling + * Covers every location a `format: date` or `format: date-time` value can appear in, so the generated (de)serialization can be checked in one place. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { mapValues } from '../runtime'; +/** + * Has no date of any kind, so it must not import the date helpers. + * @export + * @interface Venue + */ +export interface Venue { + /** + * + */ + name?: string; +} + +/** + * Check if a given object implements the Venue interface. + */ +export function instanceOfVenue(value: object): value is Venue { + return true; +} + +export function VenueFromJSON(json: any): Venue { + return VenueFromJSONTyped(json, false); +} + +export function VenueFromJSONTyped(json: any, ignoreDiscriminator: boolean): Venue { + if (json == null) { + return json; + } + return { + + 'name': json['name'] == null ? undefined : json['name'], + }; +} + +export function VenueToJSON(json: any): Venue { + return VenueToJSONTyped(json, false); +} + +export function VenueToJSONTyped(value?: Venue | null, ignoreDiscriminator: boolean = false): any { + if (value == null) { + return value; + } + + return { + + 'name': value['name'], + }; +} + diff --git a/samples/client/petstore/typescript-fetch/builds/date-library-string/models/index.ts b/samples/client/petstore/typescript-fetch/builds/date-library-string/models/index.ts index 309b5bb56aa3..e8e143b24a97 100644 --- a/samples/client/petstore/typescript-fetch/builds/date-library-string/models/index.ts +++ b/samples/client/petstore/typescript-fetch/builds/date-library-string/models/index.ts @@ -1,3 +1,4 @@ /* tslint:disable */ /* eslint-disable */ export * from './Event'; +export * from './Venue'; diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AdditionalPropertiesClass.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AdditionalPropertiesClass.ts index f2dc71ebdaf6..1db920000504 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AdditionalPropertiesClass.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AdditionalPropertiesClass.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AllOfWithSingleRef.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AllOfWithSingleRef.ts index 48d511219088..743b9141a1af 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AllOfWithSingleRef.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/AllOfWithSingleRef.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { SingleRefType } from './SingleRefType'; import { SingleRefTypeFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Animal.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Animal.ts index 86520b9e608e..2a8b126041f7 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Animal.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Animal.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import { type Cat, CatFromJSONTyped, CatToJSON, CatToJSONTyped } from './Cat'; import { type Dog, DogFromJSONTyped, DogToJSON, DogToJSONTyped } from './Dog'; /** diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfArrayOfNumberOnly.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfArrayOfNumberOnly.ts index eb46a92a17f4..bce79e8d3b63 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfArrayOfNumberOnly.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfArrayOfNumberOnly.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfNumberOnly.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfNumberOnly.ts index 58a124c4d597..8640a0d74aa5 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfNumberOnly.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayOfNumberOnly.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayTest.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayTest.ts index 209bc6d83544..002052b417d3 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayTest.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ArrayTest.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { ReadOnlyFirst } from './ReadOnlyFirst'; import { ReadOnlyFirstFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Capitalization.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Capitalization.ts index e1ae19d0722d..de75ac5926d6 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Capitalization.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Capitalization.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Cat.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Cat.ts index 6744be5087c2..33efae9ddcf9 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Cat.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Cat.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Animal } from './Animal'; import { AnimalFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Category.ts index f5c1719da512..04cd593f2dce 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ChildWithNullable.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ChildWithNullable.ts index 2c415f0b05b9..aa6dc996a500 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ChildWithNullable.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ChildWithNullable.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { ParentWithNullable } from './ParentWithNullable'; import { ParentWithNullableFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ClassModel.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ClassModel.ts index 39f27a81ee3a..cef4c58640ce 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ClassModel.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ClassModel.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Model for testing model with "_class" property * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Client.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Client.ts index 39f16473b2db..7f353720b90d 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Client.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Client.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/DeprecatedObject.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/DeprecatedObject.ts index 5264e69b1e0b..14623160e258 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/DeprecatedObject.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/DeprecatedObject.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Dog.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Dog.ts index cec03d19fee0..967f5cf772f2 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Dog.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Dog.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Animal } from './Animal'; import { AnimalFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumArrays.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumArrays.ts index 88d2b45098c5..84cd87dd1408 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumArrays.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumArrays.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumTest.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumTest.ts index 58374a3bc6cf..4c27767e593c 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumTest.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/EnumTest.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { OuterEnum } from './OuterEnum'; import { OuterEnumFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FakeBigDecimalMap200Response.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FakeBigDecimalMap200Response.ts index 097fae0be926..ed87ea529d3d 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FakeBigDecimalMap200Response.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FakeBigDecimalMap200Response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FileSchemaTestClass.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FileSchemaTestClass.ts index 9f5f785effe6..4dcd0b2ed2c4 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FileSchemaTestClass.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FileSchemaTestClass.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Foo.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Foo.ts index 265c8bb9a8d7..843b44d30811 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Foo.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Foo.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FooGetDefaultResponse.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FooGetDefaultResponse.ts index cdf9c480ebc7..d12c4924c2f3 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FooGetDefaultResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/FooGetDefaultResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Foo } from './Foo'; import { FooFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/HasOnlyReadOnly.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/HasOnlyReadOnly.ts index 93656b13dc8f..b81e989b86d4 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/HasOnlyReadOnly.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/HasOnlyReadOnly.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/HealthCheckResult.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/HealthCheckResult.ts index 01c77603870f..520e91e780bd 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/HealthCheckResult.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/HealthCheckResult.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model. * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/List.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/List.ts index 4f585b061668..a51be9f76c2c 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/List.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/List.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MapTest.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MapTest.ts index f7a65d7e8822..18ea456c8951 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MapTest.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/MapTest.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Model200Response.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Model200Response.ts index 98089b550456..62f11d4d4e5a 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Model200Response.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Model200Response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Model for testing model name starting with number * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ModelApiResponse.ts index 4650d81f3a85..8e8b92dc4228 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ModelFile.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ModelFile.ts index 2eaf8fd20162..e823e6cd03cc 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ModelFile.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ModelFile.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Must be named `File` for test. * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Name.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Name.ts index cedfa4b67db8..4b7ed42911fb 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Name.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Name.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Model for testing model name same as property name * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/NumberOnly.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/NumberOnly.ts index bab9610104f4..b899ac447f22 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/NumberOnly.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/NumberOnly.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ObjectWithDeprecatedFields.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ObjectWithDeprecatedFields.ts index d17040b0b56e..73a8eb403427 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ObjectWithDeprecatedFields.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ObjectWithDeprecatedFields.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { DeprecatedObject } from './DeprecatedObject'; import { DeprecatedObjectFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterComposite.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterComposite.ts index bde6e9963ef6..f3375c3124f7 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterComposite.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterComposite.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterObjectWithEnumProperty.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterObjectWithEnumProperty.ts index 5ea61247a3ed..420c964cd78b 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterObjectWithEnumProperty.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/OuterObjectWithEnumProperty.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { OuterEnumInteger } from './OuterEnumInteger'; import { OuterEnumIntegerFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ParentWithNullable.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ParentWithNullable.ts index b59604b5d13b..0eedf046f63c 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ParentWithNullable.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ParentWithNullable.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import { type ChildWithNullable, ChildWithNullableFromJSONTyped, ChildWithNullableToJSON, ChildWithNullableToJSONTyped } from './ChildWithNullable'; /** * diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts index d90d4d1cf971..20d21e2f1aad 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ReadOnlyFirst.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ReadOnlyFirst.ts index 99d7deac013e..3a80d04b6d6d 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ReadOnlyFirst.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ReadOnlyFirst.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Return.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Return.ts index 652fabd69106..c0b3275a6ed8 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Return.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Return.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Model for testing reserved words * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/SpecialModelName.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/SpecialModelName.ts index 763e45b6ee39..d13618509744 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/SpecialModelName.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/SpecialModelName.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Tag.ts index 55fc45e2c9a5..a0caf8140a38 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/TestInlineFreeformAdditionalPropertiesRequest.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/TestInlineFreeformAdditionalPropertiesRequest.ts index 5e453f9ea286..b11489089d02 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/TestInlineFreeformAdditionalPropertiesRequest.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/TestInlineFreeformAdditionalPropertiesRequest.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/User.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/User.ts index d09fd6f21295..207ad34596fc 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts index 9a57ab110acb..5b823ec12c0d 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/default/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/default/models/Category.ts index d4ff2b5e4d9a..cdffe07db910 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A category for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/default/models/ModelApiResponse.ts index 71da44967c79..f89423073868 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Describes the result of uploading an image resource * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/default/models/Pet.ts index 8230f3435432..4c0cb6e73685 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/default/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/default/models/Tag.ts index 83b9ad7dcb3f..80126e24919e 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A tag for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default/models/User.ts b/samples/client/petstore/typescript-fetch/builds/default/models/User.ts index 59dfa0baec26..68e240e4afb3 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A User who is purchasing from the pet store * @export diff --git a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts index 7d4323ad5e99..4ea4c5de5589 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/enum/models/EnumPatternObject.ts b/samples/client/petstore/typescript-fetch/builds/enum/models/EnumPatternObject.ts index c686f79ca418..0ad7eb19c7df 100644 --- a/samples/client/petstore/typescript-fetch/builds/enum/models/EnumPatternObject.ts +++ b/samples/client/petstore/typescript-fetch/builds/enum/models/EnumPatternObject.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { NumberEnum } from './NumberEnum'; import { NumberEnumFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/enum/models/FakeEnumRequestGetInline200Response.ts b/samples/client/petstore/typescript-fetch/builds/enum/models/FakeEnumRequestGetInline200Response.ts index edc214ae5c51..50912880cb8f 100644 --- a/samples/client/petstore/typescript-fetch/builds/enum/models/FakeEnumRequestGetInline200Response.ts +++ b/samples/client/petstore/typescript-fetch/builds/enum/models/FakeEnumRequestGetInline200Response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts b/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts index 5a2edca34dd6..d09ba0070951 100644 --- a/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Category.ts index d4ff2b5e4d9a..cdffe07db910 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A category for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/ModelApiResponse.ts index 71da44967c79..f89423073868 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Describes the result of uploading an image resource * @export diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Pet.ts index 8230f3435432..4c0cb6e73685 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Tag.ts index 83b9ad7dcb3f..80126e24919e 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A tag for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/User.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/User.ts index 59dfa0baec26..68e240e4afb3 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A User who is purchasing from the pet store * @export diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts index 7d4323ad5e99..4ea4c5de5589 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/additional-properties-class.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/additional-properties-class.ts index f2dc71ebdaf6..1db920000504 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/additional-properties-class.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/additional-properties-class.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/all-of-with-single-ref.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/all-of-with-single-ref.ts index d46434597e44..aa782062bc3d 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/all-of-with-single-ref.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/all-of-with-single-ref.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { SingleRefType } from './single-ref-type'; import { SingleRefTypeFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/animal.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/animal.ts index 86520b9e608e..2a8b126041f7 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/animal.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/animal.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import { type Cat, CatFromJSONTyped, CatToJSON, CatToJSONTyped } from './Cat'; import { type Dog, DogFromJSONTyped, DogToJSON, DogToJSONTyped } from './Dog'; /** diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-of-array-of-number-only.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-of-array-of-number-only.ts index eb46a92a17f4..bce79e8d3b63 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-of-array-of-number-only.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-of-array-of-number-only.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-of-number-only.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-of-number-only.ts index 58a124c4d597..8640a0d74aa5 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-of-number-only.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-of-number-only.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-test.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-test.ts index 1aec9d9d532b..a41776f9d876 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-test.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/array-test.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { ReadOnlyFirst } from './read-only-first'; import { ReadOnlyFirstFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/capitalization.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/capitalization.ts index e1ae19d0722d..de75ac5926d6 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/capitalization.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/capitalization.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/cat.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/cat.ts index 1543026b61cf..05327a0a2074 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/cat.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/cat.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Animal } from './animal'; import { AnimalFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/category.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/category.ts index f5c1719da512..04cd593f2dce 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/category.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/child-with-nullable.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/child-with-nullable.ts index a0f2256d9c1b..0581ad6f5e92 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/child-with-nullable.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/child-with-nullable.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { ParentWithNullable } from './parent-with-nullable'; import { ParentWithNullableFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/class-model.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/class-model.ts index 39f27a81ee3a..cef4c58640ce 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/class-model.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/class-model.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Model for testing model with "_class" property * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/client.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/client.ts index 39f16473b2db..7f353720b90d 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/client.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/client.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/deprecated-object.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/deprecated-object.ts index 5264e69b1e0b..14623160e258 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/deprecated-object.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/deprecated-object.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/dog.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/dog.ts index 6b8e43b30a8f..8eae2e8bd755 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/dog.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/dog.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Animal } from './animal'; import { AnimalFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-arrays.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-arrays.ts index 88d2b45098c5..84cd87dd1408 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-arrays.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-arrays.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-test.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-test.ts index e211560bed95..ebfff184b281 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-test.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-test.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { OuterEnum } from './outer-enum'; import { OuterEnumFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/fake-big-decimal-map200-response.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/fake-big-decimal-map200-response.ts index 097fae0be926..ed87ea529d3d 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/fake-big-decimal-map200-response.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/fake-big-decimal-map200-response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/file-schema-test-class.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/file-schema-test-class.ts index 9f5f785effe6..4dcd0b2ed2c4 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/file-schema-test-class.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/file-schema-test-class.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/foo-get-default-response.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/foo-get-default-response.ts index 1891c0a8e371..010ffd4b422f 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/foo-get-default-response.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/foo-get-default-response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Foo } from './foo'; import { FooFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/foo.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/foo.ts index 265c8bb9a8d7..843b44d30811 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/foo.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/foo.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/has-only-read-only.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/has-only-read-only.ts index 93656b13dc8f..b81e989b86d4 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/has-only-read-only.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/has-only-read-only.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/health-check-result.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/health-check-result.ts index 01c77603870f..520e91e780bd 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/health-check-result.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/health-check-result.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model. * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/list.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/list.ts index 4f585b061668..a51be9f76c2c 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/list.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/list.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/map-test.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/map-test.ts index f7a65d7e8822..18ea456c8951 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/map-test.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/map-test.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model-api-response.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model-api-response.ts index 4650d81f3a85..8e8b92dc4228 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model-api-response.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model-api-response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model-file.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model-file.ts index 2eaf8fd20162..e823e6cd03cc 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model-file.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model-file.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Must be named `File` for test. * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model200-response.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model200-response.ts index 98089b550456..62f11d4d4e5a 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model200-response.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/model200-response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Model for testing model name starting with number * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/name.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/name.ts index cedfa4b67db8..4b7ed42911fb 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/name.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/name.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Model for testing model name same as property name * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/number-only.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/number-only.ts index bab9610104f4..b899ac447f22 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/number-only.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/number-only.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/object-with-deprecated-fields.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/object-with-deprecated-fields.ts index 6b0b8f88c2f5..1491b14913df 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/object-with-deprecated-fields.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/object-with-deprecated-fields.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { DeprecatedObject } from './deprecated-object'; import { DeprecatedObjectFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/outer-composite.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/outer-composite.ts index bde6e9963ef6..f3375c3124f7 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/outer-composite.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/outer-composite.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/outer-object-with-enum-property.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/outer-object-with-enum-property.ts index bc604a7827b3..1ebc71806729 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/outer-object-with-enum-property.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/outer-object-with-enum-property.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { OuterEnumInteger } from './outer-enum-integer'; import { OuterEnumIntegerFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/parent-with-nullable.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/parent-with-nullable.ts index b59604b5d13b..0eedf046f63c 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/parent-with-nullable.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/parent-with-nullable.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import { type ChildWithNullable, ChildWithNullableFromJSONTyped, ChildWithNullableToJSON, ChildWithNullableToJSONTyped } from './ChildWithNullable'; /** * diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/pet.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/pet.ts index f29f7917399c..add649416353 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Category } from './category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/read-only-first.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/read-only-first.ts index 99d7deac013e..3a80d04b6d6d 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/read-only-first.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/read-only-first.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/return.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/return.ts index 652fabd69106..c0b3275a6ed8 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/return.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/return.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Model for testing reserved words * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/special-model-name.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/special-model-name.ts index 763e45b6ee39..d13618509744 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/special-model-name.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/special-model-name.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/tag.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/tag.ts index 55fc45e2c9a5..a0caf8140a38 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/test-inline-freeform-additional-properties-request.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/test-inline-freeform-additional-properties-request.ts index 5e453f9ea286..b11489089d02 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/test-inline-freeform-additional-properties-request.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/test-inline-freeform-additional-properties-request.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/user.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/user.ts index d09fd6f21295..207ad34596fc 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/user.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/user.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/runtime.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/runtime.ts index 9a57ab110acb..5b823ec12c0d 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Category.ts index d4ff2b5e4d9a..cdffe07db910 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A category for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/ModelApiResponse.ts index 71da44967c79..f89423073868 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Describes the result of uploading an image resource * @export diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Pet.ts index 8230f3435432..4c0cb6e73685 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Tag.ts index 83b9ad7dcb3f..80126e24919e 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A tag for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/User.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/User.ts index 59dfa0baec26..68e240e4afb3 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A User who is purchasing from the pet store * @export diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts index 7d4323ad5e99..4ea4c5de5589 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/DashedOptionOne.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/DashedOptionOne.ts index 159a8eeaddcd..42b09a797522 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/DashedOptionOne.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/DashedOptionOne.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/DashedOptionTwo.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/DashedOptionTwo.ts index d3f6103f6de7..a7f16917f6de 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/DashedOptionTwo.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/DashedOptionTwo.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/NumericSingletonEnumModel.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/NumericSingletonEnumModel.ts index bd4facf17ec7..45551ae6a917 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/NumericSingletonEnumModel.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/NumericSingletonEnumModel.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/OptionOne.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/OptionOne.ts index 5327fef74811..ccfc53dfe05e 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/OptionOne.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/OptionOne.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/OptionTwo.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/OptionTwo.ts index 492a0f9b33a7..ff75902cb6fd 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/OptionTwo.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/OptionTwo.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/SnakeOptionOne.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/SnakeOptionOne.ts index a6c376e6fe94..d738d4d73a15 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/SnakeOptionOne.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/SnakeOptionOne.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/SnakeOptionTwo.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/SnakeOptionTwo.ts index c1b5976c26be..c8b1f9451572 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/SnakeOptionTwo.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/SnakeOptionTwo.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestA.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestA.ts index d4f52060df5b..fe0962f260bb 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestA.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestA.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestB.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestB.ts index 2bcd659b825d..ec828078dec6 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestB.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestB.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/runtime.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/runtime.ts index 96f7409806d3..c52d6273d984 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Category.ts index d4ff2b5e4d9a..cdffe07db910 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A category for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/ModelApiResponse.ts index 71da44967c79..f89423073868 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Describes the result of uploading an image resource * @export diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Pet.ts index 8230f3435432..4c0cb6e73685 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Tag.ts index 83b9ad7dcb3f..80126e24919e 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A tag for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/User.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/User.ts index 59dfa0baec26..68e240e4afb3 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A User who is purchasing from the pet store * @export diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts index 7d4323ad5e99..4ea4c5de5589 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Category.ts index d4ff2b5e4d9a..cdffe07db910 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A category for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/DefaultMetaOnlyResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/DefaultMetaOnlyResponse.ts index eb2f43d628c6..032fabdfc4b0 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/DefaultMetaOnlyResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/DefaultMetaOnlyResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { ResponseMeta } from './ResponseMeta'; import { ResponseMetaFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/FindPetsByStatusResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/FindPetsByStatusResponse.ts index fee211391474..3dd03e912526 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/FindPetsByStatusResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/FindPetsByStatusResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { ResponseMeta } from './ResponseMeta'; import { ResponseMetaFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/FindPetsByUserResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/FindPetsByUserResponse.ts index daf85cacbcc9..575ab1f0413e 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/FindPetsByUserResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/FindPetsByUserResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { User } from './User'; import { UserFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetBehaviorPermissionsResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetBehaviorPermissionsResponse.ts index 6ed81a22fac9..3fbab7b0499f 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetBehaviorPermissionsResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetBehaviorPermissionsResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { ResponseMeta } from './ResponseMeta'; import { ResponseMetaFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetBehaviorTypeResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetBehaviorTypeResponse.ts index c21ba3be783d..a7ac60073220 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetBehaviorTypeResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetBehaviorTypeResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { BehaviorType } from './BehaviorType'; import { BehaviorTypeFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetMatchingPartsResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetMatchingPartsResponse.ts index fae2fa423428..1545eb7cb80a 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetMatchingPartsResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetMatchingPartsResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { ResponseMeta } from './ResponseMeta'; import { ResponseMetaFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetPetPartTypeResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetPetPartTypeResponse.ts index 3cd20a38a830..d70ad8ee64d9 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetPetPartTypeResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/GetPetPartTypeResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { ResponseMeta } from './ResponseMeta'; import { ResponseMetaFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ItemId.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ItemId.ts index 865c9e48c685..18103ba2ee18 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ItemId.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ItemId.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Simplified identifier of an item * @export diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/MatchingParts.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/MatchingParts.ts index 892e52ea29d0..d323c477e85d 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/MatchingParts.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/MatchingParts.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Part } from './Part'; import { PartFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ModelApiResponse.ts index 71da44967c79..f89423073868 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Describes the result of uploading an image resource * @export diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ModelError.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ModelError.ts index ec5fbfb8d8fa..6dae6855c8a5 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ModelError.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ModelError.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { ItemId } from './ItemId'; import { ItemIdFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Part.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Part.ts index ef1223205b87..043bbec9d1cc 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Part.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Part.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Contains all the info about a pet part * @export diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Pet.ts index 56994baf4bb1..3d20dc56c6c8 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/PetRegionsResponse.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/PetRegionsResponse.ts index 1a17bc156581..c769237d5e3a 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/PetRegionsResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/PetRegionsResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { ResponseMeta } from './ResponseMeta'; import { ResponseMetaFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ResponseMeta.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ResponseMeta.ts index a56ded1b063f..df38da1be6e4 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ResponseMeta.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/ResponseMeta.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { ErrorCode } from './ErrorCode'; import { ErrorCodeFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Tag.ts index 83b9ad7dcb3f..80126e24919e 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A tag for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/User.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/User.ts index 83108d636c33..ce78194e47f1 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A User who is purchasing from the pet store * @export diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts index 7d4323ad5e99..4ea4c5de5589 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/AdditionalPropertiesClass.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/AdditionalPropertiesClass.ts index f2dc71ebdaf6..1db920000504 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/AdditionalPropertiesClass.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/AdditionalPropertiesClass.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/AllOfWithSingleRef.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/AllOfWithSingleRef.ts index 48d511219088..743b9141a1af 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/AllOfWithSingleRef.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/AllOfWithSingleRef.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { SingleRefType } from './SingleRefType'; import { SingleRefTypeFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Animal.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Animal.ts index 577770de18a9..3b1b2fcdc204 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Animal.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Animal.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import { type Cat, CatFromJSONTyped, CatToJSON, CatToJSONTyped } from './Cat'; import { type Dog, DogFromJSONTyped, DogToJSON, DogToJSONTyped } from './Dog'; /** diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayOfArrayOfNumberOnly.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayOfArrayOfNumberOnly.ts index eb46a92a17f4..bce79e8d3b63 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayOfArrayOfNumberOnly.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayOfArrayOfNumberOnly.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayOfNumberOnly.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayOfNumberOnly.ts index 58a124c4d597..8640a0d74aa5 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayOfNumberOnly.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayOfNumberOnly.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayTest.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayTest.ts index 209bc6d83544..002052b417d3 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayTest.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ArrayTest.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { ReadOnlyFirst } from './ReadOnlyFirst'; import { ReadOnlyFirstFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Capitalization.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Capitalization.ts index e1ae19d0722d..de75ac5926d6 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Capitalization.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Capitalization.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Cat.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Cat.ts index 6744be5087c2..33efae9ddcf9 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Cat.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Cat.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Animal } from './Animal'; import { AnimalFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Category.ts index f5c1719da512..04cd593f2dce 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ClassModel.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ClassModel.ts index 39f27a81ee3a..cef4c58640ce 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ClassModel.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ClassModel.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Model for testing model with "_class" property * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Client.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Client.ts index 39f16473b2db..7f353720b90d 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Client.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Client.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/DeprecatedObject.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/DeprecatedObject.ts index 5264e69b1e0b..14623160e258 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/DeprecatedObject.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/DeprecatedObject.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Dog.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Dog.ts index cec03d19fee0..967f5cf772f2 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Dog.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Dog.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Animal } from './Animal'; import { AnimalFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumArrays.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumArrays.ts index 88d2b45098c5..84cd87dd1408 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumArrays.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumArrays.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumTest.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumTest.ts index 58374a3bc6cf..4c27767e593c 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumTest.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/EnumTest.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { OuterEnum } from './OuterEnum'; import { OuterEnumFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FakeBigDecimalMap200Response.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FakeBigDecimalMap200Response.ts index 097fae0be926..ed87ea529d3d 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FakeBigDecimalMap200Response.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FakeBigDecimalMap200Response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FileSchemaTestClass.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FileSchemaTestClass.ts index 9f5f785effe6..4dcd0b2ed2c4 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FileSchemaTestClass.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FileSchemaTestClass.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Foo.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Foo.ts index 265c8bb9a8d7..843b44d30811 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Foo.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Foo.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FooGetDefaultResponse.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FooGetDefaultResponse.ts index cdf9c480ebc7..d12c4924c2f3 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FooGetDefaultResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/FooGetDefaultResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Foo } from './Foo'; import { FooFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/HasOnlyReadOnly.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/HasOnlyReadOnly.ts index 93656b13dc8f..b81e989b86d4 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/HasOnlyReadOnly.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/HasOnlyReadOnly.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/HealthCheckResult.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/HealthCheckResult.ts index 01c77603870f..520e91e780bd 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/HealthCheckResult.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/HealthCheckResult.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model. * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/List.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/List.ts index 4f585b061668..a51be9f76c2c 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/List.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/List.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/MapTest.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/MapTest.ts index f7a65d7e8822..18ea456c8951 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/MapTest.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/MapTest.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Model200Response.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Model200Response.ts index 98089b550456..62f11d4d4e5a 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Model200Response.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Model200Response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Model for testing model name starting with number * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ModelApiResponse.ts index 4650d81f3a85..8e8b92dc4228 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ModelFile.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ModelFile.ts index 2eaf8fd20162..e823e6cd03cc 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ModelFile.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ModelFile.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Must be named `File` for test. * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Name.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Name.ts index cedfa4b67db8..4b7ed42911fb 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Name.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Name.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Model for testing model name same as property name * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/NumberOnly.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/NumberOnly.ts index bab9610104f4..b899ac447f22 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/NumberOnly.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/NumberOnly.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ObjectWithDeprecatedFields.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ObjectWithDeprecatedFields.ts index d17040b0b56e..73a8eb403427 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ObjectWithDeprecatedFields.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ObjectWithDeprecatedFields.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { DeprecatedObject } from './DeprecatedObject'; import { DeprecatedObjectFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterComposite.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterComposite.ts index bde6e9963ef6..f3375c3124f7 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterComposite.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterComposite.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterObjectWithEnumProperty.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterObjectWithEnumProperty.ts index 5ea61247a3ed..420c964cd78b 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterObjectWithEnumProperty.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/OuterObjectWithEnumProperty.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { OuterEnumInteger } from './OuterEnumInteger'; import { OuterEnumIntegerFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Pet.ts index d90d4d1cf971..20d21e2f1aad 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ReadOnlyFirst.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ReadOnlyFirst.ts index 99d7deac013e..3a80d04b6d6d 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ReadOnlyFirst.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/ReadOnlyFirst.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Return.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Return.ts index 652fabd69106..c0b3275a6ed8 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Return.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Return.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Model for testing reserved words * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/SpecialModelName.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/SpecialModelName.ts index 763e45b6ee39..d13618509744 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/SpecialModelName.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/SpecialModelName.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Tag.ts index 55fc45e2c9a5..a0caf8140a38 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/User.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/User.ts index d09fd6f21295..207ad34596fc 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/runtime.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/runtime.ts index 9a57ab110acb..5b823ec12c0d 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Category.ts index 31d9e8d6dfdf..7a5fb6a636ea 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A category for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/ModelApiResponse.ts index 4809607b702c..94dbefb8376a 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Describes the result of uploading an image resource * @export diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Pet.ts index 383e5475fbcd..cde0e7b42de0 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Tag.ts index 452ea74fb49c..b6222ddd699c 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A tag for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/User.ts b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/User.ts index 1263e9173f30..af745c1ee60e 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A User who is purchasing from the pet store * @export diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/runtime.ts b/samples/client/petstore/typescript-fetch/builds/validation-attributes/runtime.ts index 7d4323ad5e99..4ea4c5de5589 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Category.ts index d4ff2b5e4d9a..cdffe07db910 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A category for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/ModelApiResponse.ts index 71da44967c79..f89423073868 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Describes the result of uploading an image resource * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Pet.ts index 8230f3435432..4c0cb6e73685 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Tag.ts index 83b9ad7dcb3f..80126e24919e 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A tag for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/User.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/User.ts index 59dfa0baec26..68e240e4afb3 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A User who is purchasing from the pet store * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts index 7d4323ad5e99..4ea4c5de5589 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Category.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Category.ts index d4ff2b5e4d9a..cdffe07db910 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Category.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Category.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A category for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/ModelApiResponse.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/ModelApiResponse.ts index 71da44967c79..f89423073868 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/ModelApiResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/ModelApiResponse.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * Describes the result of uploading an image resource * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Pet.ts index 8230f3435432..4c0cb6e73685 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Pet.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { Category } from './Category'; import { CategoryFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Tag.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Tag.ts index 83b9ad7dcb3f..80126e24919e 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Tag.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/Tag.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A tag for a pet * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/User.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/User.ts index 59dfa0baec26..68e240e4afb3 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/User.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/models/User.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * A User who is purchasing from the pet store * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts index 7d4323ad5e99..4ea4c5de5589 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); } diff --git a/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/EnumPatternObject.ts b/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/EnumPatternObject.ts index c686f79ca418..0ad7eb19c7df 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/EnumPatternObject.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/EnumPatternObject.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; import type { NumberEnum } from './NumberEnum'; import { NumberEnumFromJSON, diff --git a/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/FakeEnumRequestGetInline200Response.ts b/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/FakeEnumRequestGetInline200Response.ts index 1beee2564028..caf1f20c75b4 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/FakeEnumRequestGetInline200Response.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-string-enums/models/FakeEnumRequestGetInline200Response.ts @@ -12,7 +12,7 @@ * Do not edit the class manually. */ -import { mapValues, parseDate, parseDateTime, serializeDate, serializeDateTime } from '../runtime'; +import { mapValues } from '../runtime'; /** * * @export diff --git a/samples/client/petstore/typescript-fetch/builds/with-string-enums/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-string-enums/runtime.ts index 5a2edca34dd6..d09ba0070951 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-string-enums/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-string-enums/runtime.ts @@ -371,9 +371,13 @@ export function serializeDateTime(value: Date): string { } export function serializeDate(value: Date): string { - const year = String(value.getFullYear()).padStart(4, '0'); - const month = String(value.getMonth() + 1).padStart(2, '0'); - const day = String(value.getDate()).padStart(2, '0'); + if (isNaN(value.getTime())) { + throw new RangeError('Invalid time value'); + } + // Not padStart: the generated client may target ES6, where it does not exist. + const year = ('000' + value.getFullYear()).slice(-4); + const month = ('0' + (value.getMonth() + 1)).slice(-2); + const day = ('0' + value.getDate()).slice(-2); return `${year}-${month}-${day}`; } @@ -383,10 +387,22 @@ export function parseDate(value: any): Date { return value; } // `new Date("2026-08-05")` would parse as UTC midnight: a different day west of UTC. - // `new Date(2026, 7, 5)` builds local midnight, which is the stated day everywhere. + // Local midnight is the stated day everywhere. setFullYear avoids the 1900 offset the + // multi-argument constructor applies to years 0-99. const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(value)); if (fullDate) { - return new Date(Number(fullDate[1]), Number(fullDate[2]) - 1, Number(fullDate[3])); + const year = Number(fullDate[1]); + const month = Number(fullDate[2]) - 1; + const day = Number(fullDate[3]); + const date = new Date(0); + date.setFullYear(year, month, day); + date.setHours(0, 0, 0, 0); + // Out-of-range components (or a day the local zone skipped) silently roll over, + // which would hand back a date the server never sent. + if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { + return new Date(NaN); + } + return date; } return new Date(value); }