From 2c6e2d987e3b9ab6690b461adc9fe5a39acde496 Mon Sep 17 00:00:00 2001 From: Senn Geerts Date: Thu, 11 Jul 2024 23:34:02 +0200 Subject: [PATCH] #197 formatting --- src/Saunter/AsyncApiOptions.cs | 14 +- .../AsyncApiSchema/v2/AsyncApiDocument.cs | 14 +- .../AsyncApiServiceCollectionExtensions.cs | 10 +- .../InterfaceAttributeTests.cs | 214 +++++++++--------- .../SchemaGeneration/SchemaGenerationTests.cs | 30 +-- 5 files changed, 141 insertions(+), 141 deletions(-) diff --git a/src/Saunter/AsyncApiOptions.cs b/src/Saunter/AsyncApiOptions.cs index cc64cc55..cdd410fb 100644 --- a/src/Saunter/AsyncApiOptions.cs +++ b/src/Saunter/AsyncApiOptions.cs @@ -1,13 +1,13 @@ using System; using System.Collections.Concurrent; -using System.Collections.Generic; - +using System.Collections.Generic; + using Newtonsoft.Json; using Newtonsoft.Json.Serialization; - + using NJsonSchema; using NJsonSchema.NewtonsoftJson.Generation; - + using Saunter.AsyncApiSchema.v2; using Saunter.Generation.Filters; using Saunter.Generation.SchemaGeneration; @@ -90,10 +90,10 @@ public void AddOperationFilter() where T : IOperationFilter public class AsyncApiSchemaOptions : NewtonsoftJsonSchemaGeneratorSettings { - public AsyncApiSchemaOptions() + public AsyncApiSchemaOptions() { SchemaType = SchemaType.JsonSchema; // AsyncAPI uses json-schema, see https://github.com/tehmantra/saunter/pull/103#issuecomment-893267360 - TypeNameGenerator = new CamelCaseTypeNameGenerator(); + TypeNameGenerator = new CamelCaseTypeNameGenerator(); SerializerSettings = new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver(), @@ -120,4 +120,4 @@ public class AsyncApiMiddlewareOptions /// public string UiTitle { get; set; } = "AsyncAPI"; } -} +} diff --git a/src/Saunter/AsyncApiSchema/v2/AsyncApiDocument.cs b/src/Saunter/AsyncApiSchema/v2/AsyncApiDocument.cs index ed38829a..a5604b64 100644 --- a/src/Saunter/AsyncApiSchema/v2/AsyncApiDocument.cs +++ b/src/Saunter/AsyncApiSchema/v2/AsyncApiDocument.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; -using System.Linq; - -using Newtonsoft.Json; - +using System.Linq; + +using Newtonsoft.Json; + using NJsonSchema.NewtonsoftJson.Converters; namespace Saunter.AsyncApiSchema.v2 @@ -15,8 +15,8 @@ public class AsyncApiDocument : ICloneable /// Specifies the AsyncAPI Specification version being used. /// [JsonProperty("asyncapi", NullValueHandling = NullValueHandling.Ignore)] - public string AsyncApi { get; } = "2.4.0"; - + public string AsyncApi { get; } = "2.4.0"; + /// /// Identifier of the application the AsyncAPI document is defining. /// @@ -105,4 +105,4 @@ object ICloneable.Clone() return Clone(); } } -} +} diff --git a/src/Saunter/AsyncApiServiceCollectionExtensions.cs b/src/Saunter/AsyncApiServiceCollectionExtensions.cs index 288001cb..cf2ac39c 100644 --- a/src/Saunter/AsyncApiServiceCollectionExtensions.cs +++ b/src/Saunter/AsyncApiServiceCollectionExtensions.cs @@ -1,8 +1,8 @@ -using System; - +using System; + using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; - +using Microsoft.Extensions.DependencyInjection.Extensions; + using Saunter.AsyncApiSchema.v2; using Saunter.Generation; using Saunter.Serialization; @@ -57,4 +57,4 @@ public static IServiceCollection ConfigureNamedAsyncApi(this IServiceCollection return services; } } -} +} diff --git a/test/Saunter.Tests/Generation/DocumentGeneratorTests/InterfaceAttributeTests.cs b/test/Saunter.Tests/Generation/DocumentGeneratorTests/InterfaceAttributeTests.cs index a5183890..f520bd10 100644 --- a/test/Saunter.Tests/Generation/DocumentGeneratorTests/InterfaceAttributeTests.cs +++ b/test/Saunter.Tests/Generation/DocumentGeneratorTests/InterfaceAttributeTests.cs @@ -1,107 +1,107 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Reflection; -using Saunter.AsyncApiSchema.v2; -using Saunter.Attributes; -using Saunter.Generation; -using Shouldly; -using Xunit; -using System.Linq; - -namespace Saunter.Tests.Generation.DocumentGeneratorTests -{ - public class InterfaceAttributeTests - { - [Theory] - [InlineData(typeof(IServiceEvents))] - [InlineData(typeof(ServiceEventsFromInterface))] - [InlineData(typeof(ServiceEventsFromAnnotatedInterface))] // Check that annotations are not inherited from the interface - public void NonAnnotatedTypesTest(Type type) - { - // Arrange - var options = new AsyncApiOptions(); - var documentGenerator = new DocumentGenerator(); - - // Act - var document = documentGenerator.GenerateDocument(new[] { type.GetTypeInfo() }, options, options.AsyncApi, ActivatorServiceProvider.Instance); - - // Assert - document.ShouldNotBeNull(); - document.Channels.Count.ShouldBe(0); - } - - [Theory] - [InlineData(typeof(IAnnotatedServiceEvents), "interface")] - [InlineData(typeof(AnnotatedServiceEventsFromInterface), "class")] - [InlineData(typeof(AnnotatedServiceEventsFromAnnotatedInterface), "class")] // Check that the actual type's annotation takes precedence of the inherited interface - public void AnnotatedTypesTest(Type type, string source) - { - // Arrange - var options = new AsyncApiOptions(); - var documentGenerator = new DocumentGenerator(); - - // Act - var document = documentGenerator.GenerateDocument(new[] { type.GetTypeInfo() }, options, options.AsyncApi, ActivatorServiceProvider.Instance); - - // Assert - document.ShouldNotBeNull(); - document.Channels.Count.ShouldBe(1); - - var channel = document.Channels.First(); - channel.Key.ShouldBe($"{source}.event"); - channel.Value.Description.ShouldBeNull(); - - var publish = channel.Value.Publish; - publish.ShouldNotBeNull(); - publish.OperationId.ShouldBe("PublishEvent"); - publish.Description.ShouldBe($"({source}) Subscribe to domains events about a tenant."); - - var messageRef = publish.Message.ShouldBeOfType(); - messageRef.Id.ShouldBe("tenantEvent"); - } - - [AsyncApi] - private interface IAnnotatedServiceEvents - { - [Channel("interface.event")] - [PublishOperation(typeof(TenantEvent), Description = "(interface) Subscribe to domains events about a tenant.")] - void PublishEvent(TenantEvent evt); - } - - private interface IServiceEvents - { - void PublishEvent(TenantEvent evt); - } - - private class ServiceEventsFromInterface : IServiceEvents - { - public void PublishEvent(TenantEvent evt) { } - } - - private class ServiceEventsFromAnnotatedInterface : IAnnotatedServiceEvents - { - public void PublishEvent(TenantEvent evt) { } - } - - [AsyncApi] - private class AnnotatedServiceEventsFromInterface : IAnnotatedServiceEvents - { - [Channel("class.event")] - [PublishOperation(typeof(TenantEvent), Description = "(class) Subscribe to domains events about a tenant.")] - public void PublishEvent(TenantEvent evt) { } - } - - [AsyncApi] - private class AnnotatedServiceEventsFromAnnotatedInterface : IAnnotatedServiceEvents - { - [Channel("class.event")] - [PublishOperation(typeof(TenantEvent), Description = "(class) Subscribe to domains events about a tenant.")] - public void PublishEvent(TenantEvent evt) { } - } - - private class TenantEvent { } - } -} +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Reflection; +using Saunter.AsyncApiSchema.v2; +using Saunter.Attributes; +using Saunter.Generation; +using Shouldly; +using Xunit; +using System.Linq; + +namespace Saunter.Tests.Generation.DocumentGeneratorTests +{ + public class InterfaceAttributeTests + { + [Theory] + [InlineData(typeof(IServiceEvents))] + [InlineData(typeof(ServiceEventsFromInterface))] + [InlineData(typeof(ServiceEventsFromAnnotatedInterface))] // Check that annotations are not inherited from the interface + public void NonAnnotatedTypesTest(Type type) + { + // Arrange + var options = new AsyncApiOptions(); + var documentGenerator = new DocumentGenerator(); + + // Act + var document = documentGenerator.GenerateDocument(new[] { type.GetTypeInfo() }, options, options.AsyncApi, ActivatorServiceProvider.Instance); + + // Assert + document.ShouldNotBeNull(); + document.Channels.Count.ShouldBe(0); + } + + [Theory] + [InlineData(typeof(IAnnotatedServiceEvents), "interface")] + [InlineData(typeof(AnnotatedServiceEventsFromInterface), "class")] + [InlineData(typeof(AnnotatedServiceEventsFromAnnotatedInterface), "class")] // Check that the actual type's annotation takes precedence of the inherited interface + public void AnnotatedTypesTest(Type type, string source) + { + // Arrange + var options = new AsyncApiOptions(); + var documentGenerator = new DocumentGenerator(); + + // Act + var document = documentGenerator.GenerateDocument(new[] { type.GetTypeInfo() }, options, options.AsyncApi, ActivatorServiceProvider.Instance); + + // Assert + document.ShouldNotBeNull(); + document.Channels.Count.ShouldBe(1); + + var channel = document.Channels.First(); + channel.Key.ShouldBe($"{source}.event"); + channel.Value.Description.ShouldBeNull(); + + var publish = channel.Value.Publish; + publish.ShouldNotBeNull(); + publish.OperationId.ShouldBe("PublishEvent"); + publish.Description.ShouldBe($"({source}) Subscribe to domains events about a tenant."); + + var messageRef = publish.Message.ShouldBeOfType(); + messageRef.Id.ShouldBe("tenantEvent"); + } + + [AsyncApi] + private interface IAnnotatedServiceEvents + { + [Channel("interface.event")] + [PublishOperation(typeof(TenantEvent), Description = "(interface) Subscribe to domains events about a tenant.")] + void PublishEvent(TenantEvent evt); + } + + private interface IServiceEvents + { + void PublishEvent(TenantEvent evt); + } + + private class ServiceEventsFromInterface : IServiceEvents + { + public void PublishEvent(TenantEvent evt) { } + } + + private class ServiceEventsFromAnnotatedInterface : IAnnotatedServiceEvents + { + public void PublishEvent(TenantEvent evt) { } + } + + [AsyncApi] + private class AnnotatedServiceEventsFromInterface : IAnnotatedServiceEvents + { + [Channel("class.event")] + [PublishOperation(typeof(TenantEvent), Description = "(class) Subscribe to domains events about a tenant.")] + public void PublishEvent(TenantEvent evt) { } + } + + [AsyncApi] + private class AnnotatedServiceEventsFromAnnotatedInterface : IAnnotatedServiceEvents + { + [Channel("class.event")] + [PublishOperation(typeof(TenantEvent), Description = "(class) Subscribe to domains events about a tenant.")] + public void PublishEvent(TenantEvent evt) { } + } + + private class TenantEvent { } + } +} diff --git a/test/Saunter.Tests/Generation/SchemaGeneration/SchemaGenerationTests.cs b/test/Saunter.Tests/Generation/SchemaGeneration/SchemaGenerationTests.cs index 41d11a8c..b836fa00 100644 --- a/test/Saunter.Tests/Generation/SchemaGeneration/SchemaGenerationTests.cs +++ b/test/Saunter.Tests/Generation/SchemaGeneration/SchemaGenerationTests.cs @@ -1,23 +1,23 @@ using System; using System.ComponentModel.DataAnnotations; using System.Linq; -using System.Runtime.Serialization; - +using System.Runtime.Serialization; + using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; - +using Newtonsoft.Json.Serialization; + using NJsonSchema; using NJsonSchema.Generation; -using NJsonSchema.NewtonsoftJson.Converters; - +using NJsonSchema.NewtonsoftJson.Converters; + using Saunter.AsyncApiSchema.v2; using Saunter.Generation.SchemaGeneration; -using Saunter.Tests.Utils; - -using Shouldly; - -using Xunit; - +using Saunter.Tests.Utils; + +using Shouldly; + +using Xunit; + using JsonInheritanceAttribute = NJsonSchema.NewtonsoftJson.Converters.JsonInheritanceAttribute; namespace Saunter.Tests.Generation.SchemaGeneration @@ -97,8 +97,8 @@ public void GenerateSchema_GenerateSchemaFromClassWithDiscriminator_GeneratesSch var schema = _schemaGenerator.Generate(type, _schemaResolver); - schema.ShouldNotBeNull(); - + schema.ShouldNotBeNull(); + _schemaResolver.Schemas.ShouldNotBeNull(); var petSchema = _schemaResolver.Schemas.FirstOrDefault(s => s.Id == "pet"); petSchema.Discriminator.ShouldBe("petType"); @@ -242,4 +242,4 @@ public class Dog : Pet { public string PackSize { get; set; } } -} +}