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:
7
tools/Umbraco.JsonSchema/Options.cs
Normal file
7
tools/Umbraco.JsonSchema/Options.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using CommandLine;
|
||||
|
||||
internal class Options
|
||||
{
|
||||
[Option("outputFile", Default = "appsettings-schema.Umbraco.Cms.json", HelpText = "Output file to save the generated JSON schema for Umbraco CMS.")]
|
||||
public string OutputFile { get; set; } = null!;
|
||||
}
|
||||
14
tools/Umbraco.JsonSchema/Program.cs
Normal file
14
tools/Umbraco.JsonSchema/Program.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using CommandLine;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
|
||||
await Parser.Default.ParseArguments<Options>(args).WithParsedAsync(async options =>
|
||||
{
|
||||
// Generate CMS schema
|
||||
var jsonSchemaGenerator = new UmbracoJsonSchemaGenerator();
|
||||
var jsonSchema = jsonSchemaGenerator.Generate(typeof(UmbracoCmsSchema));
|
||||
|
||||
// TODO: When the UmbracoPath setter is removed from GlobalSettings (scheduled for V12), remove this line as well
|
||||
jsonSchema.Definitions[nameof(GlobalSettings)]?.Properties?.Remove(nameof(GlobalSettings.UmbracoPath));
|
||||
|
||||
await File.WriteAllTextAsync(options.OutputFile, jsonSchema.ToJson());
|
||||
});
|
||||
16
tools/Umbraco.JsonSchema/Umbraco.JsonSchema.csproj
Normal file
16
tools/Umbraco.JsonSchema/Umbraco.JsonSchema.csproj
Normal file
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<IsPackable>false</IsPackable>
|
||||
<EnablePackageValidation>false</EnablePackageValidation>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
||||
<PackageReference Include="NJsonSchema" Version="10.8.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Umbraco.Core\Umbraco.Core.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
81
tools/Umbraco.JsonSchema/UmbracoCmsSchema.cs
Normal file
81
tools/Umbraco.JsonSchema/UmbracoCmsSchema.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using Umbraco.Cms.Core.Configuration;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
|
||||
internal class UmbracoCmsSchema
|
||||
{
|
||||
public UmbracoDefinition Umbraco { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Configuration container for all Umbraco products.
|
||||
/// </summary>
|
||||
public class UmbracoDefinition
|
||||
{
|
||||
public UmbracoCmsDefinition CMS { get; set; } = null!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configuration of Umbraco CMS.
|
||||
/// </summary>
|
||||
public class UmbracoCmsDefinition
|
||||
{
|
||||
public ContentSettings Content { get; set; } = null!;
|
||||
|
||||
public CoreDebugSettings Debug { get; set; } = null!;
|
||||
|
||||
public ExceptionFilterSettings ExceptionFilter { get; set; } = null!;
|
||||
|
||||
public ModelsBuilderSettings ModelsBuilder { get; set; } = null!;
|
||||
|
||||
public GlobalSettings Global { get; set; } = null!;
|
||||
|
||||
public HealthChecksSettings HealthChecks { get; set; } = null!;
|
||||
|
||||
public HostingSettings Hosting { get; set; } = null!;
|
||||
|
||||
public ImagingSettings Imaging { get; set; } = null!;
|
||||
|
||||
public IndexCreatorSettings Examine { get; set; } = null!;
|
||||
|
||||
public KeepAliveSettings KeepAlive { get; set; } = null!;
|
||||
|
||||
public LoggingSettings Logging { get; set; } = null!;
|
||||
|
||||
public NuCacheSettings NuCache { get; set; } = null!;
|
||||
|
||||
public RequestHandlerSettings RequestHandler { get; set; } = null!;
|
||||
|
||||
public RuntimeSettings Runtime { get; set; } = null!;
|
||||
|
||||
public SecuritySettings Security { get; set; } = null!;
|
||||
|
||||
public TourSettings Tours { get; set; } = null!;
|
||||
|
||||
public TypeFinderSettings TypeFinder { get; set; } = null!;
|
||||
|
||||
public WebRoutingSettings WebRouting { get; set; } = null!;
|
||||
|
||||
public UmbracoPluginSettings Plugins { get; set; } = null!;
|
||||
|
||||
public UnattendedSettings Unattended { get; set; } = null!;
|
||||
|
||||
public RichTextEditorSettings RichTextEditor { get; set; } = null!;
|
||||
|
||||
public RuntimeMinificationSettings RuntimeMinification { get; set; } = null!;
|
||||
|
||||
public BasicAuthSettings BasicAuth { get; set; } = null!;
|
||||
|
||||
public PackageMigrationSettings PackageMigration { get; set; } = null!;
|
||||
|
||||
public LegacyPasswordMigrationSettings LegacyPasswordMigration { get; set; } = null!;
|
||||
|
||||
public ContentDashboardSettings ContentDashboard { get; set; } = null!;
|
||||
|
||||
public HelpPageSettings HelpPage { get; set; } = null!;
|
||||
|
||||
public InstallDefaultDataSettings DefaultDataCreation { get; set; } = null!;
|
||||
|
||||
public DataTypesSettings DataTypes { get; set; } = null!;
|
||||
|
||||
public MarketplaceSettings Marketplace { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
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