Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v14: JSON schema tool improvements #16035

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Umbraco.Core/Configuration/Models/GlobalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ internal const string
public int VersionCheckPeriod { get; set; } = StaticVersionCheckPeriod;

/// <summary>
/// Gets or sets a value for the Umbraco back-office path.
/// 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 { }
}

Expand Down
2 changes: 1 addition & 1 deletion tools/Umbraco.JsonSchema/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
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; }
}
4 changes: 0 additions & 4 deletions tools/Umbraco.JsonSchema/Program.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
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());
});
66 changes: 33 additions & 33 deletions tools/Umbraco.JsonSchema/UmbracoCmsSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,81 @@

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>
/// Configuration of Umbraco CMS.
/// </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; }
}
}
23 changes: 12 additions & 11 deletions tools/Umbraco.JsonSchema/UmbracoJsonSchemaGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using NJsonSchema.Generation;

/// <inheritdoc />
public class UmbracoJsonSchemaGenerator : JsonSchemaGenerator
internal class UmbracoJsonSchemaGenerator : JsonSchemaGenerator
{
/// <summary>
/// Initializes a new instance of the <see cref="UmbracoJsonSchemaGenerator" /> class.
Expand All @@ -19,11 +19,8 @@ public UmbracoJsonSchemaGenerator()
ReflectionService = new UmbracoSystemTextJsonReflectionService(),
SerializerOptions = new JsonSerializerOptions()
{
Converters =
{
new JsonStringEnumConverter()
},
WriteIndented = true,
Converters = { new JsonStringEnumConverter() },
IgnoreReadOnlyProperties = true,
},
})
{ }
Expand All @@ -34,16 +31,20 @@ private class UmbracoSystemTextJsonReflectionService : SystemTextJsonReflectionS
/// <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
foreach (ContextualPropertyInfo property in contextualType.Properties)
if (settings.SerializerOptions.IgnoreReadOnlyProperties)
{
if (property.CanWrite is false)
// Remove read-only properties (because this is not implemented by the base class)
foreach (ContextualPropertyInfo property in contextualType.Properties)
{
string propertyName = GetPropertyName(property, settings);
if (property.CanWrite is false)
{
string propertyName = GetPropertyName(property, settings);

schema.Properties.Remove(propertyName);
schema.Properties.Remove(propertyName);
}
}
}
}
Expand Down
Loading