Bug Report Checklist
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()),
Bug Report Checklist
Description
Currently, when a class is being generated, any
dateTimevalues can not be null. It will replace the value withundefinedinstead. 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:
Or with docker:
Possible offending file:
openapi-generator/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache
Lines 142 to 147 in a7159f6
Steps to reproduce
Generate a class with a
dateTimeproperty that is nullable:Related issues/PRs
Might be related? #11307
Suggest a fix
Expected result (somewhat like seen here):
Current result (as seen here)