RicoSuter/NJsonSchema

Create schema from generated code with inheritance.

Open

#1,162 建立於 2020年4月16日

在 GitHub 查看
 (3 留言) (1 反應) (0 負責人)C# (550 fork)github user discovery
help wantedtype: enhancement

倉庫指標

Star
 (1,578 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

Hi,

I have special case, that causes issues.

I have a API with inheritance and a custom discriminator:

In short it looks like this:

[JsonConverter(typeof(TypedJsonInheritanceConverter<FieldPropertiesDto>), "fieldType")]
    [KnownType(nameof(Subtypes))]
    public abstract class FieldPropertiesDto
    {
        public static Type[] Subtypes()
        {
            return type.Assembly ...
        }
    }

As you can see, I have a custom converter, which derives from your InheritanceConverter and uses custom type names. This works fine, thanks to your awesome library.

From the API I generate a client library in C# and the output is like this:

[JsonConverter(typeof(JsonInheritanceConverter), new[] { "fieldType" })]
    [JsonInheritanceAttribute("Array", typeof(ArrayFieldPropertiesDto))]]
    public abstract class FieldPropertiesDto
    {
    }
}

The output is as expected. But this client library should be extended with an import feature, so I would like to use the generated code to create a json schema from it and I expect the result to be identical to the API schema.

But there are two issues:

  1. The discriminator is discriminator instead of fieldType. I think the reason is that the generated JsonInheritanceConverter class does not contain a DiscriminatorName property. This should be easy to fix.

  2. The type names are used instead of my custom names, e.g ArrayFieldPropertiesDto instead of Array. I don't know how to solve that.

貢獻者指南