-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
When the OpenAPI 3.0 schema defines inheritance the generated code using System.Text.Json is full of compilation errors.
NSwag: 13.15.7
OpenAPI definition:
TypeBase:
type: object
required:
- $type
properties:
$type:
type: string
discriminator:
propertyName: $type
TypeA:
allOf:
- $ref: '#/components/schemas/TypeBase'
- type: object
TypeB:
allOf:
- $ref: '#/components/schemas/TypeBase'
- type: objectCommand: dotnet nswag openapi2csclient /JsonLibrary:SystemTextJson
Generated model specifies JsonInheritanceConverter improperly, which leaves a compilation error:
[JsonInheritanceConverter(typeof(TypeBase), "$type")]
[JsonInheritanceAttribute("TypeA", typeof(TypeA))]
[JsonInheritanceAttribute("TypeB", typeof(TypeB))]
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.15.7.0 (NJsonSchema v10.6.7.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class TypeBase
{
private System.Collections.Generic.IDictionary<string, object> _additionalProperties = new System.Collections.Generic.Dictionary<string, object>();
[System.Text.Json.Serialization.JsonExtensionData]
public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
{
get { return _additionalProperties; }
set { _additionalProperties = value; }
}
}
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.15.7.0 (NJsonSchema v10.6.7.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class TypeA : TypeBase
{
}
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.15.7.0 (NJsonSchema v10.6.7.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class TypeB : TypeBase
{
}Generated JsonInheritanceConverter still uses NewtonsoftJson, which leaves a lot of compilation errors: internal class JsonInheritanceConverter : Newtonsoft.Json.JsonConverter
Is there any issue with the OpenAPI definition or does the command require some more parameters?
Though, the generated code using NewtonsoftJson works as expected.
Metadata
Metadata
Assignees
Labels
No labels