From 4e2f2bc844a63a32e420e130c12bbab03beb2ee6 Mon Sep 17 00:00:00 2001 From: Ivan Date: Thu, 9 May 2019 01:24:46 +0300 Subject: [PATCH 1/3] Add tests for UrlAttribute, PhoneAttribute, EmailAddressAttribute (#963) --- .../Generation/AnnotationsGenerationTests.cs | 69 +++++-------------- 1 file changed, 18 insertions(+), 51 deletions(-) diff --git a/src/NJsonSchema.Tests/Generation/AnnotationsGenerationTests.cs b/src/NJsonSchema.Tests/Generation/AnnotationsGenerationTests.cs index 4abc05ec9..fe823539c 100644 --- a/src/NJsonSchema.Tests/Generation/AnnotationsGenerationTests.cs +++ b/src/NJsonSchema.Tests/Generation/AnnotationsGenerationTests.cs @@ -341,64 +341,31 @@ public class DataTypeAttributeClass [DataType(DataType.Url)] public string Url { get; set; } -#if !LEGACY - [DataType(DataType.Upload)] - public string Upload { get; set; } -#endif - } - - [Fact] - public async Task When_DataTypeAttribute_is_DateTime_then_the_format_property_is_datetime() - { - var schema = await JsonSchema4.FromTypeAsync(); - var property = schema.Properties["DateTime"]; - - Assert.Equal("date-time", property.Format); - } + [EmailAddress] // should be equivalent to [DataType(DataType.EmailAddress)] + public string EmailAddress2 { get; set; } - [Fact] - public async Task When_DataTypeAttribute_is_Date_then_the_format_property_is_date() - { - var schema = await JsonSchema4.FromTypeAsync(); - var property = schema.Properties["Date"]; + [Phone] // should be equivalent to [DataType(DataType.PhoneNumber)] + public string PhoneNumber2 { get; set; } - Assert.Equal("date", property.Format); + [Url] // should be equivalent to [DataType(DataType.Url)] + public string Url2 { get; set; } } - [Fact] - public async Task When_DataTypeAttribute_is_Time_then_the_format_property_is_time() - { - var schema = await JsonSchema4.FromTypeAsync(); - var property = schema.Properties["Time"]; - - Assert.Equal("time", property.Format); - } - - [Fact] - public async Task When_DataTypeAttribute_is_EmailAddress_then_the_format_property_is_email() - { - var schema = await JsonSchema4.FromTypeAsync(); - var property = schema.Properties["EmailAddress"]; - - Assert.Equal("email", property.Format); - } - - [Fact] - public async Task When_DataTypeAttribute_is_PhoneNumber_then_the_format_property_is_phone() - { - var schema = await JsonSchema4.FromTypeAsync(); - var property = schema.Properties["PhoneNumber"]; - - Assert.Equal("phone", property.Format); - } - - [Fact] - public async Task When_DataTypeAttribute_is_Url_then_the_format_property_is_uri() + [Theory] + [InlineData(nameof(DataTypeAttributeClass.EmailAddress), "email")] + [InlineData(nameof(DataTypeAttributeClass.PhoneNumber), "phone")] + [InlineData(nameof(DataTypeAttributeClass.DateTime), "date-time")] + [InlineData(nameof(DataTypeAttributeClass.Time), "time")] + [InlineData(nameof(DataTypeAttributeClass.Url), "uri")] + [InlineData(nameof(DataTypeAttributeClass.EmailAddress2), "email")] + [InlineData(nameof(DataTypeAttributeClass.PhoneNumber2), "phone")] + [InlineData(nameof(DataTypeAttributeClass.Url2), "uri")] + public async Task When_DataTypeAttribute_is_set_then_the_format_property_should_come_from_the_attribute(string propertyName, string expectedFormat) { var schema = await JsonSchema4.FromTypeAsync(); - var property = schema.Properties["Url"]; + var property = schema.Properties[propertyName]; - Assert.Equal("uri", property.Format); + Assert.Equal(expectedFormat, property.Format); } [JsonSchemaIgnore] From 521519b482a71a9bd70cf13ea46c4a77fea4f73b Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Thu, 16 May 2019 07:17:16 +0200 Subject: [PATCH 2/3] Remove CodeArtifactCollection, add CodeArtifactCategory --- .../GeneralGeneratorTests.cs | 4 +- .../CSharpGenerator.cs | 26 +++++------ .../ClassOrderTests.cs | 14 +++--- .../TypeScriptGenerator.cs | 45 +++++++++++-------- .../CodeArtifact.cs | 36 +++++++++------ .../CodeArtifactCategory.cs | 26 +++++++++++ ...ollection.cs => CodeArtifactExtensions.cs} | 29 ++++-------- .../GeneratorBase.cs | 16 +++---- 8 files changed, 114 insertions(+), 82 deletions(-) create mode 100644 src/NJsonSchema.CodeGeneration/CodeArtifactCategory.cs rename src/NJsonSchema.CodeGeneration/{CodeArtifactCollection.cs => CodeArtifactExtensions.cs} (74%) diff --git a/src/NJsonSchema.CodeGeneration.CSharp.Tests/GeneralGeneratorTests.cs b/src/NJsonSchema.CodeGeneration.CSharp.Tests/GeneralGeneratorTests.cs index 94f0789ff..ce55b8580 100644 --- a/src/NJsonSchema.CodeGeneration.CSharp.Tests/GeneralGeneratorTests.cs +++ b/src/NJsonSchema.CodeGeneration.CSharp.Tests/GeneralGeneratorTests.cs @@ -1724,8 +1724,8 @@ public void When_schema_has_negative_value_of_enum_it_is_generated_in_CSharp_and var types = generator.GenerateTypes(schema, "MyEnum"); //// Assert - Assert.Contains("_1 = 1", types.Artifacts.First().Code); - Assert.Contains("__1 = -1", types.Artifacts.First().Code); + Assert.Contains("_1 = 1", types.First().Code); + Assert.Contains("__1 = -1", types.First().Code); } private static void AssertCompile(string code) diff --git a/src/NJsonSchema.CodeGeneration.CSharp/CSharpGenerator.cs b/src/NJsonSchema.CodeGeneration.CSharp/CSharpGenerator.cs index ed11fe620..4895dbf87 100644 --- a/src/NJsonSchema.CodeGeneration.CSharp/CSharpGenerator.cs +++ b/src/NJsonSchema.CodeGeneration.CSharp/CSharpGenerator.cs @@ -37,7 +37,7 @@ public CSharpGenerator(object rootObject, CSharpGeneratorSettings settings) /// The root object to search for all JSON Schemas. /// The generator settings. /// The resolver. - public CSharpGenerator(object rootObject, CSharpGeneratorSettings settings, CSharpTypeResolver resolver) + public CSharpGenerator(object rootObject, CSharpGeneratorSettings settings, CSharpTypeResolver resolver) : base(rootObject, resolver, settings) { _resolver = resolver; @@ -48,40 +48,40 @@ public CSharpGenerator(object rootObject, CSharpGeneratorSettings settings, CSha public CSharpGeneratorSettings Settings { get; } /// - public override CodeArtifactCollection GenerateTypes() + public override IEnumerable GenerateTypes() { - var collection = base.GenerateTypes(); - var results = new List(); + var baseArtifacts = base.GenerateTypes(); + var artifacts = new List(); - if (collection.Artifacts.Any(r => r.Code.Contains("JsonInheritanceConverter"))) + if (baseArtifacts.Any(r => r.Code.Contains("JsonInheritanceConverter"))) { if (Settings.ExcludedTypeNames?.Contains("JsonInheritanceAttribute") != true) { var template = Settings.TemplateFactory.CreateTemplate("CSharp", "JsonInheritanceAttribute", new TemplateModelBase()); - results.Add(new CodeArtifact("JsonInheritanceAttribute", CodeArtifactType.Class, CodeArtifactLanguage.CSharp, template)); + artifacts.Add(new CodeArtifact("JsonInheritanceAttribute", CodeArtifactType.Class, CodeArtifactLanguage.CSharp, CodeArtifactCategory.Utility, template)); } if (Settings.ExcludedTypeNames?.Contains("JsonInheritanceConverter") != true) { var template = Settings.TemplateFactory.CreateTemplate("CSharp", "JsonInheritanceConverter", new TemplateModelBase()); - results.Add(new CodeArtifact("JsonInheritanceConverter", CodeArtifactType.Class, CodeArtifactLanguage.CSharp, template)); + artifacts.Add(new CodeArtifact("JsonInheritanceConverter", CodeArtifactType.Class, CodeArtifactLanguage.CSharp, CodeArtifactCategory.Utility, template)); } } - if (collection.Artifacts.Any(r => r.Code.Contains("DateFormatConverter"))) + if (baseArtifacts.Any(r => r.Code.Contains("DateFormatConverter"))) { if (Settings.ExcludedTypeNames?.Contains("DateFormatConverter") != true) { var template = Settings.TemplateFactory.CreateTemplate("CSharp", "DateFormatConverter", new TemplateModelBase()); - results.Add(new CodeArtifact("DateFormatConverter", CodeArtifactType.Class, CodeArtifactLanguage.CSharp, template)); + artifacts.Add(new CodeArtifact("DateFormatConverter", CodeArtifactType.Class, CodeArtifactLanguage.CSharp, CodeArtifactCategory.Utility, template)); } } - return new CodeArtifactCollection(collection.Artifacts.Concat(results), collection.ExtensionCode); + return baseArtifacts.Concat(artifacts); } /// - protected override string GenerateFile(CodeArtifactCollection artifactCollection) + protected override string GenerateFile(IEnumerable artifactCollection) { var model = new FileTemplateModel { @@ -114,7 +114,7 @@ private CodeArtifact GenerateClass(JsonSchema4 schema, string typeName) RenamePropertyWithSameNameAsClass(typeName, model.Properties); var template = Settings.TemplateFactory.CreateTemplate("CSharp", "Class", model); - return new CodeArtifact(typeName, model.BaseClassName, CodeArtifactType.Class, CodeArtifactLanguage.CSharp, template); + return new CodeArtifact(typeName, model.BaseClassName, CodeArtifactType.Class, CodeArtifactLanguage.CSharp, CodeArtifactCategory.Dto, template); } private void RenamePropertyWithSameNameAsClass(string typeName, IEnumerable properties) @@ -134,7 +134,7 @@ private CodeArtifact GenerateEnum(JsonSchema4 schema, string typeName) { var model = new EnumTemplateModel(typeName, schema, Settings); var template = Settings.TemplateFactory.CreateTemplate("CSharp", "Enum", model); - return new CodeArtifact(typeName, CodeArtifactType.Enum, CodeArtifactLanguage.CSharp, template); + return new CodeArtifact(typeName, CodeArtifactType.Enum, CodeArtifactLanguage.CSharp, CodeArtifactCategory.Dto, template); } } } diff --git a/src/NJsonSchema.CodeGeneration.TypeScript.Tests/ClassOrderTests.cs b/src/NJsonSchema.CodeGeneration.TypeScript.Tests/ClassOrderTests.cs index 141e0b9d7..3f3295881 100644 --- a/src/NJsonSchema.CodeGeneration.TypeScript.Tests/ClassOrderTests.cs +++ b/src/NJsonSchema.CodeGeneration.TypeScript.Tests/ClassOrderTests.cs @@ -12,16 +12,16 @@ public void When_class_order_is_wrong_then_classes_are_correctly_reordered() //// Arrange var classes = new List { - new CodeArtifact("Car", CodeArtifactType.Class, CodeArtifactLanguage.CSharp), - new CodeArtifact("Apple", "List", CodeArtifactType.Class, CodeArtifactLanguage.CSharp), - new CodeArtifact("Professor", "Teacher", CodeArtifactType.Class, CodeArtifactLanguage.CSharp), - new CodeArtifact("Teacher", "Person[]", CodeArtifactType.Class, CodeArtifactLanguage.CSharp), - new CodeArtifact("Fruit", CodeArtifactType.Class, CodeArtifactLanguage.CSharp), - new CodeArtifact("Person", CodeArtifactType.Class, CodeArtifactLanguage.CSharp) + new CodeArtifact("Car", CodeArtifactType.Class, CodeArtifactLanguage.CSharp, CodeArtifactCategory.Undefined, ""), + new CodeArtifact("Apple", "List", CodeArtifactType.Class, CodeArtifactLanguage.CSharp, CodeArtifactCategory.Undefined, ""), + new CodeArtifact("Professor", "Teacher", CodeArtifactType.Class, CodeArtifactLanguage.CSharp, CodeArtifactCategory.Undefined, ""), + new CodeArtifact("Teacher", "Person[]", CodeArtifactType.Class, CodeArtifactLanguage.CSharp, CodeArtifactCategory.Undefined, ""), + new CodeArtifact("Fruit", CodeArtifactType.Class, CodeArtifactLanguage.CSharp, CodeArtifactCategory.Undefined, ""), + new CodeArtifact("Person", CodeArtifactType.Class, CodeArtifactLanguage.CSharp, CodeArtifactCategory.Undefined, "") }; //// Act - classes = CodeArtifactCollection.OrderByBaseDependency(classes).ToList(); + classes = classes.OrderByBaseDependency().ToList(); var order = string.Join(", ", classes.Select(c => c.TypeName)); //// Assert diff --git a/src/NJsonSchema.CodeGeneration.TypeScript/TypeScriptGenerator.cs b/src/NJsonSchema.CodeGeneration.TypeScript/TypeScriptGenerator.cs index ba8571789..00d702a1c 100644 --- a/src/NJsonSchema.CodeGeneration.TypeScript/TypeScriptGenerator.cs +++ b/src/NJsonSchema.CodeGeneration.TypeScript/TypeScriptGenerator.cs @@ -10,6 +10,7 @@ using NJsonSchema.CodeGeneration.TypeScript.Models; using System.Linq; using NJsonSchema.CodeGeneration.Models; +using System.Collections.Generic; namespace NJsonSchema.CodeGeneration.TypeScript { @@ -17,6 +18,7 @@ namespace NJsonSchema.CodeGeneration.TypeScript public class TypeScriptGenerator : GeneratorBase { private readonly TypeScriptTypeResolver _resolver; + private TypeScriptExtensionCode _extensionCode; /// Initializes a new instance of the class. /// The schema. @@ -49,19 +51,20 @@ public TypeScriptGenerator(object rootObject, TypeScriptGeneratorSettings settin /// Generates all types from the resolver with extension code from the settings. /// The code. - public override CodeArtifactCollection GenerateTypes() + public override IEnumerable GenerateTypes() { - return GenerateTypes(new TypeScriptExtensionCode(Settings.ExtensionCode, Settings.ExtendedClasses)); + _extensionCode = _extensionCode ?? + new TypeScriptExtensionCode(Settings.ExtensionCode, Settings.ExtendedClasses); + + return GenerateTypes(_extensionCode); } /// Generates all types from the resolver with the given extension code. /// The code. - public CodeArtifactCollection GenerateTypes(ExtensionCode extensionCode) + public IEnumerable GenerateTypes(TypeScriptExtensionCode extensionCode) { - var collection = base.GenerateTypes(); - var artifacts = collection.Artifacts.ToList(); - - foreach (var artifact in collection.Artifacts) + var artifacts = base.GenerateTypes(); + foreach (var artifact in artifacts) { if (extensionCode?.ExtensionClasses.ContainsKey(artifact.TypeName) == true) { @@ -69,40 +72,46 @@ public CodeArtifactCollection GenerateTypes(ExtensionCode extensionCode) var index = classCode.IndexOf("constructor(", StringComparison.Ordinal); if (index != -1) - artifact.Code = classCode.Insert(index, extensionCode.GetExtensionClassBody(artifact.TypeName).Trim() + "\n\n "); + { + var code = classCode.Insert(index, extensionCode.GetExtensionClassBody(artifact.TypeName).Trim() + "\n\n "); + yield return new CodeArtifact(artifact.TypeName, artifact.Type, artifact.Language, artifact.Category, code); + } else { index = classCode.IndexOf("class", StringComparison.Ordinal); index = classCode.IndexOf("{", index, StringComparison.Ordinal) + 1; - artifact.Code = classCode.Insert(index, "\n " + extensionCode.GetExtensionClassBody(artifact.TypeName).Trim() + "\n"); + var code = classCode.Insert(index, "\n " + extensionCode.GetExtensionClassBody(artifact.TypeName).Trim() + "\n"); + yield return new CodeArtifact(artifact.TypeName, artifact.Type, artifact.Language, artifact.Category, code); } } + else + { + yield return artifact; + } } if (artifacts.Any(r => r.Code.Contains("formatDate("))) { var template = Settings.TemplateFactory.CreateTemplate("TypeScript", "File.FormatDate", new TemplateModelBase()); - artifacts.Add(new CodeArtifact("formatDate", CodeArtifactType.Function, CodeArtifactLanguage.CSharp, template)); + yield return new CodeArtifact("formatDate", CodeArtifactType.Function, CodeArtifactLanguage.CSharp, CodeArtifactCategory.Utility, template); } if (Settings.HandleReferences) { var template = Settings.TemplateFactory.CreateTemplate("TypeScript", "File.ReferenceHandling", new TemplateModelBase()); - artifacts.Add(new CodeArtifact("jsonParse", CodeArtifactType.Function, CodeArtifactLanguage.CSharp, template)); + yield return new CodeArtifact("jsonParse", CodeArtifactType.Function, CodeArtifactLanguage.CSharp, CodeArtifactCategory.Utility, template); } - - return new CodeArtifactCollection(artifacts, extensionCode); } /// Generates the file. /// The file contents. - protected override string GenerateFile(CodeArtifactCollection artifactCollection) + protected override string GenerateFile(IEnumerable artifacts) { var model = new FileTemplateModel(Settings) { - Types = artifactCollection.Concatenate(), - ExtensionCode = (TypeScriptExtensionCode)artifactCollection.ExtensionCode + Types = artifacts.Concatenate(), + ExtensionCode = _extensionCode }; var template = Settings.TemplateFactory.CreateTemplate("TypeScript", "File", model); @@ -121,7 +130,7 @@ protected override CodeArtifact GenerateType(JsonSchema4 schema, string typeName { var model = new EnumTemplateModel(typeName, schema, Settings); var template = Settings.TemplateFactory.CreateTemplate("TypeScript", "Enum", model); - return new CodeArtifact(typeName, CodeArtifactType.Enum, CodeArtifactLanguage.TypeScript, template); + return new CodeArtifact(typeName, CodeArtifactType.Enum, CodeArtifactLanguage.TypeScript, CodeArtifactCategory.Dto, template); } else { @@ -132,7 +141,7 @@ protected override CodeArtifact GenerateType(JsonSchema4 schema, string typeName ? CodeArtifactType.Interface : CodeArtifactType.Class; - return new CodeArtifact(typeName, model.BaseClass, type, CodeArtifactLanguage.TypeScript, template); + return new CodeArtifact(typeName, model.BaseClass, type, CodeArtifactLanguage.TypeScript, CodeArtifactCategory.Dto, template); } } } diff --git a/src/NJsonSchema.CodeGeneration/CodeArtifact.cs b/src/NJsonSchema.CodeGeneration/CodeArtifact.cs index 5aec76ab0..e92e71a42 100644 --- a/src/NJsonSchema.CodeGeneration/CodeArtifact.cs +++ b/src/NJsonSchema.CodeGeneration/CodeArtifact.cs @@ -17,29 +17,33 @@ public class CodeArtifact /// The type name. /// The artifact type. /// The artifact language. - public CodeArtifact(string typeName, CodeArtifactType type, CodeArtifactLanguage language) - : this(typeName, null, type, language, null) + /// The category. + /// The code. + public CodeArtifact(string typeName, CodeArtifactType type, CodeArtifactLanguage language, CodeArtifactCategory category, string code) + : this(typeName, null, type, language, category, code) { } /// Initializes a new instance of the class. /// The type name. - /// The base type name (e.g. base class). /// The artifact type. /// The artifact language. - public CodeArtifact(string typeName, string baseTypeName, CodeArtifactType type, CodeArtifactLanguage language) - : this(typeName, baseTypeName, type, language, null) + /// The category. + /// The template to render the code. + public CodeArtifact(string typeName, CodeArtifactType type, CodeArtifactLanguage language, CodeArtifactCategory category, ITemplate template) + : this(typeName, null, type, language, category, template?.Render()) { - BaseTypeName = baseTypeName; } /// Initializes a new instance of the class. /// The type name. + /// The base type name (e.g. base class). /// The artifact type. /// The artifact language. + /// The category. /// The template to render the code. - public CodeArtifact(string typeName, CodeArtifactType type, CodeArtifactLanguage language, ITemplate template) - : this(typeName, null, type, language, template) + public CodeArtifact(string typeName, string baseTypeName, CodeArtifactType type, CodeArtifactLanguage language, CodeArtifactCategory category, ITemplate template) + : this(typeName, baseTypeName, type, language, category, template?.Render()) { } @@ -48,8 +52,9 @@ public CodeArtifact(string typeName, CodeArtifactType type, CodeArtifactLanguage /// The base type name (e.g. base class). /// The artifact type. /// The artifact language. - /// The template to render the code. - public CodeArtifact(string typeName, string baseTypeName, CodeArtifactType type, CodeArtifactLanguage language, ITemplate template) + /// The category. + /// The code. + public CodeArtifact(string typeName, string baseTypeName, CodeArtifactType type, CodeArtifactLanguage language, CodeArtifactCategory category, string code) { if (typeName == baseTypeName) { @@ -61,8 +66,8 @@ public CodeArtifact(string typeName, string baseTypeName, CodeArtifactType type, Type = type; Language = language; - - Code = template?.Render(); + Category = category; + Code = code; } /// Gets the type name. @@ -77,7 +82,10 @@ public CodeArtifact(string typeName, string baseTypeName, CodeArtifactType type, /// Get the artifact language. public CodeArtifactLanguage Language { get; } - /// Gets or sets the generated code. - public string Code { get; set; } + /// Gets the category. + public CodeArtifactCategory Category { get; } + + /// Gets the generated code. + public string Code { get; } } } \ No newline at end of file diff --git a/src/NJsonSchema.CodeGeneration/CodeArtifactCategory.cs b/src/NJsonSchema.CodeGeneration/CodeArtifactCategory.cs new file mode 100644 index 000000000..061dafdce --- /dev/null +++ b/src/NJsonSchema.CodeGeneration/CodeArtifactCategory.cs @@ -0,0 +1,26 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) Rico Suter. All rights reserved. +// +// https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md +// Rico Suter, mail@rsuter.com +//----------------------------------------------------------------------- + +namespace NJsonSchema.CodeGeneration +{ + /// The code artifact category. + public enum CodeArtifactCategory + { + /// Undefined. + Undefined, + + /// Client. + Client, + + /// DTO. + Dto, + + /// Utility. + Utility + } +} \ No newline at end of file diff --git a/src/NJsonSchema.CodeGeneration/CodeArtifactCollection.cs b/src/NJsonSchema.CodeGeneration/CodeArtifactExtensions.cs similarity index 74% rename from src/NJsonSchema.CodeGeneration/CodeArtifactCollection.cs rename to src/NJsonSchema.CodeGeneration/CodeArtifactExtensions.cs index 291926f3f..2c1d5c7ca 100644 --- a/src/NJsonSchema.CodeGeneration/CodeArtifactCollection.cs +++ b/src/NJsonSchema.CodeGeneration/CodeArtifactExtensions.cs @@ -12,35 +12,20 @@ namespace NJsonSchema.CodeGeneration { - /// - public class CodeArtifactCollection + /// Code artifact extensions. + public static class CodeArtifactExtensions { - /// Initializes a new instance of the class. - /// The artifacts. - /// The extension code. - public CodeArtifactCollection(IEnumerable artifacts, ExtensionCode extensionCode) - { - Artifacts = OrderByBaseDependency(artifacts); - ExtensionCode = extensionCode; - } - - /// Gets the artifacts. - public IEnumerable Artifacts { get; } - - /// Gets the extension code. - public ExtensionCode ExtensionCode { get; } - /// Concatenates the results. /// The result. - public string Concatenate() + public static string Concatenate(this IEnumerable artifacts) { - return ConversionUtilities.TrimWhiteSpaces(string.Join("\n\n", Artifacts.Select(p => p.Code))); + return ConversionUtilities.TrimWhiteSpaces(string.Join("\n\n", artifacts.Select(p => p.Code))); } /// Reorders the results so that base classes are always before child classes. /// The results. /// The reordered results. - public static IEnumerable OrderByBaseDependency(IEnumerable results) + public static IEnumerable OrderByBaseDependency(this IEnumerable results) { var newResults = new List(results); foreach (var result in newResults.ToArray()) @@ -70,11 +55,15 @@ public static IEnumerable OrderByBaseDependency(IEnumerable", m => m.Groups[1].Value); diff --git a/src/NJsonSchema.CodeGeneration/GeneratorBase.cs b/src/NJsonSchema.CodeGeneration/GeneratorBase.cs index 8130555a7..6b09edbca 100644 --- a/src/NJsonSchema.CodeGeneration/GeneratorBase.cs +++ b/src/NJsonSchema.CodeGeneration/GeneratorBase.cs @@ -52,7 +52,7 @@ public string GenerateFile() /// The schema /// The type name hint. /// The code. - public CodeArtifactCollection GenerateTypes(JsonSchema4 schema, string typeNameHint) + public IEnumerable GenerateTypes(JsonSchema4 schema, string typeNameHint) { _resolver.Resolve(schema, false, typeNameHint); // register root type return GenerateTypes(); @@ -62,13 +62,13 @@ public CodeArtifactCollection GenerateTypes(JsonSchema4 schema, string typeNameH /// The code public string GenerateFile(JsonSchema4 schema, string typeNameHint) { - var collection = GenerateTypes(schema, typeNameHint); - return GenerateFile(collection); + var artifacts = GenerateTypes(schema, typeNameHint); + return GenerateFile(artifacts); } /// Generates all types from the resolver. /// The code. - public virtual CodeArtifactCollection GenerateTypes() + public virtual IEnumerable GenerateTypes() { var processedTypes = new List(); var types = new Dictionary(); @@ -82,15 +82,15 @@ public virtual CodeArtifactCollection GenerateTypes() } } - var artifacts = types.Values.Where(p => - !_settings.ExcludedTypeNames.Contains(p.TypeName)); + var artifacts = types.Values + .Where(p => !_settings.ExcludedTypeNames.Contains(p.TypeName)); - return new CodeArtifactCollection(artifacts, null); + return artifacts; } /// Generates the the whole file containing all needed types. /// The code - protected abstract string GenerateFile(CodeArtifactCollection artifactCollection); + protected abstract string GenerateFile(IEnumerable artifacts); /// Generates the type. /// The schema. From 7a02d5fd32b41188e04dc7c37ef188b6aaaf70ec Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Thu, 16 May 2019 07:18:38 +0200 Subject: [PATCH 3/3] v9.14.0 --- .../NJsonSchema.CodeGeneration.CSharp.csproj | 2 +- .../NJsonSchema.CodeGeneration.TypeScript.csproj | 2 +- .../NJsonSchema.CodeGeneration.csproj | 2 +- src/NJsonSchema.Yaml/NJsonSchema.Yaml.csproj | 2 +- src/NJsonSchema/NJsonSchema.csproj | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/NJsonSchema.CodeGeneration.CSharp/NJsonSchema.CodeGeneration.CSharp.csproj b/src/NJsonSchema.CodeGeneration.CSharp/NJsonSchema.CodeGeneration.CSharp.csproj index e3b9ce4c5..0dbcb19b3 100644 --- a/src/NJsonSchema.CodeGeneration.CSharp/NJsonSchema.CodeGeneration.CSharp.csproj +++ b/src/NJsonSchema.CodeGeneration.CSharp/NJsonSchema.CodeGeneration.CSharp.csproj @@ -2,7 +2,7 @@ netstandard1.3;netstandard2.0;net451 JSON Schema reader, generator and validator for .NET - 9.13.37 + 9.14.0 json schema validation generator .net Copyright © Rico Suter, 2018 https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md diff --git a/src/NJsonSchema.CodeGeneration.TypeScript/NJsonSchema.CodeGeneration.TypeScript.csproj b/src/NJsonSchema.CodeGeneration.TypeScript/NJsonSchema.CodeGeneration.TypeScript.csproj index b03e78b22..de2c66efc 100644 --- a/src/NJsonSchema.CodeGeneration.TypeScript/NJsonSchema.CodeGeneration.TypeScript.csproj +++ b/src/NJsonSchema.CodeGeneration.TypeScript/NJsonSchema.CodeGeneration.TypeScript.csproj @@ -2,7 +2,7 @@ netstandard1.3;netstandard2.0;net451 JSON Schema reader, generator and validator for .NET - 9.13.37 + 9.14.0 json schema validation generator .net Copyright © Rico Suter, 2018 https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md diff --git a/src/NJsonSchema.CodeGeneration/NJsonSchema.CodeGeneration.csproj b/src/NJsonSchema.CodeGeneration/NJsonSchema.CodeGeneration.csproj index 97e9acf8d..ffc7af615 100644 --- a/src/NJsonSchema.CodeGeneration/NJsonSchema.CodeGeneration.csproj +++ b/src/NJsonSchema.CodeGeneration/NJsonSchema.CodeGeneration.csproj @@ -2,7 +2,7 @@ netstandard1.3;netstandard2.0;net451 JSON Schema reader, generator and validator for .NET - 9.13.37 + 9.14.0 json schema validation generator .net Copyright © Rico Suter, 2018 https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md diff --git a/src/NJsonSchema.Yaml/NJsonSchema.Yaml.csproj b/src/NJsonSchema.Yaml/NJsonSchema.Yaml.csproj index 0142ee72c..e744a19c1 100644 --- a/src/NJsonSchema.Yaml/NJsonSchema.Yaml.csproj +++ b/src/NJsonSchema.Yaml/NJsonSchema.Yaml.csproj @@ -2,7 +2,7 @@ netstandard1.3;netstandard2.0;net45 JSON Schema reader, generator and validator for .NET - 9.13.37 + 9.14.0 json schema validation generator .net Copyright © Rico Suter, 2018 https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md diff --git a/src/NJsonSchema/NJsonSchema.csproj b/src/NJsonSchema/NJsonSchema.csproj index f2363aaca..696fd4023 100644 --- a/src/NJsonSchema/NJsonSchema.csproj +++ b/src/NJsonSchema/NJsonSchema.csproj @@ -2,7 +2,7 @@ netstandard1.0;netstandard2.0;net40;net45 JSON Schema reader, generator and validator for .NET - 9.13.37 + 9.14.0 json schema validation generator .net Copyright © Rico Suter, 2018 https://github.com/rsuter/NJsonSchema/blob/master/LICENSE.md