You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use NSwag to generate a CSharp client (System.Text.Json) based on an OpenAPI spec from HERE. And with one of their APIs I have the following exception with the generated NSwag code.
System.InvalidOperationException
The type 'Here.Routing.CalculateMatrix.Truck2' cannot have more than one member that has the attribute 'System.Text.Json.Serialization.JsonExtensionDataAttribute'.
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializationDuplicateTypeAttribute(Type classType, Type attribute)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.CacheMember(Type declaringType, Type memberType, MemberInfo memberInfo, Boolean isVirtual, Nullable`1 typeNumberHandling, Boolean& propertyOrderSpecified, Dictionary`2& ignoredMembers)
The problem is that Truck2 inherits from Truck and both have the following code being generated.
The base class and the derived class both have a property AdditionalProperties with the JsonExtensionData attribute and it seems that System.Text.Json (v6.0.0) doesn't allow that.
Is there a way to prevent AdditionalProperties being added to derived classes?
And what is the reason, the element in the yaml/json that renders this?
I want to help with a PR, but I'm a bit lost in the code ;-).
I found the place where the AdditionalProperties are generated.
I'm trying to use NSwag to generate a CSharp client (System.Text.Json) based on an OpenAPI spec from HERE. And with one of their APIs I have the following exception with the generated NSwag code.
https://developer.here.com/documentation/matrix-routing-api/8.5.0/swagger/spec.yaml
The problem is that Truck2 inherits from Truck and both have the following code being generated.
The base class and the derived class both have a property AdditionalProperties with the JsonExtensionData attribute and it seems that System.Text.Json (v6.0.0) doesn't allow that.
Is there a way to prevent AdditionalProperties being added to derived classes?
And what is the reason, the element in the yaml/json that renders this?
I want to help with a PR, but I'm a bit lost in the code ;-).
I found the place where the AdditionalProperties are generated.
NJsonSchema/src/NJsonSchema.CodeGeneration.CSharp/Templates/Class.liquid
Lines 117 to 132 in 463d246
And the code that determines the HasAdditionalPropertiesType.
NJsonSchema/src/NJsonSchema.CodeGeneration.CSharp/Models/ClassTemplateModel.cs
Lines 66 to 72 in 3aef4ea
But I'm uncertain what to add to prevent the AdditionalProperties being added to derived classes and it that is the right solution.
The text was updated successfully, but these errors were encountered: