Open Dietatko opened 2 years ago
One of data schemas in OpenApi spec has property containing array of DayOfWeek enumerations:
ShiftDto: type: object properties: daysOfWeekActive: type: array items: $ref: '#/components/schemas/DayOfWeek' DayOfWeek: enum: - Sunday - Monday - Tuesday - Wednesday - Thursday - Friday - Saturday type: string
I want to use the System.DayOfWeek enum in the generated C# client so I tweaked the generator options:
{ ..., "codeGenerators": { "openApiToCSharpClient": { "additionalNamespaceUsages": [ "DayOfWeek = System.DayOfWeek" ], "excludedTypeNames": [ "DayOfWeek" ], ... } } }
Actual behaviour:
The generated client code is:
public partial class ShiftDto { [System.Text.Json.Serialization.JsonPropertyName("daysOfWeekActive")] // TODO(system.text.json): Add string enum item converter public System.Collections.Generic.ICollection<DayOfWeek> DaysOfWeekActive { get; set; } }
and the deserialisation fails unless the JsonStringEnumConverter is explicitly added to serialiser options.
Expected behaviour:
The object can be deserialised without configuring the serialiser.
@Dietatko, Did you find a solution to your problem? We have a similar issue. THnak you for your help!!
One of data schemas in OpenApi spec has property containing array of DayOfWeek enumerations:
I want to use the System.DayOfWeek enum in the generated C# client so I tweaked the generator options:
Actual behaviour:
The generated client code is:
and the deserialisation fails unless the JsonStringEnumConverter is explicitly added to serialiser options.
Expected behaviour:
The object can be deserialised without configuring the serialiser.