Bug Report Checklist
Description
When generating a C# client with the generichost templates and useDateTimeOffset=true, string/date-time properties are emitted as DateTimeOffset model properties, but the generated JSON converter first deserializes the incoming value into DateTime. That drops the original offset and replaces it with the local system offset when the DateTimeOffset is constructed.
openapi-generator version
7.21.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: DateTimeOffset Repro
version: 1.0.0
paths:
/example:
get:
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Example"
components:
schemas:
Example:
type: object
properties:
timestamp:
type: string
format: date-time
required:
- timestamp
Generation Details
- Generator: OpenAPI Generator C# client
- Library: generichost
- Config:
useDateTimeOffset=true
Steps to reproduce
Generation command:
openapi-generator-cli generate \
-g csharp \
-i openapi.yaml \
-o out \
--additional-properties=library=generichost,useDateTimeOffset=true
Repro input:
{ "timestamp": "2026-03-24T10:15:30+02:00" }
Observed result:
The generated model property is DateTimeOffset, but the deserialization path first parses the value as DateTime, so the offset from the JSON payload is not preserved.
Related issues/PRs
none found
Suggest a fix
Update the generichost date-time deserialization path to deserialize directly into DateTimeOffset when useDateTimeOffset=true, or otherwise preserve the original offset information all the way through the converter.
We customized the JsonConverter.mustache template, line 224, by inserting {{#useDateTimeOffset}}Offset{{/useDateTimeOffset}}:
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}} = {{>OptionProperty}}JsonSerializer.Deserialize<DateTime{{#useDateTimeOffset}}Offset{{/useDateTimeOffset}}{{#isNullable}}?{{/isNullable}}>(ref utf8JsonReader, jsonSerializerOptions));
Bug Report Checklist
Description
When generating a C# client with the generichost templates and
useDateTimeOffset=true,string/date-timeproperties are emitted asDateTimeOffsetmodel properties, but the generated JSON converter first deserializes the incoming value intoDateTime. That drops the original offset and replaces it with the local system offset when theDateTimeOffsetis constructed.openapi-generator version
7.21.0
OpenAPI declaration file content or url
Generation Details
useDateTimeOffset=trueSteps to reproduce
Generation command:
Repro input:
{ "timestamp": "2026-03-24T10:15:30+02:00" }Observed result:
The generated model property is DateTimeOffset, but the deserialization path first parses the value as DateTime, so the offset from the JSON payload is not preserved.
Related issues/PRs
none found
Suggest a fix
Update the generichost date-time deserialization path to deserialize directly into DateTimeOffset when useDateTimeOffset=true, or otherwise preserve the original offset information all the way through the converter.
We customized the
JsonConverter.mustachetemplate, line 224, by inserting{{#useDateTimeOffset}}Offset{{/useDateTimeOffset}}: