-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
Description
I have class inheritance in schema definition and using enum in descriminator property. When generating code with csharp a generichost library it generates wrong code in base class and its JSON converter.
[JsonIgnore]
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public ObjectTypeEnum ObjectType { get; } = "TestDescendants"; //This line does not compileand
public void WriteProperties(Utf8JsonWriter writer, TestDescendants testDescendants, JsonSerializerOptions jsonSerializerOptions)
{
if (testDescendants.AlternativeName == null)
throw new ArgumentNullException(nameof(testDescendants.AlternativeName), "Property is required for class TestDescendants.");
writer.WriteString("alternativeName", testDescendants.AlternativeName);
writer.WriteString("objectType", ); //This line does not compile
}openapi-generator version
openapi-codegen-cli-7.8.0.jar
OpenAPI declaration file content or url
Generation Details
java.exe -jar .\openapi-generator-cli.jar generate -i '.\enum-discriminator.yaml' -g csharp -o .\test\ --additional-properties='library=generichost,targetFramework=net8.0,excludeTests=true,nullableReferenceTypes=true,useOneOfDiscriminatorLookup=true,packageName=Test.Client'
Steps to reproduce
Generate code with command above and then open solution in VS and build or use dotnet build command. Compilation error appears.
Suggest a fix
The objectType property in TestDescendants does not have isNew flag set to true and wrong template branch is used in modelGeneric.mustache on line 173 and also in JsonConverter.mustache on line 442. Remove {{#isNew}} check for enum properties.