From f78d2cec12c6fb7a6d48b1f98286b1e31edad53e Mon Sep 17 00:00:00 2001 From: Turnerj Date: Sat, 20 Mar 2021 18:03:47 +1030 Subject: [PATCH 1/7] Optimizing schema parsing Primarily moves processing only to the branches that need it. Additionally makes the comment field not-nullable as we perform an initial check at the beginning of the Read method on SchemaPropertyJsonConverter. --- Tools/Schema.NET.Tool/Models/SchemaClass.cs | 4 +-- .../Models/SchemaEnumerationValue.cs | 4 +-- Tools/Schema.NET.Tool/Models/SchemaObject.cs | 7 ++-- .../Schema.NET.Tool/Models/SchemaProperty.cs | 4 +-- .../SchemaPropertyJsonConverter.cs | 34 ++++++++----------- 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/Tools/Schema.NET.Tool/Models/SchemaClass.cs b/Tools/Schema.NET.Tool/Models/SchemaClass.cs index 6dadaeaa..da667a26 100644 --- a/Tools/Schema.NET.Tool/Models/SchemaClass.cs +++ b/Tools/Schema.NET.Tool/Models/SchemaClass.cs @@ -9,8 +9,8 @@ public class SchemaClass : SchemaObject { private static readonly Uri EnumerationId = new("https://schema.org/Enumeration"); - public SchemaClass(Uri id, string label, string layer) - : base(id, label, layer) + public SchemaClass(string comment, Uri id, string label, string layer) + : base(comment, id, label, layer) { } diff --git a/Tools/Schema.NET.Tool/Models/SchemaEnumerationValue.cs b/Tools/Schema.NET.Tool/Models/SchemaEnumerationValue.cs index 4599b355..5875bcbe 100644 --- a/Tools/Schema.NET.Tool/Models/SchemaEnumerationValue.cs +++ b/Tools/Schema.NET.Tool/Models/SchemaEnumerationValue.cs @@ -4,8 +4,8 @@ namespace Schema.NET.Tool.Models public class SchemaEnumerationValue : SchemaObject { - public SchemaEnumerationValue(Uri id, string label, string layer) - : base(id, label, layer) + public SchemaEnumerationValue(string comment, Uri id, string label, string layer) + : base(comment, id, label, layer) { } } diff --git a/Tools/Schema.NET.Tool/Models/SchemaObject.cs b/Tools/Schema.NET.Tool/Models/SchemaObject.cs index 593a2ee2..32e848ae 100644 --- a/Tools/Schema.NET.Tool/Models/SchemaObject.cs +++ b/Tools/Schema.NET.Tool/Models/SchemaObject.cs @@ -30,21 +30,22 @@ public abstract class SchemaObject "PronounceableText", }; - public SchemaObject(Uri id, string label, string layer) + public SchemaObject(string comment, Uri id, string label, string layer) { + this.Comment = comment; this.Id = id; this.Label = label; this.Layer = layer; } + public string Comment { get; } + public Uri Id { get; } public string Label { get; } public string Layer { get; } - public string? Comment { get; set; } - public List Types { get; } = new List(); public virtual bool IsArchived => string.Equals(this.Layer, LayerName.Archived, StringComparison.OrdinalIgnoreCase); diff --git a/Tools/Schema.NET.Tool/Models/SchemaProperty.cs b/Tools/Schema.NET.Tool/Models/SchemaProperty.cs index 60d05190..9ee4d37a 100644 --- a/Tools/Schema.NET.Tool/Models/SchemaProperty.cs +++ b/Tools/Schema.NET.Tool/Models/SchemaProperty.cs @@ -5,8 +5,8 @@ namespace Schema.NET.Tool.Models public class SchemaProperty : SchemaObject { - public SchemaProperty(Uri id, string label, string layer) - : base(id, label, layer) + public SchemaProperty(string comment, Uri id, string label, string layer) + : base(comment, id, label, layer) { } diff --git a/Tools/Schema.NET.Tool/Repositories/SchemaPropertyJsonConverter.cs b/Tools/Schema.NET.Tool/Repositories/SchemaPropertyJsonConverter.cs index cf3ee0ee..bef7e7ba 100644 --- a/Tools/Schema.NET.Tool/Repositories/SchemaPropertyJsonConverter.cs +++ b/Tools/Schema.NET.Tool/Repositories/SchemaPropertyJsonConverter.cs @@ -51,20 +51,17 @@ public override void Write(Utf8JsonWriter writer, List value, Json var id = SchemaOrgUrl(idToken.GetString()!); var types = GetTokenValues(token, "@type").ToArray(); - string? comment; + string comment; if (commentToken.ValueKind == JsonValueKind.Object && commentToken.TryGetProperty("@value", out var commentValueToken)) { - comment = commentValueToken.GetString(); + comment = commentValueToken.GetString()!; } else { - comment = commentToken.GetString(); + comment = commentToken.GetString()!; } var label = GetLabel(token); - var domainIncludes = GetTokenValues(token, "schema:domainIncludes", "@id").Select(SchemaOrgUrl).ToArray(); - var rangeIncludes = GetTokenValues(token, "schema:rangeIncludes", "@id").Select(SchemaOrgUrl).ToArray(); - var subClassOf = GetTokenValues(token, "rdfs:subClassOf", "@id").Select(SchemaOrgUrl).ToArray(); var isPartOf = GetTokenValues(token, "schema:isPartOf", "@id").Select(s => new Uri(s)).FirstOrDefault(); var layer = LayerName.Core; @@ -75,32 +72,31 @@ public override void Write(Utf8JsonWriter writer, List value, Json if (types.Any(type => string.Equals(type, "rdfs:Class", StringComparison.Ordinal))) { - var schemaClass = new SchemaClass(id, label, layer) - { - Comment = comment, - }; + var schemaClass = new SchemaClass(comment, id, label, layer); + + var subClassOf = GetTokenValues(token, "rdfs:subClassOf", "@id").Select(SchemaOrgUrl); schemaClass.SubClassOfIds.AddRange(subClassOf); + schemaClass.Types.AddRange(types); return schemaClass; } else if (types.Any(type => string.Equals(type, "rdf:Property", StringComparison.Ordinal))) { - var schemaProperty = new SchemaProperty(id, label, layer) - { - Comment = comment, - }; + var schemaProperty = new SchemaProperty(comment, id, label, layer); + + var domainIncludes = GetTokenValues(token, "schema:domainIncludes", "@id").Select(SchemaOrgUrl); schemaProperty.DomainIncludes.AddRange(domainIncludes); + + var rangeIncludes = GetTokenValues(token, "schema:rangeIncludes", "@id").Select(SchemaOrgUrl); schemaProperty.RangeIncludes.AddRange(rangeIncludes); + schemaProperty.Types.AddRange(types); return schemaProperty; } else { - var schemaEnumerationValue = new SchemaEnumerationValue(id, label, layer) - { - Comment = comment, - }; - schemaEnumerationValue.Types.AddRange(types.Select(SchemaOrgUrl).Select(u => u.ToString()).ToArray()); + var schemaEnumerationValue = new SchemaEnumerationValue(comment, id, label, layer); + schemaEnumerationValue.Types.AddRange(types.Select(SchemaOrgUrl).Select(u => u.ToString())); return schemaEnumerationValue; } } From f9fd7b3ae3184331ec666cc99bd38232e9736294 Mon Sep 17 00:00:00 2001 From: Turnerj Date: Sat, 20 Mar 2021 18:05:52 +1030 Subject: [PATCH 2/7] Generator JSON parsing to be async and concurrent Technically the code was asynchronous before however the initial request would buffer internally, which we then serialize to a string and parse back out. Now we start processing the stream as we receive the content - improving performance and decreasing allocations. --- .../Schema.NET.Tool/Repositories/SchemaRepository.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Tools/Schema.NET.Tool/Repositories/SchemaRepository.cs b/Tools/Schema.NET.Tool/Repositories/SchemaRepository.cs index 7da11fe5..3ada507d 100644 --- a/Tools/Schema.NET.Tool/Repositories/SchemaRepository.cs +++ b/Tools/Schema.NET.Tool/Repositories/SchemaRepository.cs @@ -2,6 +2,7 @@ namespace Schema.NET.Tool.Repositories { using System; using System.Collections.Generic; + using System.IO; using System.Linq; using System.Net.Http; using System.Text.Json; @@ -35,23 +36,23 @@ public class SchemaRepository : ISchemaRepository public async Task?> GetSchemaObjectsAsync() { using (var response = await this.httpClient - .GetAsync(new Uri("/version/latest/schemaorg-all-https.jsonld", UriKind.Relative)) + .GetAsync(new Uri("/version/latest/schemaorg-all-https.jsonld", UriKind.Relative), HttpCompletionOption.ResponseHeadersRead) .ConfigureAwait(false)) { response.EnsureSuccessStatusCode(); - var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - return Deserialize>(json, new SchemaPropertyJsonConverter()); + var jsonStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); + return await DeserializeAsync>(jsonStream, new SchemaPropertyJsonConverter()).ConfigureAwait(false); } } - private static T? Deserialize(string json, JsonConverter converter) + private static async Task DeserializeAsync(Stream jsonStream, JsonConverter converter) { var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, }; options.Converters.Add(converter); - return JsonSerializer.Deserialize(json, options); + return await JsonSerializer.DeserializeAsync(jsonStream, options).ConfigureAwait(false); } } } From 5009475f074b770470188d2e99131be590e69d86 Mon Sep 17 00:00:00 2001 From: Turnerj Date: Sun, 21 Mar 2021 15:19:49 +1030 Subject: [PATCH 3/7] Remove Task.Run for source generator initialization --- .../Schema.NET.Tool/SchemaSourceGenerator.cs | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/Tools/Schema.NET.Tool/SchemaSourceGenerator.cs b/Tools/Schema.NET.Tool/SchemaSourceGenerator.cs index 41a646d2..68d41193 100644 --- a/Tools/Schema.NET.Tool/SchemaSourceGenerator.cs +++ b/Tools/Schema.NET.Tool/SchemaSourceGenerator.cs @@ -18,29 +18,24 @@ public class SchemaSourceGenerator : ISourceGenerator public void Initialize(GeneratorInitializationContext context) { -#pragma warning disable IDE0022 // Use expression body for methods - Task.Run(async () => + var schemaRepository = new SchemaRepository(new HttpClient() { - var schemaRepository = new SchemaRepository(new HttpClient() + BaseAddress = new Uri("https://schema.org"), + }); + var schemaService = new SchemaService( + new IClassOverride[] { - BaseAddress = new Uri("https://schema.org"), - }); - var schemaService = new SchemaService( - new IClassOverride[] - { new AddQueryInputPropertyToSearchAction(), new AddTextTypeToActionTarget(), new AddNumberTypeToMediaObjectHeightAndWidth(), new RenameEventProperty(), - }, - Array.Empty(), - schemaRepository, - false); + }, + Array.Empty(), + schemaRepository, + false); - this.SchemaObjects = await schemaService.GetObjectsAsync().ConfigureAwait(false); #pragma warning disable VSTHRD002 // Avoid problematic synchronous waits - }).GetAwaiter().GetResult(); -#pragma warning restore IDE0022 // Use expression body for methods + this.SchemaObjects = schemaService.GetObjectsAsync().GetAwaiter().GetResult(); #pragma warning restore VSTHRD002 // Avoid problematic synchronous waits } From ad0ac33e94fdc09fc01c68059e1a9f6569f4c0c6 Mon Sep 17 00:00:00 2001 From: Turnerj Date: Sun, 21 Mar 2021 16:55:07 +1030 Subject: [PATCH 4/7] Access schema objects through static property --- .../Schema.NET.Tool/SchemaSourceGenerator.cs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Tools/Schema.NET.Tool/SchemaSourceGenerator.cs b/Tools/Schema.NET.Tool/SchemaSourceGenerator.cs index 68d41193..ad56263f 100644 --- a/Tools/Schema.NET.Tool/SchemaSourceGenerator.cs +++ b/Tools/Schema.NET.Tool/SchemaSourceGenerator.cs @@ -4,7 +4,6 @@ namespace Schema.NET.Tool using System.Collections.Generic; using System.Linq; using System.Net.Http; - using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Schema.NET.Tool.CustomOverrides; using Schema.NET.Tool.GeneratorModels; @@ -14,7 +13,9 @@ namespace Schema.NET.Tool [Generator] public class SchemaSourceGenerator : ISourceGenerator { - private IEnumerable? SchemaObjects { get; set; } + private static readonly object SchemaLock = new(); + + private static IEnumerable? SchemaObjects { get; set; } public void Initialize(GeneratorInitializationContext context) { @@ -34,16 +35,25 @@ public void Initialize(GeneratorInitializationContext context) schemaRepository, false); + if (SchemaObjects is null) + { + lock (SchemaLock) + { + if (SchemaObjects is null) + { #pragma warning disable VSTHRD002 // Avoid problematic synchronous waits - this.SchemaObjects = schemaService.GetObjectsAsync().GetAwaiter().GetResult(); + SchemaObjects = schemaService.GetObjectsAsync().GetAwaiter().GetResult(); #pragma warning restore VSTHRD002 // Avoid problematic synchronous waits + } + } + } } public void Execute(GeneratorExecutionContext context) { - if (this.SchemaObjects is not null) + if (SchemaObjects is not null) { - foreach (var schemaObject in this.SchemaObjects) + foreach (var schemaObject in SchemaObjects) { var source = string.Empty; if (schemaObject is GeneratorSchemaClass schemaClass) From b7dabb3ffd2ad698fd88228af130ca6d1462e860 Mon Sep 17 00:00:00 2001 From: Turnerj Date: Sun, 21 Mar 2021 17:35:18 +1030 Subject: [PATCH 5/7] Fixed indenting --- Tools/Schema.NET.Tool/SchemaSourceGenerator.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tools/Schema.NET.Tool/SchemaSourceGenerator.cs b/Tools/Schema.NET.Tool/SchemaSourceGenerator.cs index ad56263f..d03747c8 100644 --- a/Tools/Schema.NET.Tool/SchemaSourceGenerator.cs +++ b/Tools/Schema.NET.Tool/SchemaSourceGenerator.cs @@ -26,10 +26,10 @@ public void Initialize(GeneratorInitializationContext context) var schemaService = new SchemaService( new IClassOverride[] { - new AddQueryInputPropertyToSearchAction(), - new AddTextTypeToActionTarget(), - new AddNumberTypeToMediaObjectHeightAndWidth(), - new RenameEventProperty(), + new AddQueryInputPropertyToSearchAction(), + new AddTextTypeToActionTarget(), + new AddNumberTypeToMediaObjectHeightAndWidth(), + new RenameEventProperty(), }, Array.Empty(), schemaRepository, From 09869ce9a1dd7f67122f4e1ea75874a409fe6e62 Mon Sep 17 00:00:00 2001 From: Turnerj Date: Sun, 21 Mar 2021 22:56:24 +1030 Subject: [PATCH 6/7] Updated constructor parameters for tool models Changes the order of constructor parameters and also pushes description/comment and "IsCombined" into constructors, making the properties immutable. --- .../GeneratorModels/GeneratorSchemaClass.cs | 18 +++++++------ .../GeneratorSchemaEnumeration.cs | 8 ++---- .../GeneratorSchemaEnumerationValue.cs | 5 ++-- .../GeneratorModels/GeneratorSchemaObject.cs | 5 +++- .../GeneratorSchemaProperty.cs | 10 +++---- Tools/Schema.NET.Tool/Models/SchemaClass.cs | 4 +-- .../Models/SchemaEnumerationValue.cs | 4 +-- Tools/Schema.NET.Tool/Models/SchemaObject.cs | 6 ++--- .../Schema.NET.Tool/Models/SchemaProperty.cs | 4 +-- .../SchemaPropertyJsonConverter.cs | 6 ++--- .../Schema.NET.Tool/Services/SchemaService.cs | 27 ++++--------------- 11 files changed, 40 insertions(+), 57 deletions(-) diff --git a/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaClass.cs b/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaClass.cs index 04e990a6..ce179151 100644 --- a/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaClass.cs +++ b/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaClass.cs @@ -7,15 +7,19 @@ namespace Schema.NET.Tool.GeneratorModels using Schema.NET.Tool.Constants; [DebuggerDisplay("{Name}")] -#pragma warning disable CA1716 // Identifiers should not match keywords public class GeneratorSchemaClass : GeneratorSchemaObject -#pragma warning restore CA1716 // Identifiers should not match keywords { public GeneratorSchemaClass(Uri id) - : base(string.Empty, string.Empty) => this.Id = id; + : this(layer: string.Empty, id, name: string.Empty, description: string.Empty) + { + } - public GeneratorSchemaClass(Uri id, string layer, string name) - : base(layer, name) => this.Id = id; + public GeneratorSchemaClass(string layer, Uri id, string name, string description, bool isCombined = false) + : base(layer, name, description) + { + this.Id = id; + this.IsCombined = isCombined; + } public IEnumerable Ancestors => EnumerableExtensions .Traverse(this, x => x.Parents) @@ -29,15 +33,13 @@ public GeneratorSchemaClass(Uri id, string layer, string name) .Traverse(this, x => x.Children) .Where(x => x != this); - public string? Description { get; set; } - public Uri Id { get; } public bool IsArchived => EnumerableExtensions .Traverse(this, x => x.Parents) .Any(x => string.Equals(x.Layer, LayerName.Archived, StringComparison.Ordinal)); - public bool IsCombined { get; set; } + public bool IsCombined { get; } public IEnumerable DeclaredProperties { diff --git a/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaEnumeration.cs b/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaEnumeration.cs index 14e90f9f..a16ddee6 100644 --- a/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaEnumeration.cs +++ b/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaEnumeration.cs @@ -4,17 +4,13 @@ namespace Schema.NET.Tool.GeneratorModels using System.Diagnostics; [DebuggerDisplay("{Name}")] -#pragma warning disable CA1724 // Identifiers should conflict with namespaces public class GeneratorSchemaEnumeration : GeneratorSchemaObject -#pragma warning restore CA1724 // Identifiers should conflict with namespaces { - public GeneratorSchemaEnumeration(string layer, string name) - : base(layer, name) + public GeneratorSchemaEnumeration(string layer, string name, string description) + : base(layer, name, description) { } - public string? Description { get; set; } - public List Values { get; } = new List(); } } diff --git a/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaEnumerationValue.cs b/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaEnumerationValue.cs index b83761a1..38985fdc 100644 --- a/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaEnumerationValue.cs +++ b/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaEnumerationValue.cs @@ -6,13 +6,14 @@ namespace Schema.NET.Tool.GeneratorModels [DebuggerDisplay("{Name}")] public class GeneratorSchemaEnumerationValue { - public GeneratorSchemaEnumerationValue(string name, Uri uri) + public GeneratorSchemaEnumerationValue(string name, Uri uri, string description) { this.Name = name; this.Uri = uri; + this.Description = description; } - public string? Description { get; set; } + public string Description { get; } public string Name { get; } diff --git a/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaObject.cs b/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaObject.cs index 8a6b7b7d..bb7ef5e1 100644 --- a/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaObject.cs +++ b/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaObject.cs @@ -2,12 +2,15 @@ namespace Schema.NET.Tool.GeneratorModels { public class GeneratorSchemaObject { - public GeneratorSchemaObject(string layer, string name) + public GeneratorSchemaObject(string layer, string name, string description) { this.Layer = layer; this.Name = name; + this.Description = description; } + public string Description { get; } + public string Layer { get; } public string Name { get; } diff --git a/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaProperty.cs b/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaProperty.cs index 7bc752fd..b1a8acf0 100644 --- a/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaProperty.cs +++ b/Tools/Schema.NET.Tool/GeneratorModels/GeneratorSchemaProperty.cs @@ -6,20 +6,19 @@ namespace Schema.NET.Tool.GeneratorModels using System.Linq; [DebuggerDisplay("{Name}")] -#pragma warning disable CA1716 // Identifiers should not match keywords public class GeneratorSchemaProperty -#pragma warning restore CA1716 // Identifiers should not match keywords { - public GeneratorSchemaProperty(GeneratorSchemaClass @class, string jsonName, string name) + public GeneratorSchemaProperty(GeneratorSchemaClass @class, string jsonName, string name, string description) { this.Class = @class; this.JsonName = jsonName; this.Name = name; + this.Description = description; } public GeneratorSchemaClass Class { get; } - public string? Description { get; set; } + public string Description { get; } public string JsonName { get; } @@ -66,9 +65,8 @@ public string JsonConverterType public GeneratorSchemaProperty Clone(GeneratorSchemaClass context) { - var property = new GeneratorSchemaProperty(context, this.JsonName, this.Name) + var property = new GeneratorSchemaProperty(context, this.JsonName, this.Name, this.Description) { - Description = this.Description, Order = this.Order, }; property.Types.AddRange(this.Types.Select(x => x.Clone())); diff --git a/Tools/Schema.NET.Tool/Models/SchemaClass.cs b/Tools/Schema.NET.Tool/Models/SchemaClass.cs index da667a26..f6921798 100644 --- a/Tools/Schema.NET.Tool/Models/SchemaClass.cs +++ b/Tools/Schema.NET.Tool/Models/SchemaClass.cs @@ -9,8 +9,8 @@ public class SchemaClass : SchemaObject { private static readonly Uri EnumerationId = new("https://schema.org/Enumeration"); - public SchemaClass(string comment, Uri id, string label, string layer) - : base(comment, id, label, layer) + public SchemaClass(string layer, Uri id, string label, string comment) + : base(layer, id, label, comment) { } diff --git a/Tools/Schema.NET.Tool/Models/SchemaEnumerationValue.cs b/Tools/Schema.NET.Tool/Models/SchemaEnumerationValue.cs index 5875bcbe..0af96dd5 100644 --- a/Tools/Schema.NET.Tool/Models/SchemaEnumerationValue.cs +++ b/Tools/Schema.NET.Tool/Models/SchemaEnumerationValue.cs @@ -4,8 +4,8 @@ namespace Schema.NET.Tool.Models public class SchemaEnumerationValue : SchemaObject { - public SchemaEnumerationValue(string comment, Uri id, string label, string layer) - : base(comment, id, label, layer) + public SchemaEnumerationValue(string layer, Uri id, string label, string comment) + : base(layer, id, label, comment) { } } diff --git a/Tools/Schema.NET.Tool/Models/SchemaObject.cs b/Tools/Schema.NET.Tool/Models/SchemaObject.cs index 32e848ae..1de5f995 100644 --- a/Tools/Schema.NET.Tool/Models/SchemaObject.cs +++ b/Tools/Schema.NET.Tool/Models/SchemaObject.cs @@ -30,12 +30,12 @@ public abstract class SchemaObject "PronounceableText", }; - public SchemaObject(string comment, Uri id, string label, string layer) + public SchemaObject(string layer, Uri id, string label, string comment) { - this.Comment = comment; + this.Layer = layer; this.Id = id; this.Label = label; - this.Layer = layer; + this.Comment = comment; } public string Comment { get; } diff --git a/Tools/Schema.NET.Tool/Models/SchemaProperty.cs b/Tools/Schema.NET.Tool/Models/SchemaProperty.cs index 9ee4d37a..a0b8a235 100644 --- a/Tools/Schema.NET.Tool/Models/SchemaProperty.cs +++ b/Tools/Schema.NET.Tool/Models/SchemaProperty.cs @@ -5,8 +5,8 @@ namespace Schema.NET.Tool.Models public class SchemaProperty : SchemaObject { - public SchemaProperty(string comment, Uri id, string label, string layer) - : base(comment, id, label, layer) + public SchemaProperty(string layer, Uri id, string label, string comment) + : base(layer, id, label, comment) { } diff --git a/Tools/Schema.NET.Tool/Repositories/SchemaPropertyJsonConverter.cs b/Tools/Schema.NET.Tool/Repositories/SchemaPropertyJsonConverter.cs index bef7e7ba..513d23a3 100644 --- a/Tools/Schema.NET.Tool/Repositories/SchemaPropertyJsonConverter.cs +++ b/Tools/Schema.NET.Tool/Repositories/SchemaPropertyJsonConverter.cs @@ -72,7 +72,7 @@ public override void Write(Utf8JsonWriter writer, List value, Json if (types.Any(type => string.Equals(type, "rdfs:Class", StringComparison.Ordinal))) { - var schemaClass = new SchemaClass(comment, id, label, layer); + var schemaClass = new SchemaClass(layer, id, label, comment); var subClassOf = GetTokenValues(token, "rdfs:subClassOf", "@id").Select(SchemaOrgUrl); schemaClass.SubClassOfIds.AddRange(subClassOf); @@ -82,7 +82,7 @@ public override void Write(Utf8JsonWriter writer, List value, Json } else if (types.Any(type => string.Equals(type, "rdf:Property", StringComparison.Ordinal))) { - var schemaProperty = new SchemaProperty(comment, id, label, layer); + var schemaProperty = new SchemaProperty(layer, id, label, comment); var domainIncludes = GetTokenValues(token, "schema:domainIncludes", "@id").Select(SchemaOrgUrl); schemaProperty.DomainIncludes.AddRange(domainIncludes); @@ -95,7 +95,7 @@ public override void Write(Utf8JsonWriter writer, List value, Json } else { - var schemaEnumerationValue = new SchemaEnumerationValue(comment, id, label, layer); + var schemaEnumerationValue = new SchemaEnumerationValue(layer, id, label, comment); schemaEnumerationValue.Types.AddRange(types.Select(SchemaOrgUrl).Select(u => u.ToString())); return schemaEnumerationValue; } diff --git a/Tools/Schema.NET.Tool/Services/SchemaService.cs b/Tools/Schema.NET.Tool/Services/SchemaService.cs index 65be5e0a..02b5f66d 100644 --- a/Tools/Schema.NET.Tool/Services/SchemaService.cs +++ b/Tools/Schema.NET.Tool/Services/SchemaService.cs @@ -124,11 +124,7 @@ private static void CombineMultipleParentsIntoCombinedClass(List x.Name).OrderBy(x => x)) + " for more information."; var parents = @class.Parents.SelectMany(x => x.Parents).GroupBy(x => x.Name).Select(x => x.First()).ToArray(); var layerName = @class.IsCombined ? @class.Layer : $"{@class.Layer}.combined"; - combinedClass = new GeneratorSchemaClass(new Uri($"https://CombinedClass/{className}"), layerName, className) - { - Description = classDescription, - IsCombined = true, - }; + combinedClass = new GeneratorSchemaClass(layerName, new Uri($"https://CombinedClass/{className}"), className, classDescription, isCombined: true); combinedClass.CombinationOf.AddRange(@class.Parents); combinedClass.Properties.AddRange(@class .Parents @@ -208,17 +204,10 @@ private static GeneratorSchemaEnumeration TranslateEnumeration( Models.SchemaClass schemaClass, IEnumerable schemaValues) { - var enumeration = new GeneratorSchemaEnumeration($"{schemaClass.Layer}.enumerations", schemaClass.Label) - { - Description = schemaClass.Comment, - }; + var enumeration = new GeneratorSchemaEnumeration($"{schemaClass.Layer}.enumerations", schemaClass.Label, schemaClass.Comment); enumeration.Values.AddRange(schemaValues .Where(x => x.Types.Contains(schemaClass.Id.ToString())) - .Select( - x => new GeneratorSchemaEnumerationValue(x.Label, x.Id) - { - Description = x.Comment, - }) + .Select(x => new GeneratorSchemaEnumerationValue(x.Label, x.Id, x.Comment)) .OrderBy(x => x.Name, new EnumerationValueComparer())); return enumeration; } @@ -232,10 +221,7 @@ private static GeneratorSchemaClass TranslateClass( bool includePending) { var className = StartsWithNumber.IsMatch(schemaClass.Label) ? $"_{schemaClass.Label}" : schemaClass.Label; - var @class = new GeneratorSchemaClass(schemaClass.Id, schemaClass.Layer, className) - { - Description = schemaClass.Comment, - }; + var @class = new GeneratorSchemaClass(schemaClass.Layer, schemaClass.Id, className, schemaClass.Comment); @class.Parents.AddRange(schemaClass.SubClassOfIds .Where(id => knownSchemaClasses.Contains(id)) @@ -245,10 +231,7 @@ private static GeneratorSchemaClass TranslateClass( .Select(x => { var propertyName = GetPropertyName(x.Label); - var property = new GeneratorSchemaProperty(@class, CamelCase(propertyName), propertyName) - { - Description = x.Comment, - }; + var property = new GeneratorSchemaProperty(@class, CamelCase(propertyName), propertyName, x.Comment); property.Types.AddRange(x.RangeIncludes .Where(id => { From a0a27766a1bfa719fb6f1866b8d0ebafd4533fc1 Mon Sep 17 00:00:00 2001 From: Turnerj Date: Sun, 21 Mar 2021 23:01:26 +1030 Subject: [PATCH 7/7] Updated constructor calls for overrides --- .../CustomOverrides/AddQueryInputPropertyToSearchAction.cs | 5 +---- Tools/Schema.NET.Tool/CustomOverrides/RenameEventProperty.cs | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Tools/Schema.NET.Tool/CustomOverrides/AddQueryInputPropertyToSearchAction.cs b/Tools/Schema.NET.Tool/CustomOverrides/AddQueryInputPropertyToSearchAction.cs index 02e8bbc5..278047be 100644 --- a/Tools/Schema.NET.Tool/CustomOverrides/AddQueryInputPropertyToSearchAction.cs +++ b/Tools/Schema.NET.Tool/CustomOverrides/AddQueryInputPropertyToSearchAction.cs @@ -23,10 +23,7 @@ public void Override(GeneratorSchemaClass c) throw new ArgumentNullException(nameof(c)); } - var property = new GeneratorSchemaProperty(c, "query-input", "QueryInput") - { - Description = "Gets or sets the query input search parameter.", - }; + var property = new GeneratorSchemaProperty(c, "query-input", "QueryInput", "Gets or sets the query input search parameter."); property.Types.AddRange( new List() { diff --git a/Tools/Schema.NET.Tool/CustomOverrides/RenameEventProperty.cs b/Tools/Schema.NET.Tool/CustomOverrides/RenameEventProperty.cs index 97810173..1232b5e3 100644 --- a/Tools/Schema.NET.Tool/CustomOverrides/RenameEventProperty.cs +++ b/Tools/Schema.NET.Tool/CustomOverrides/RenameEventProperty.cs @@ -28,9 +28,8 @@ public void Override(GeneratorSchemaClass c) .First(x => string.Equals(x.Name, "Event", StringComparison.OrdinalIgnoreCase)); c.Properties.Remove(eventProperty); - var updatedProperty = new GeneratorSchemaProperty(c, eventProperty.JsonName, "Events") + var updatedProperty = new GeneratorSchemaProperty(c, eventProperty.JsonName, "Events", eventProperty.Description) { - Description = eventProperty.Description, Order = eventProperty.Order, }; updatedProperty.Types.AddRange(eventProperty.Types);