Repository navigation
Open
Labels
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- 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
I tested polymoprphie with with the charp generator default not library=RestSharp. In my open api description i have a discriminator mapping which is not applied correctly in the Deserializer of the BaseType
Type: ValueTypeBase
openapi-generator version
v7.17.0
OpenAPI declaration file content or url
Generation Details
config.yaml
additionalProperties:
targetFramework: net9.0
packageName: Rexroth.InduFlow.ApiClientdocker run --rm -v C:\100_Devel\induflow-example\:/local openapitools/openapi-generator-cli:v7.17.0 generate -i /local/code-generation/openapi.json -g csharp -o /local/lib/Rexroth.InduFlow.ApiClient -c /local/code-generation/config.yaml Output
Steps to reproduce
Generate as described and see the Model/ValueTypeBase.cs
public override ValueTypeBase Read(ref Utf8JsonReader utf8JsonReader, Type typeToConvert, JsonSerializerOptions jsonSerializerOptions)
{
int currentDepth = utf8JsonReader.CurrentDepth;
if (utf8JsonReader.TokenType != JsonTokenType.StartObject && utf8JsonReader.TokenType != JsonTokenType.StartArray)
throw new JsonException();
JsonTokenType startingTokenType = utf8JsonReader.TokenType;
Option<string?> kind = default;
string? discriminator = ClientUtils.GetDiscriminator(utf8JsonReader, "kind");
if (discriminator != null && discriminator.Equals("BooleanValue"))
return JsonSerializer.Deserialize<BooleanValue>(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value.");
if (discriminator != null && discriminator.Equals("NumberValue"))
return JsonSerializer.Deserialize<NumberValue>(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value.");
if (discriminator != null && discriminator.Equals("PhysicalValue"))
return JsonSerializer.Deserialize<PhysicalValue>(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value.");
if (discriminator != null && discriminator.Equals("TextValue"))
return JsonSerializer.Deserialize<TextValue>(ref utf8JsonReader, jsonSerializerOptions) ?? throw new JsonException("The result was an unexpected value.");
while (utf8JsonReader.Read())
{
if (startingTokenType == JsonTokenType.StartObject && utf8JsonReader.TokenType == JsonTokenType.EndObject && currentDepth == utf8JsonReader.CurrentDepth)
break;
if (startingTokenType == JsonTokenType.StartArray && utf8JsonReader.TokenType == JsonTokenType.EndArray && currentDepth == utf8JsonReader.CurrentDepth)
break;
if (utf8JsonReader.TokenType == JsonTokenType.PropertyName && currentDepth == utf8JsonReader.CurrentDepth - 1)
{
string? localVarJsonPropertyName = utf8JsonReader.GetString();
utf8JsonReader.Read();
switch (localVarJsonPropertyName)
{
case "kind":
kind = new Option<string?>(utf8JsonReader.GetString()!);
break;
default:
break;
}
}
}
if (!kind.IsSet)
throw new ArgumentException("Property is required for class ValueTypeBase.", nameof(kind));
if (kind.IsSet && kind.Value == null)
throw new ArgumentNullException(nameof(kind), "Property is not nullable for class ValueTypeBase.");
return new ValueTypeBase();
}discriminator check should be on "bool", "text", "physical" and "number"
Related issues/PRs
Suggest a fix
Reacted by Alexander Kunkel and floflausch
Activity
wing328 commentedon Nov 5, 2025
can you try
restsharplibrary? I remember it has implementation for discriminator mapping but I could be wrong.pfeufferdaniel commentedon Nov 7, 2025
sorry for the late response i thought i got some notifications if some one replies....
yes we tried restsharp and it do the mapping. But we had some other troubles with the Restsharp implmentation. And we like the default generator because it has less dependency.
But do you know what will be the maintained better?
But never the less we changed our Open Api description especially this parts
then it do the mapping:
and works if the server still has polymorphie. But then the client has no Polymorphie....
its not the best solution for us but something we can use.
devhl-labs commentedon Nov 8, 2025
Im tracking this already. I've got a branch i think targets this, its a tricky one though.