Simplify JSON schema, generation, copying and updating (#13427)
* Simplify JSON schema and only generate appsettings-schema.Umbraco.Cms.json * Use Umbraco.JsonSchema.Extensions to dynamically add JSON schema references * Move DependentUpon items to shared MSBuild props * Update LangVersion to latest * Update Umbraco.GitVersioning.Extensions to 0.2.0 * Remove JSON schemas on clean * Remove Umbraco.JsonSchema.Core project * Fix JSON schema nullability * Ignore additional JSON schema files in template * Update CompatibilitySuppressions.xml * Remove GlobalSettings.UmbracoPath from JSON schema again * Remove RemoveUmbracoJsonSchemaFiles target * Update Umbraco.JsonSchema.Extensions to 0.2.0 and add weights * Flatten generated JSON schema hierarchy * Remove LicensesSettings from CMS codebase * Change AdditionalParameters to IDictionary
This commit is contained in:
35
tools/Umbraco.JsonSchema/UmbracoJsonSchemaGenerator.cs
Normal file
35
tools/Umbraco.JsonSchema/UmbracoJsonSchemaGenerator.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using NJsonSchema.Generation;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class UmbracoJsonSchemaGenerator : JsonSchemaGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UmbracoJsonSchemaGenerator" /> class.
|
||||
/// </summary>
|
||||
public UmbracoJsonSchemaGenerator()
|
||||
: base(new JsonSchemaGeneratorSettings()
|
||||
{
|
||||
AlwaysAllowAdditionalObjectProperties = true,
|
||||
DefaultReferenceTypeNullHandling = ReferenceTypeNullHandling.NotNull,
|
||||
FlattenInheritanceHierarchy = true,
|
||||
IgnoreObsoleteProperties = true,
|
||||
SerializerSettings = new JsonSerializerSettings()
|
||||
{
|
||||
ContractResolver = new WritablePropertiesOnlyResolver()
|
||||
}
|
||||
})
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user