Skip to content

Commit ad82fe8

Browse files
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
1 parent 767c417 commit ad82fe8

File tree

5 files changed

+48
-52
lines changed

5 files changed

+48
-52
lines changed

src/Umbraco.Core/Configuration/Models/GlobalSettings.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,12 @@ internal const string
7878
public int VersionCheckPeriod { get; set; } = StaticVersionCheckPeriod;
7979

8080
/// <summary>
81-
/// Gets or sets a value for the Umbraco back-office path.
81+
/// Gets or sets a value for the Umbraco back-office path.
8282
/// </summary>
83+
[Obsolete($"UmbracoPath is no longer configurable, use Constants.System.DefaultUmbracoPath instead. This property is scheduled for removal in a future version.")]
8384
public string UmbracoPath
8485
{
8586
get => Constants.System.DefaultUmbracoPath;
86-
[Obsolete($"{nameof(UmbracoPath)} is no longer configurable, this property setter is scheduled for removal in V12.")]
87-
// NOTE: When removing this, also clean up the hardcoded removal of UmbracoPath in Umbraco.JsonSchema
8887
set { }
8988
}
9089

tools/Umbraco.JsonSchema/Options.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
internal class Options
44
{
55
[Option("outputFile", Default = "appsettings-schema.Umbraco.Cms.json", HelpText = "Output file to save the generated JSON schema for Umbraco CMS.")]
6-
public string OutputFile { get; set; } = null!;
6+
public required string OutputFile { get; set; }
77
}

tools/Umbraco.JsonSchema/Program.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
using CommandLine;
2-
using Umbraco.Cms.Core.Configuration.Models;
32

43
await Parser.Default.ParseArguments<Options>(args).WithParsedAsync(async options =>
54
{
65
// Generate CMS schema
76
var jsonSchemaGenerator = new UmbracoJsonSchemaGenerator();
87
var jsonSchema = jsonSchemaGenerator.Generate(typeof(UmbracoCmsSchema));
98

10-
// TODO: When the UmbracoPath setter is removed from GlobalSettings (scheduled for V12), remove this line as well
11-
jsonSchema.Definitions[nameof(GlobalSettings)]?.Properties?.Remove(nameof(GlobalSettings.UmbracoPath));
12-
139
await File.WriteAllTextAsync(options.OutputFile, jsonSchema.ToJson());
1410
});

tools/Umbraco.JsonSchema/UmbracoCmsSchema.cs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,81 +3,81 @@
33

44
internal class UmbracoCmsSchema
55
{
6-
public UmbracoDefinition Umbraco { get; set; } = null!;
6+
public required UmbracoDefinition Umbraco { get; set; }
77

88
/// <summary>
99
/// Configuration container for all Umbraco products.
1010
/// </summary>
1111
public class UmbracoDefinition
1212
{
13-
public UmbracoCmsDefinition CMS { get; set; } = null!;
13+
public required UmbracoCmsDefinition CMS { get; set; }
1414
}
1515

1616
/// <summary>
1717
/// Configuration of Umbraco CMS.
1818
/// </summary>
1919
public class UmbracoCmsDefinition
2020
{
21-
public ContentSettings Content { get; set; } = null!;
21+
public required ContentSettings Content { get; set; }
2222

23-
public DeliveryApiSettings DeliveryApi { get; set; } = null!;
23+
public required DeliveryApiSettings DeliveryApi { get; set; }
2424

25-
public CoreDebugSettings Debug { get; set; } = null!;
25+
public required CoreDebugSettings Debug { get; set; }
2626

27-
public ExceptionFilterSettings ExceptionFilter { get; set; } = null!;
27+
public required ExceptionFilterSettings ExceptionFilter { get; set; }
2828

29-
public ModelsBuilderSettings ModelsBuilder { get; set; } = null!;
29+
public required ModelsBuilderSettings ModelsBuilder { get; set; }
3030

31-
public GlobalSettings Global { get; set; } = null!;
31+
public required GlobalSettings Global { get; set; }
3232

33-
public HealthChecksSettings HealthChecks { get; set; } = null!;
33+
public required HealthChecksSettings HealthChecks { get; set; }
3434

35-
public HostingSettings Hosting { get; set; } = null!;
35+
public required HostingSettings Hosting { get; set; }
3636

37-
public ImagingSettings Imaging { get; set; } = null!;
37+
public required ImagingSettings Imaging { get; set; }
3838

39-
public IndexCreatorSettings Examine { get; set; } = null!;
39+
public required IndexCreatorSettings Examine { get; set; }
4040

41-
public IndexingSettings Indexing { get; set; } = null!;
41+
public required IndexingSettings Indexing { get; set; }
4242

43-
public LoggingSettings Logging { get; set; } = null!;
43+
public required LoggingSettings Logging { get; set; }
4444

45-
public NuCacheSettings NuCache { get; set; } = null!;
45+
public required NuCacheSettings NuCache { get; set; }
4646

47-
public RequestHandlerSettings RequestHandler { get; set; } = null!;
47+
public required RequestHandlerSettings RequestHandler { get; set; }
4848

49-
public RuntimeSettings Runtime { get; set; } = null!;
49+
public required RuntimeSettings Runtime { get; set; }
5050

51-
public SecuritySettings Security { get; set; } = null!;
51+
public required SecuritySettings Security { get; set; }
5252

53-
public TypeFinderSettings TypeFinder { get; set; } = null!;
53+
public required TypeFinderSettings TypeFinder { get; set; }
5454

55-
public WebRoutingSettings WebRouting { get; set; } = null!;
55+
public required WebRoutingSettings WebRouting { get; set; }
5656

57-
public UmbracoPluginSettings Plugins { get; set; } = null!;
57+
public required UmbracoPluginSettings Plugins { get; set; }
5858

59-
public UnattendedSettings Unattended { get; set; } = null!;
59+
public required UnattendedSettings Unattended { get; set; }
6060

61-
public RichTextEditorSettings RichTextEditor { get; set; } = null!;
61+
public required RichTextEditorSettings RichTextEditor { get; set; }
6262

63-
public RuntimeMinificationSettings RuntimeMinification { get; set; } = null!;
63+
public required RuntimeMinificationSettings RuntimeMinification { get; set; }
6464

65-
public BasicAuthSettings BasicAuth { get; set; } = null!;
65+
public required BasicAuthSettings BasicAuth { get; set; }
6666

67-
public PackageMigrationSettings PackageMigration { get; set; } = null!;
67+
public required PackageMigrationSettings PackageMigration { get; set; }
6868

69-
public LegacyPasswordMigrationSettings LegacyPasswordMigration { get; set; } = null!;
69+
public required LegacyPasswordMigrationSettings LegacyPasswordMigration { get; set; }
7070

71-
public ContentDashboardSettings ContentDashboard { get; set; } = null!;
71+
public required ContentDashboardSettings ContentDashboard { get; set; }
7272

73-
public HelpPageSettings HelpPage { get; set; } = null!;
73+
public required HelpPageSettings HelpPage { get; set; }
7474

75-
public InstallDefaultDataSettings DefaultDataCreation { get; set; } = null!;
75+
public required InstallDefaultDataSettings DefaultDataCreation { get; set; }
7676

77-
public DataTypesSettings DataTypes { get; set; } = null!;
77+
public required DataTypesSettings DataTypes { get; set; }
7878

79-
public MarketplaceSettings Marketplace { get; set; } = null!;
79+
public required MarketplaceSettings Marketplace { get; set; }
8080

81-
public WebhookSettings Webhook { get; set; } = null!;
81+
public required WebhookSettings Webhook { get; set; }
8282
}
8383
}

tools/Umbraco.JsonSchema/UmbracoJsonSchemaGenerator.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using NJsonSchema.Generation;
66

77
/// <inheritdoc />
8-
public class UmbracoJsonSchemaGenerator : JsonSchemaGenerator
8+
internal class UmbracoJsonSchemaGenerator : JsonSchemaGenerator
99
{
1010
/// <summary>
1111
/// Initializes a new instance of the <see cref="UmbracoJsonSchemaGenerator" /> class.
@@ -19,11 +19,8 @@ public UmbracoJsonSchemaGenerator()
1919
ReflectionService = new UmbracoSystemTextJsonReflectionService(),
2020
SerializerOptions = new JsonSerializerOptions()
2121
{
22-
Converters =
23-
{
24-
new JsonStringEnumConverter()
25-
},
26-
WriteIndented = true,
22+
Converters = { new JsonStringEnumConverter() },
23+
IgnoreReadOnlyProperties = true,
2724
},
2825
})
2926
{ }
@@ -34,16 +31,20 @@ private class UmbracoSystemTextJsonReflectionService : SystemTextJsonReflectionS
3431
/// <inheritdoc />
3532
public override void GenerateProperties(JsonSchema schema, ContextualType contextualType, SystemTextJsonSchemaGeneratorSettings settings, JsonSchemaGenerator schemaGenerator, JsonSchemaResolver schemaResolver)
3633
{
34+
// Populate schema properties
3735
base.GenerateProperties(schema, contextualType, settings, schemaGenerator, schemaResolver);
3836

39-
// Remove read-only properties
40-
foreach (ContextualPropertyInfo property in contextualType.Properties)
37+
if (settings.SerializerOptions.IgnoreReadOnlyProperties)
4138
{
42-
if (property.CanWrite is false)
39+
// Remove read-only properties (because this is not implemented by the base class)
40+
foreach (ContextualPropertyInfo property in contextualType.Properties)
4341
{
44-
string propertyName = GetPropertyName(property, settings);
42+
if (property.CanWrite is false)
43+
{
44+
string propertyName = GetPropertyName(property, settings);
4545

46-
schema.Properties.Remove(propertyName);
46+
schema.Properties.Remove(propertyName);
47+
}
4748
}
4849
}
4950
}

0 commit comments

Comments
 (0)