Files
Umbraco-CMS/tools/Umbraco.JsonSchema/UmbracoJsonSchemaGenerator.cs
Bjarke Berg fcda25af50 Premigrations + Updated NuGet Dependencies (#15987)
* Updated nuget packages + added migrations for OpenIddict - Currently can only be executed using unatttended installs

* Added new Premigration concept - Migrations that always runs unattended before other migrations

* Apply suggestions from code review

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>

---------

Co-authored-by: Zeegaan <skrivdetud@gmail.com>
Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>
2024-04-10 12:30:30 +02:00

39 lines
1.4 KiB
C#

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using NJsonSchema.Generation;
using NJsonSchema.NewtonsoftJson.Generation;
/// <inheritdoc />
public class UmbracoJsonSchemaGenerator : JsonSchemaGenerator
{
/// <summary>
/// Initializes a new instance of the <see cref="UmbracoJsonSchemaGenerator" /> class.
/// </summary>
public UmbracoJsonSchemaGenerator()
: base(new NewtonsoftJsonSchemaGeneratorSettings()
{
AlwaysAllowAdditionalObjectProperties = true,
DefaultReferenceTypeNullHandling = ReferenceTypeNullHandling.NotNull,
FlattenInheritanceHierarchy = true,
IgnoreObsoleteProperties = true,
SerializerSettings = new JsonSerializerSettings()
{
ContractResolver = new WritablePropertiesOnlyResolver()
}
})
{
((NewtonsoftJsonSchemaGeneratorSettings)Settings).SerializerSettings.Converters.Add(new StringEnumConverter());
}
/// <inheritdoc />
private class WritablePropertiesOnlyResolver : DefaultContractResolver
{
/// <inheritdoc />
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
=> base.CreateProperties(type, memberSerialization).Where(p => p.Writable).ToList();
}
}