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:
@@ -80,11 +80,10 @@ public class GlobalSettings
|
||||
/// <summary>
|
||||
/// Gets or sets a value for the Umbraco back-office path.
|
||||
/// </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
|
||||
{
|
||||
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 { }
|
||||
}
|
||||
|
||||
|
||||
@@ -3,5 +3,5 @@ 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!;
|
||||
public required string OutputFile { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using CommandLine;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
|
||||
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 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());
|
||||
});
|
||||
|
||||
@@ -3,14 +3,14 @@ using Umbraco.Cms.Core.Configuration.Models;
|
||||
|
||||
internal class UmbracoCmsSchema
|
||||
{
|
||||
public UmbracoDefinition Umbraco { get; set; } = null!;
|
||||
public required UmbracoDefinition Umbraco { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Configuration container for all Umbraco products.
|
||||
/// </summary>
|
||||
public class UmbracoDefinition
|
||||
{
|
||||
public UmbracoCmsDefinition CMS { get; set; } = null!;
|
||||
public required UmbracoCmsDefinition CMS { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -18,66 +18,66 @@ internal class UmbracoCmsSchema
|
||||
/// </summary>
|
||||
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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using NJsonSchema;
|
||||
using NJsonSchema.Generation;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class UmbracoJsonSchemaGenerator : JsonSchemaGenerator
|
||||
internal class UmbracoJsonSchemaGenerator : JsonSchemaGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UmbracoJsonSchemaGenerator" /> class.
|
||||
@@ -19,11 +19,8 @@ public class UmbracoJsonSchemaGenerator : JsonSchemaGenerator
|
||||
ReflectionService = new UmbracoSystemTextJsonReflectionService(),
|
||||
SerializerOptions = new JsonSerializerOptions()
|
||||
{
|
||||
Converters =
|
||||
{
|
||||
new JsonStringEnumConverter()
|
||||
},
|
||||
WriteIndented = true,
|
||||
Converters = { new JsonStringEnumConverter() },
|
||||
IgnoreReadOnlyProperties = true,
|
||||
},
|
||||
})
|
||||
{ }
|
||||
@@ -34,9 +31,12 @@ public class UmbracoJsonSchemaGenerator : JsonSchemaGenerator
|
||||
/// <inheritdoc />
|
||||
public override void GenerateProperties(JsonSchema schema, ContextualType contextualType, SystemTextJsonSchemaGeneratorSettings settings, JsonSchemaGenerator schemaGenerator, JsonSchemaResolver schemaResolver)
|
||||
{
|
||||
// Populate schema properties
|
||||
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)
|
||||
{
|
||||
if (property.CanWrite is false)
|
||||
@@ -48,4 +48,5 @@ public class UmbracoJsonSchemaGenerator : JsonSchemaGenerator
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user