Skip to content

Commit

Permalink
Merge pull request #182 from zarusz/feature/179_latest_NJsonSchema
Browse files Browse the repository at this point in the history
Upgrade to NJsonSchema in version 11.0.0
  • Loading branch information
m-wild authored Jan 16, 2024
2 parents 02d631d + 2efd1c2 commit 5255a55
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
15 changes: 9 additions & 6 deletions src/Saunter/AsyncApiOptions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +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.Generation;
using NJsonSchema.NewtonsoftJson.Generation;

using Saunter.AsyncApiSchema.v2;
using Saunter.Generation.Filters;
using Saunter.Generation.SchemaGeneration;
Expand Down Expand Up @@ -85,13 +88,13 @@ public void AddOperationFilter<T>() where T : IOperationFilter
public AsyncApiSchemaOptions SchemaOptions { get; set; } = new AsyncApiSchemaOptions();
}

public class AsyncApiSchemaOptions : JsonSchemaGeneratorSettings
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();
SerializerSettings = new JsonSerializerSettings
TypeNameGenerator = new CamelCaseTypeNameGenerator();
SerializerSettings = new JsonSerializerSettings()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore,
Expand Down
12 changes: 7 additions & 5 deletions src/Saunter/AsyncApiSchema/v2/AsyncApiDocument.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using NJsonSchema.Converters;
using System.Linq;

using Newtonsoft.Json;

using NJsonSchema.NewtonsoftJson.Converters;

namespace Saunter.AsyncApiSchema.v2
{
Expand All @@ -13,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
10 changes: 6 additions & 4 deletions src/Saunter/AsyncApiServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +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 All @@ -14,7 +16,7 @@ public static class AsyncApiServiceCollectionExtensions
/// </summary>
/// <param name="services">The collection to add services to.</param>
/// <param name="setupAction">An action used to configure the AsyncAPI options.</param>
/// <returns>The service collection so additional calls can be chained.</returns>
/// <returns>The service collection so additional calls can b e chained.</returns>
public static IServiceCollection AddAsyncApiSchemaGeneration(this IServiceCollection services, Action<AsyncApiOptions> setupAction = null)
{
services.AddOptions();
Expand Down Expand Up @@ -48,7 +50,7 @@ public static IServiceCollection ConfigureNamedAsyncApi(this IServiceCollection
options.Middleware.UiBaseRoute = "/asyncapi/{document}/ui/";
}

var document = options.NamedApis.GetOrAdd(documentName, _ => new AsyncApiDocument() {DocumentName = documentName});
var document = options.NamedApis.GetOrAdd(documentName, _ => new AsyncApiDocument() { DocumentName = documentName });

setupAction(document);
});
Expand Down
3 changes: 2 additions & 1 deletion src/Saunter/Saunter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NJsonSchema" Version="10.9.0" />
<PackageReference Include="NJsonSchema" Version="11.0.0" />

<!-- Development Dependencies -->
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="NJsonSchema.NewtonsoftJson" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
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.Converters;
using NJsonSchema.Generation;
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 @@ -90,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

0 comments on commit 5255a55

Please sign in to comment.