Bug Report Checklist
Description
When generating a C# client using OpenAPI Generator (v7.24), there is a critical issue with oneOf schemas:
Empty WriteProperties Methods: The WriteProperties methods in the JsonConverter<T> classes for oneOf schemas are empty, causing serialization to produce incorrect JSON (e.g., {}).
Impact (Major Blocker)
- Serialization produces incorrect output: The
Write method calls WriteProperties, but the latter contains no logic to serialize the active oneOf member.
- Affects multiple
oneOf variants: observed with primitive types (number/string), inline string enums, and object references ($ref).
openapi-generator version
v7.24.0
OpenAPI declaration file content or url
openapi: 3.1.2
info:
title: Simple API
version: 1.0.0
paths:
/hello:
post:
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/HelloResponse'
components:
schemas:
HelloResponse:
type: object
properties:
firstCustomProperty:
oneOf:
- type: number
- type: string
secondCustomProperty:
oneOf:
- type: number
- type: string
enum: [TEST1, TEST2, TEST3]
thirdCustomProperty:
oneOf:
- $ref: '#/components/schemas/FirstSub'
- $ref: '#/components/schemas/SecondSub'
FirstSub:
type: object
properties:
id: { type: string }
name: { type: string }
SecondSub:
type: object
properties:
id: { type: number }
name: { type: string }
age: { type: number }
Generation Details
Use this config.json:
{
"packageName": "Tenics.OneOfDemo.Sdk",
"packageVersion": "1.0.0",
"targetFramework": "net10.0",
"library": "generichost",
"nullableReferenceTypes": true,
"modelPropertyNaming": "PascalCase"
}
Use this to generate client:
openapi-generator-cli generate \
-i spec.yaml \
-g csharp \
-c config.json \
-o ./generated
Expected Behavior
The generated JsonConverter<T> should serialize whichever oneOf branch is populated.
For example:
public void Write(Utf8JsonWriter writer, HelloResponseSecondCustomProperty value, JsonSerializerOptions options)
{
if (value.Double.HasValue)
{
writer.WriteNumberValue(value.Double.Value);
}
else if (value.String != null)
{
writer.WriteStringValue(value.String);
}
}
Actual Behavior
The generated file:
HelloResponseSecondCustomPropertyJsonConverter.cs
contains:
- The
WriteProperties method is empty and lacks serialization logic:
public override void Write(Utf8JsonWriter writer, HelloResponseSecondCustomProperty helloResponseSecondCustomProperty, JsonSerializerOptions jsonSerializerOptions)
{
writer.WriteStartObject();
WriteProperties(writer, helloResponseSecondCustomProperty, jsonSerializerOptions);
writer.WriteEndObject();
}
public void WriteProperties(Utf8JsonWriter writer, HelloResponseSecondCustomProperty value, JsonSerializerOptions options)
{
// Missing logic to serialize Double or String
}
Related Tickets
Bug Report Checklist
Description
When generating a C# client using OpenAPI Generator (v7.24), there is a critical issue with
oneOfschemas:Empty
WritePropertiesMethods: TheWritePropertiesmethods in theJsonConverter<T>classes foroneOfschemas are empty, causing serialization to produce incorrect JSON (e.g.,{}).Impact (Major Blocker)
Writemethod callsWriteProperties, but the latter contains no logic to serialize the activeoneOfmember.oneOfvariants: observed with primitive types (number/string), inline string enums, and object references ($ref).openapi-generator version
v7.24.0
OpenAPI declaration file content or url
Generation Details
Use this
config.json:{ "packageName": "Tenics.OneOfDemo.Sdk", "packageVersion": "1.0.0", "targetFramework": "net10.0", "library": "generichost", "nullableReferenceTypes": true, "modelPropertyNaming": "PascalCase" }Use this to generate client:
Expected Behavior
The generated
JsonConverter<T>should serialize whicheveroneOfbranch is populated.For example:
Actual Behavior
The generated file:
HelloResponseSecondCustomPropertyJsonConverter.cscontains:
WritePropertiesmethod is empty and lacks serialization logic:Related Tickets