Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ branches:
- feature
- support
- hotfix
next-version: "4.0"
next-version: "5.0"

5 changes: 0 additions & 5 deletions Solutions/Menes.Abstractions/GlobalSuppressions.cs

This file was deleted.

9 changes: 2 additions & 7 deletions Solutions/Menes.Abstractions/Menes.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Corvus.ContentHandling" Version="3.0.0" />
<PackageReference Include="Corvus.ContentHandling" Version="4.0.0-system-text-json.22" />
<PackageReference Include="Corvus.Extensions" Version="1.1.10" />
<PackageReference Include="Corvus.Extensions.Newtonsoft.Json" Version="3.0.0" />
<PackageReference Include="Corvus.Monitoring.Instrumentation.Abstractions" Version="1.3.2" />
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.4">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -27,11 +26,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.4.5" />
<PackageReference Include="Nullable" Version="1.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Interactive" Version="[4.1.*,)" />
<PackageReference Include="System.Interactive" Version="4.1.1" />
<PackageReference Include="System.Text.Encodings.Web" Version="[4.7.*,)" />
<PackageReference Include="Tavis.UriTemplates" Version="1.1.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Menes.Converters
{
using System.Text.Json;

using Menes.Validation;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

/// <summary>
/// An OpenAPI converter for booleans.
Expand Down Expand Up @@ -37,20 +37,19 @@ public bool CanConvert(OpenApiSchema schema, bool ignoreFormat = false)
/// <inheritdoc/>
public object ConvertFrom(string content, OpenApiSchema schema)
{
JToken token = content;
bool result = (bool)token;
bool result = content == "true";

this.validator.ValidateAndThrow(result, schema);
this.validator.ValidateAndThrow(content, schema);

return result;
}

/// <inheritdoc/>
public string ConvertTo(object instance, OpenApiSchema schema)
{
string result = JsonConvert.SerializeObject(instance, this.configuration.Formatting, this.configuration.SerializerSettings);
string result = JsonSerializer.Serialize(instance, typeof(bool), this.configuration.SerializerOptions);

this.validator.ValidateAndThrow(JToken.Parse(result), schema);
this.validator.ValidateAndThrow(result, schema);

return result;
}
Expand Down
17 changes: 7 additions & 10 deletions Solutions/Menes.Abstractions/Menes/Converters/DateConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace Menes.Converters

using Microsoft.OpenApi.Models;

using Newtonsoft.Json.Linq;

/// <summary>
/// An OpenAPI converter for dates.
/// </summary>
Expand All @@ -37,10 +35,9 @@ public bool CanConvert(OpenApiSchema schema, bool ignoreFormat = false)
/// <inheritdoc/>
public object ConvertFrom(string content, OpenApiSchema schema)
{
JToken token = content;
var result = new DateTimeOffset(DateTime.SpecifyKind((DateTime)token, DateTimeKind.Utc));
var result = new DateTimeOffset(DateTime.SpecifyKind(DateTime.Parse(content), DateTimeKind.Utc));

this.validator.ValidateAndThrow(token, schema);
this.validator.ValidateAndThrow(content, schema);

return result;
}
Expand All @@ -50,15 +47,15 @@ public string ConvertTo(object instance, OpenApiSchema schema)
{
string result = instance switch
{
DateTimeOffset dt => $"\"{dt:yyyy-MM-dd}\"",
DateTime dt => $"\"{dt:yyyy-MM-dd}\"",
DateOnly dt => $"\"{dt:yyyy-MM-dd}\"",
DateTimeOffset dt => dt.ToString("yyyy-MM-dd"),
DateTime dt => dt.ToString("yyyy-MM-dd"),
DateOnly dt => dt.ToString("yyyy-MM-dd"),
_ => throw new ArgumentException($"Unsupported source type {instance.GetType().FullName}"),
};

this.validator.ValidateAndThrow(JToken.Parse(result), schema);
this.validator.ValidateAndThrow(result, schema);

return result;
return $"\"{result}\"";
}
}
}
13 changes: 6 additions & 7 deletions Solutions/Menes.Abstractions/Menes/Converters/DoubleConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Menes.Converters
{
using System.Text.Json;

using Menes.Validation;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

/// <summary>
/// An OpenAPI converter for doubles.
Expand Down Expand Up @@ -37,19 +37,18 @@ public bool CanConvert(OpenApiSchema schema, bool ignoreFormat = false)
/// <inheritdoc/>
public object ConvertFrom(string content, OpenApiSchema schema)
{
JToken token = content;
double result = (double)token;
double result = double.Parse(content);

this.validator.ValidateAndThrow(result, schema);
this.validator.ValidateAndThrow(content, schema);

return result;
}

/// <inheritdoc/>
public string ConvertTo(object instance, OpenApiSchema schema)
{
string result = JsonConvert.SerializeObject(instance, this.configuration.Formatting, this.configuration.SerializerSettings);
this.validator.ValidateAndThrow(JToken.Parse(result), schema);
string result = JsonSerializer.Serialize(instance, typeof(double), this.configuration.SerializerOptions);
this.validator.ValidateAndThrow(result, schema);

return result;
}
Expand Down
14 changes: 6 additions & 8 deletions Solutions/Menes.Abstractions/Menes/Converters/FloatConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Menes.Converters
{
using System.Text.Json;

using Menes.Validation;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

/// <summary>
/// An OpenAPI converter for floats.
Expand Down Expand Up @@ -37,21 +37,19 @@ public bool CanConvert(OpenApiSchema schema, bool ignoreFormat = false)
/// <inheritdoc/>
public object ConvertFrom(string content, OpenApiSchema schema)
{
JToken token = content;

float result = (float)token;
float result = float.Parse(content);

this.validator.ValidateAndThrow(result, schema);
this.validator.ValidateAndThrow(content, schema);

return result;
}

/// <inheritdoc/>
public string ConvertTo(object instance, OpenApiSchema schema)
{
string result = JsonConvert.SerializeObject(instance, this.configuration.Formatting, this.configuration.SerializerSettings);
string result = JsonSerializer.Serialize(instance, typeof(float), this.configuration.SerializerOptions);

this.validator.ValidateAndThrow(JToken.Parse(result), schema);
this.validator.ValidateAndThrow(result, schema);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
namespace Menes.Converters
{
using System;
using System.Text.Json;

using Menes.Validation;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

/// <summary>
/// An OpenAPI converter for int64 integers.
Expand Down Expand Up @@ -39,29 +38,27 @@ public bool CanConvert(OpenApiSchema schema, bool ignoreFormat = false)
/// <inheritdoc/>
public object ConvertFrom(string content, OpenApiSchema schema)
{
JToken token = content;

int result;
try
{
result = (int)token;
result = int.Parse(content);
}
catch (OverflowException)
{
throw new FormatException("Number was too large to parse as an Int32");
}

this.validator.ValidateAndThrow(result, schema);
this.validator.ValidateAndThrow(content, schema);

return result;
}

/// <inheritdoc/>
public string ConvertTo(object instance, OpenApiSchema schema)
{
string result = JsonConvert.SerializeObject(instance, this.configuration.Formatting, this.configuration.SerializerSettings);
string result = JsonSerializer.Serialize(instance, typeof(int), this.configuration.SerializerOptions);

this.validator.ValidateAndThrow(JToken.Parse(result), schema);
this.validator.ValidateAndThrow(result, schema);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
namespace Menes.Converters
{
using System;
using System.Text.Json;

using Menes.Validation;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

/// <summary>
/// An OpenAPI converter for int64 integers.
Expand Down Expand Up @@ -39,29 +38,27 @@ public bool CanConvert(OpenApiSchema schema, bool ignoreFormat = false)
/// <inheritdoc/>
public object ConvertFrom(string content, OpenApiSchema schema)
{
JToken token = content;

long result;
try
{
result = (long)token;
result = long.Parse(content);
}
catch (OverflowException)
{
throw new FormatException("Number was too large to parse as an Int64");
}

this.validator.ValidateAndThrow(result, schema);
this.validator.ValidateAndThrow(content, schema);

return result;
}

/// <inheritdoc/>
public string ConvertTo(object instance, OpenApiSchema schema)
{
string result = JsonConvert.SerializeObject(instance, this.configuration.Formatting, this.configuration.SerializerSettings);
string result = JsonSerializer.Serialize(instance, typeof(long), this.configuration.SerializerOptions);

this.validator.ValidateAndThrow(JToken.Parse(result), schema);
this.validator.ValidateAndThrow(result, schema);

return result;
}
Expand Down
14 changes: 7 additions & 7 deletions Solutions/Menes.Abstractions/Menes/Converters/ObjectConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace Menes.Converters
{
using System;
using System.Text.Json;

using Menes.Validation;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

/// <summary>
/// An OpenAPI converter for objects.
Expand Down Expand Up @@ -50,8 +50,8 @@ public object ConvertFrom(string content, OpenApiSchema schema)
string? type;
if (!string.IsNullOrEmpty(discriminator))
{
var jobj = JObject.Parse(content);
type = (string?)jobj[discriminator];
using var jdoc = JsonDocument.Parse(content);
type = jdoc.RootElement.TryGetProperty(discriminator, out JsonElement discriminatorProperty) ? discriminatorProperty.GetString() : null;

if (type == null)
{
Expand All @@ -77,17 +77,17 @@ public object ConvertFrom(string content, OpenApiSchema schema)
if (!this.serviceProvider.TryGetTypeFor(type, out targetType))
{
// We have no immediately obvious way to discriminate the type, so fall back on the serializers.
return JsonConvert.DeserializeObject(content, this.configuration.SerializerSettings!)!;
return JsonSerializer.Deserialize<object>(content, this.configuration.SerializerOptions)!;
}
}

return JsonConvert.DeserializeObject(content, targetType, this.configuration.SerializerSettings)!;
return JsonSerializer.Deserialize(content, targetType, this.configuration.SerializerOptions)!;
}

/// <inheritdoc/>
public string ConvertTo(object instance, OpenApiSchema schema)
{
string result = JsonConvert.SerializeObject(instance, this.configuration.Formatting, this.configuration.SerializerSettings);
string result = JsonSerializer.Serialize(instance, instance.GetType(), this.configuration.SerializerOptions);

this.validator.ValidateAndThrow(result, schema);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Menes.Converters
{
using System.Text.Json.Nodes;

using Menes.Validation;
using Microsoft.OpenApi.Models;

Expand Down Expand Up @@ -53,7 +55,7 @@ public string ConvertTo(object instance, OpenApiSchema schema)

this.validator.ValidateAndThrow(result, schema);

return '"' + result + '"';
return JsonValue.Create(result)!.ToJsonString();
}
}
}
Loading