v14: JSON schema tool improvements (#16035)

* Use require modifier instead of setting null-suppressed default values

* Only remove read-only properties when IgnoreReadOnlyProperties is set

* Obsolete UmbracoPath property and remove work-around for obsolete setter
This commit is contained in:
Ronald Barendse
2024-04-15 08:58:52 +02:00
committed by GitHub
parent 767c417153
commit ad82fe89cf
5 changed files with 48 additions and 52 deletions

View File

@@ -80,11 +80,10 @@ public class GlobalSettings
/// <summary> /// <summary>
/// Gets or sets a value for the Umbraco back-office path. /// Gets or sets a value for the Umbraco back-office path.
/// </summary> /// </summary>
[Obsolete($"UmbracoPath is no longer configurable, use Constants.System.DefaultUmbracoPath instead. This property is scheduled for removal in a future version.")]
public string UmbracoPath public string UmbracoPath
{ {
get => Constants.System.DefaultUmbracoPath; get => Constants.System.DefaultUmbracoPath;
[Obsolete($"{nameof(UmbracoPath)} is no longer configurable, this property setter is scheduled for removal in V12.")]
// NOTE: When removing this, also clean up the hardcoded removal of UmbracoPath in Umbraco.JsonSchema
set { } set { }
} }

View File

@@ -3,5 +3,5 @@ using CommandLine;
internal class Options internal class Options
{ {
[Option("outputFile", Default = "appsettings-schema.Umbraco.Cms.json", HelpText = "Output file to save the generated JSON schema for Umbraco CMS.")] [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!; public required string OutputFile { get; set; }
} }

View File

@@ -1,5 +1,4 @@
using CommandLine; using CommandLine;
using Umbraco.Cms.Core.Configuration.Models;
await Parser.Default.ParseArguments<Options>(args).WithParsedAsync(async options => await Parser.Default.ParseArguments<Options>(args).WithParsedAsync(async options =>
{ {
@@ -7,8 +6,5 @@ await Parser.Default.ParseArguments<Options>(args).WithParsedAsync(async options
var jsonSchemaGenerator = new UmbracoJsonSchemaGenerator(); var jsonSchemaGenerator = new UmbracoJsonSchemaGenerator();
var jsonSchema = jsonSchemaGenerator.Generate(typeof(UmbracoCmsSchema)); 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()); await File.WriteAllTextAsync(options.OutputFile, jsonSchema.ToJson());
}); });

View File

@@ -3,14 +3,14 @@ using Umbraco.Cms.Core.Configuration.Models;
internal class UmbracoCmsSchema internal class UmbracoCmsSchema
{ {
public UmbracoDefinition Umbraco { get; set; } = null!; public required UmbracoDefinition Umbraco { get; set; }
/// <summary> /// <summary>
/// Configuration container for all Umbraco products. /// Configuration container for all Umbraco products.
/// </summary> /// </summary>
public class UmbracoDefinition public class UmbracoDefinition
{ {
public UmbracoCmsDefinition CMS { get; set; } = null!; public required UmbracoCmsDefinition CMS { get; set; }
} }
/// <summary> /// <summary>
@@ -18,66 +18,66 @@ internal class UmbracoCmsSchema
/// </summary> /// </summary>
public class UmbracoCmsDefinition public class UmbracoCmsDefinition
{ {
public ContentSettings Content { get; set; } = null!; public required ContentSettings Content { get; set; }
public DeliveryApiSettings DeliveryApi { get; set; } = null!; public required DeliveryApiSettings DeliveryApi { get; set; }
public CoreDebugSettings Debug { get; set; } = null!; public required CoreDebugSettings Debug { get; set; }
public ExceptionFilterSettings ExceptionFilter { get; set; } = null!; public required ExceptionFilterSettings ExceptionFilter { get; set; }
public ModelsBuilderSettings ModelsBuilder { get; set; } = null!; public required ModelsBuilderSettings ModelsBuilder { get; set; }
public GlobalSettings Global { get; set; } = null!; public required GlobalSettings Global { get; set; }
public HealthChecksSettings HealthChecks { get; set; } = null!; public required HealthChecksSettings HealthChecks { get; set; }
public HostingSettings Hosting { get; set; } = null!; public required HostingSettings Hosting { get; set; }
public ImagingSettings Imaging { get; set; } = null!; public required ImagingSettings Imaging { get; set; }
public IndexCreatorSettings Examine { get; set; } = null!; public required IndexCreatorSettings Examine { get; set; }
public IndexingSettings Indexing { get; set; } = null!; public required IndexingSettings Indexing { get; set; }
public LoggingSettings Logging { get; set; } = null!; public required LoggingSettings Logging { get; set; }
public NuCacheSettings NuCache { get; set; } = null!; public required NuCacheSettings NuCache { get; set; }
public RequestHandlerSettings RequestHandler { get; set; } = null!; public required RequestHandlerSettings RequestHandler { get; set; }
public RuntimeSettings Runtime { get; set; } = null!; public required RuntimeSettings Runtime { get; set; }
public SecuritySettings Security { get; set; } = null!; public required SecuritySettings Security { get; set; }
public TypeFinderSettings TypeFinder { get; set; } = null!; public required TypeFinderSettings TypeFinder { get; set; }
public WebRoutingSettings WebRouting { get; set; } = null!; public required WebRoutingSettings WebRouting { get; set; }
public UmbracoPluginSettings Plugins { get; set; } = null!; public required UmbracoPluginSettings Plugins { get; set; }
public UnattendedSettings Unattended { get; set; } = null!; public required UnattendedSettings Unattended { get; set; }
public RichTextEditorSettings RichTextEditor { get; set; } = null!; public required RichTextEditorSettings RichTextEditor { get; set; }
public RuntimeMinificationSettings RuntimeMinification { get; set; } = null!; public required RuntimeMinificationSettings RuntimeMinification { get; set; }
public BasicAuthSettings BasicAuth { get; set; } = null!; public required BasicAuthSettings BasicAuth { get; set; }
public PackageMigrationSettings PackageMigration { get; set; } = null!; public required PackageMigrationSettings PackageMigration { get; set; }
public LegacyPasswordMigrationSettings LegacyPasswordMigration { get; set; } = null!; public required LegacyPasswordMigrationSettings LegacyPasswordMigration { get; set; }
public ContentDashboardSettings ContentDashboard { get; set; } = null!; public required ContentDashboardSettings ContentDashboard { get; set; }
public HelpPageSettings HelpPage { get; set; } = null!; public required HelpPageSettings HelpPage { get; set; }
public InstallDefaultDataSettings DefaultDataCreation { get; set; } = null!; public required InstallDefaultDataSettings DefaultDataCreation { get; set; }
public DataTypesSettings DataTypes { get; set; } = null!; public required DataTypesSettings DataTypes { get; set; }
public MarketplaceSettings Marketplace { get; set; } = null!; public required MarketplaceSettings Marketplace { get; set; }
public WebhookSettings Webhook { get; set; } = null!; public required WebhookSettings Webhook { get; set; }
} }
} }

View File

@@ -5,7 +5,7 @@ using NJsonSchema;
using NJsonSchema.Generation; using NJsonSchema.Generation;
/// <inheritdoc /> /// <inheritdoc />
public class UmbracoJsonSchemaGenerator : JsonSchemaGenerator internal class UmbracoJsonSchemaGenerator : JsonSchemaGenerator
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="UmbracoJsonSchemaGenerator" /> class. /// Initializes a new instance of the <see cref="UmbracoJsonSchemaGenerator" /> class.
@@ -19,11 +19,8 @@ public class UmbracoJsonSchemaGenerator : JsonSchemaGenerator
ReflectionService = new UmbracoSystemTextJsonReflectionService(), ReflectionService = new UmbracoSystemTextJsonReflectionService(),
SerializerOptions = new JsonSerializerOptions() SerializerOptions = new JsonSerializerOptions()
{ {
Converters = Converters = { new JsonStringEnumConverter() },
{ IgnoreReadOnlyProperties = true,
new JsonStringEnumConverter()
},
WriteIndented = true,
}, },
}) })
{ } { }
@@ -34,9 +31,12 @@ public class UmbracoJsonSchemaGenerator : JsonSchemaGenerator
/// <inheritdoc /> /// <inheritdoc />
public override void GenerateProperties(JsonSchema schema, ContextualType contextualType, SystemTextJsonSchemaGeneratorSettings settings, JsonSchemaGenerator schemaGenerator, JsonSchemaResolver schemaResolver) public override void GenerateProperties(JsonSchema schema, ContextualType contextualType, SystemTextJsonSchemaGeneratorSettings settings, JsonSchemaGenerator schemaGenerator, JsonSchemaResolver schemaResolver)
{ {
// Populate schema properties
base.GenerateProperties(schema, contextualType, settings, schemaGenerator, schemaResolver); base.GenerateProperties(schema, contextualType, settings, schemaGenerator, schemaResolver);
// Remove read-only properties if (settings.SerializerOptions.IgnoreReadOnlyProperties)
{
// Remove read-only properties (because this is not implemented by the base class)
foreach (ContextualPropertyInfo property in contextualType.Properties) foreach (ContextualPropertyInfo property in contextualType.Properties)
{ {
if (property.CanWrite is false) if (property.CanWrite is false)
@@ -48,4 +48,5 @@ public class UmbracoJsonSchemaGenerator : JsonSchemaGenerator
} }
} }
} }
}
} }