Skip to content

Commit

Permalink
asyncapi#197 formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Senn Geerts authored and Senn Geerts committed Jul 11, 2024
1 parent 1b7087a commit 2c6e2d9
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 141 deletions.
14 changes: 7 additions & 7 deletions src/Saunter/AsyncApiOptions.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -90,10 +90,10 @@ public void AddOperationFilter<T>() 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(),
Expand All @@ -120,4 +120,4 @@ public class AsyncApiMiddlewareOptions
/// </summary>
public string UiTitle { get; set; } = "AsyncAPI";
}
}
}
14 changes: 7 additions & 7 deletions src/Saunter/AsyncApiSchema/v2/AsyncApiDocument.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,8 +15,8 @@ public class AsyncApiDocument : ICloneable
/// Specifies the AsyncAPI Specification version being used.
/// </summary>
[JsonProperty("asyncapi", NullValueHandling = NullValueHandling.Ignore)]
public string AsyncApi { get; } = "2.4.0";

public string AsyncApi { get; } = "2.4.0";

/// <summary>
/// Identifier of the application the AsyncAPI document is defining.
/// </summary>
Expand Down Expand Up @@ -105,4 +105,4 @@ object ICloneable.Clone()
return Clone();
}
}
}
}
10 changes: 5 additions & 5 deletions src/Saunter/AsyncApiServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -57,4 +57,4 @@ public static IServiceCollection ConfigureNamedAsyncApi(this IServiceCollection
return services;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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<MessageReference>();
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<MessageReference>();
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 { }
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -242,4 +242,4 @@ public class Dog : Pet
{
public string PackSize { get; set; }
}
}
}

0 comments on commit 2c6e2d9

Please sign in to comment.