Hello
For my use case, I am not allowed to export the Name and Description from the DisplayAttribute when generating the JSON schema.
I can work around this by overriding two functions and then setting the Description to null. (See workaround bellow.)
Would a pull request that adds two new properties for UseDisplayName and UseDisplayDescription to the JsonSchemaGeneratorSettings class (like UseXmlDocumentation) be accepted?
Or is this something you would prefer not to have in the settings?
I’d also like to add a setting for UseDefaultValue.
Since my property has not the same type as the type of the value of the DefaultValue attribute (yes, I know…), I’m getting an exception. But I’ve got a workaround for that too.
Workaround:
protected override void GenerateObject(JsonSchema schema, JsonTypeDescription typeDescription, JsonSchemaResolver schemaResolver)
{
base.GenerateObject(schema, typeDescription, schemaResolver);
schema.Description = null;
}
public override void ApplyDataAnnotations(JsonSchema schema, JsonTypeDescription typeDescription)
{
base.ApplyDataAnnotations(schema, typeDescription);
schema.Description = null;
}
public class IgnoreDefaultValuesContractResolver : DefaultContractResolver
{
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
JsonProperty property = base.CreateProperty(member, memberSerialization);
// Check if property has DefaultValueAttribute
var defaultValueAttr = member.GetCustomAttributes(typeof(DefaultValueAttribute), true)
.OfType<DefaultValueAttribute>()
.FirstOrDefault();
if (defaultValueAttr != null)
{
property.DefaultValue = null;
}
return property;
}
}
Hello
For my use case, I am not allowed to export the
NameandDescriptionfrom theDisplayAttributewhen generating the JSON schema.I can work around this by overriding two functions and then setting the
Descriptiontonull. (See workaround bellow.)Would a pull request that adds two new properties for
UseDisplayNameandUseDisplayDescriptionto theJsonSchemaGeneratorSettingsclass (likeUseXmlDocumentation) be accepted?Or is this something you would prefer not to have in the settings?
I’d also like to add a setting for
UseDefaultValue.Since my property has not the same type as the type of the value of the
DefaultValueattribute (yes, I know…), I’m getting an exception. But I’ve got a workaround for that too.Workaround: