Open
Description
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
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:
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()),