Skip to content

[BUG][typescript-fetch] Datetime in classes can't be null #21132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
5 of 6 tasks
tikki100 opened this issue Apr 23, 2025 · 0 comments · May be fixed by #21133
Open
5 of 6 tasks

[BUG][typescript-fetch] Datetime in classes can't be null #21132

tikki100 opened this issue Apr 23, 2025 · 0 comments · May be fixed by #21133

Comments

@tikki100
Copy link

tikki100 commented Apr 23, 2025

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Currently, when a class is being generated, any dateTime values can not be null. It will replace the value with undefined instead. This means that you can not pass null as a value to any property that is part of a nullable class.

openapi-generator version

7.12.0

OpenAPI declaration file content or url

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml

Generation Details

cli command:

openapi-generator generate -i openapi.yaml -g typescript-fetch -o src/generated-api --additional-properties=importFileExtension=.js

Or with docker:

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
    -i https://raw.githubusercontent.com/OpenAPITools/openapi-generator/refs/heads/master/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml \
    -g typescript-fetch \
    -o /local/packages/test/src/generated-api

Possible offending file:

{{#isDateType}}
'{{baseName}}': {{^required}}value['{{name}}'] == null ? undefined : {{/required}}({{#required}}{{#isNullable}}value['{{name}}'] == null ? null : {{/isNullable}}{{/required}}(value['{{name}}']{{#isNullable}} as any{{/isNullable}}).toISOString().substring(0,10)),
{{/isDateType}}
{{#isDateTimeType}}
'{{baseName}}': {{^required}}value['{{name}}'] == null ? undefined : {{/required}}({{#required}}{{#isNullable}}value['{{name}}'] == null ? null : {{/isNullable}}{{/required}}(value['{{name}}']{{#isNullable}} as any{{/isNullable}}).toISOString()),
{{/isDateTimeType}}

Steps to reproduce

Generate a class with a dateTime property that is nullable:

        shipDate:
          type: string
          format: date-time
          nullable: true
Related issues/PRs

Might be related? #11307

Suggest a fix

Expected result (somewhat like seen here):

        'date_prop': value['dateProp'] === null ? null : ((value['dateProp'] as any)?.toISOString().substring(0,10)),
        'datetime_prop': value['datetimeProp'] === null ? null : ((value['datetimeProp'] as any)?.toISOString()),

Current result (as seen here)

        'date_prop': value['dateProp'] == null ? undefined : ((value['dateProp'] as any).toISOString().substring(0,10)),
        'datetime_prop': value['datetimeProp'] == null ? undefined : ((value['datetimeProp'] as any).toISOString()),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant