Open pgpaccuratech opened 6 months ago
You can implement a schema processor https://github.com/RicoSuter/NJsonSchema/wiki/Schema-Processors and modify a schema after it's creation...
Thank you so much. For others that may come accros this, this how I did:
public class ExcludeSchemaProcessor(IServiceConfig config) : ISchemaProcessor
{
private int _ignoreLevel = config.IgnoreLevel;
public void Process(SchemaProcessorContext context)
{
var type = context.Type;
var properties = type.GetProperties();
foreach (var propertyInfo in properties)
{
if (propertyInfo.GetCustomAttribute<IgnoreFeatureAttribute>() is { } ignoreFeatureAttribute)
{
if (ignoreFeatureAttribute.Level < _ignoreLevel)
{
var camelCasePropertyName = char.ToLowerInvariant(propertyInfo.Name[0]) + propertyInfo.Name.Substring(1);
context.Schema.Properties.Remove(camelCasePropertyName);
}
}
}
}
}
Very similar to this (outdated): https://github.com/RicoSuter/NSwag/issues/1267
In swashbuckler I have used this to trick to remove/ignore properties runtime:
Is there anyway to remove properties from the schema runtime, when using NSwag?