NJsonSchema
NJsonSchema copied to clipboard
Make getting members in JsonSchemaGenerator virtual
Hello, I was wondering if you would be open to making retrieving a type's members a virtual method so it could be customized here. https://github.com/RicoSuter/NJsonSchema/blob/master/src/NJsonSchema/Generation/JsonSchemaGenerator.cs#L884
The need for this is due to our specialized use case of serializing and deserializing to interface contracts which may use explicit interface implementation to avoid naming conflicts. Here's an example.
public interface IFooV1
{
List<string> Bars { get; }
}
public interface IFooV2
{
List<Bar> Bars { get; }
}
public class Foo : IFooV1, IFooV2
{
public required List<Bar> Bars { get; set; }
List<string> IFooV1.Bars => Bars.ConvertAll(b => b.Name);
}
public class Bar
{
public required string Name { get; set; }
}
In this case if we're trying to get the schema for Foo
for V1 the Bars
property will show as a List<Bar>
instead of List<string>
. We've configured the JsonContractResolver
to return the proper type based on the version but the members still uses the class's property types. We'd prefer not to fork if we don't have to but understand it's a very niche request. Thanks.
can you update the link to the method to make virtual? or post the method name?
This was in regards to this code but it appears you may have changed things that may have addressed this though I haven't looked too deeply yet. https://github.com/RicoSuter/NJsonSchema/blob/ed250a8b9c4f86a4da40cf0061cf0172cdea0449/src/NJsonSchema/Generation/JsonSchemaGenerator.cs#L884-L906