RicoSuter/NJsonSchema

Create schema from generated code with inheritance.

Open

#1.162 geöffnet am 16. Apr. 2020

Auf GitHub ansehen
 (3 Kommentare) (1 Reaktion) (0 zugewiesene Personen)C# (550 Forks)github user discovery
help wantedtype: enhancement

Repository-Metriken

Stars
 (1.578 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

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.

Contributor Guide