Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue / Enum String Response #52

Merged
merged 9 commits into from
Sep 15, 2023
Merged
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
15 changes: 15 additions & 0 deletions docs/release-notes/v0-2-0.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,18 @@
- `Database` feature is added with `InMemory`,`Sqlite` and `MySql`
implementations
- `Orm` feature is added with `NHibernate` implementation

## Library Upgrades

| Package | Old Version | New Version |
| ----------------------------------------- | ----------- | ----------- |
| FluentNHibernate | new | 3.2.1 |
| Microsoft.AspNetCore.Mvc.NewtonsoftJson | new | 6.0.20 |
| Microsoft.Extensions.Logging.Abstractions | new | 7.0.1 |
| Moq | new | 4.18.4 |
| MySql.Data | new | 8.1.0 |
| NHibernate | new | 5.4.4 |
| NUnit | new | 3.13.3 |
| Shouldly | new | 4.2.1 |
| Swashbuckle.AspNetCore | new | 6.5.0 |
| System.Data.SQLite | new | 1.0.118 |
10 changes: 9 additions & 1 deletion docs/release-notes/v0-3-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@
- `ShouldBeInserted` and `ShouldBeDeleted` extensions are now added for testing
entities
- _Swagger_ now renders `enum` as `string`
- `SingleById()` query now throws a `RecordNotFoundException` if no matching
- `SingleById()` query now throws a `RecordNotFoundException` if no matching
record is found

## Library Upgrades

| Package | Old Version | New Version |
| ----------------------------------------------- | ----------- | ----------- |
| Microsoft.Extensions.Configuration.Abstractions | new | 6.0.0 |
| Microsoft.Extensions.Configuration.Binder | new | 6.0.0 |
| StyleCop.Analyzers.Unstable | new | 1.2.0.507 |
8 changes: 4 additions & 4 deletions docs/release-notes/v0-3-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
- Transaction function or action allows task return
- Add logger services during unit testing
- Reset mocked singleton services were not setup after reset, fixed
- Added `HandledException` and `HandledExceptionHandler` for providing a
- Added `HandledException` and `HandledExceptionHandler` for providing a
better distinction in results for managed and unmanaged exceptions
- `AddHandler<T>()` extension for exception handling feature is now removed,
all `IExceptionHandler` implementations should be registered as singleton
- `AddHandler<T>()` extension for exception handling feature is now removed,
all `IExceptionHandler` implementations should be registered as singleton
services from features
- `RecordNotFoundException` now returns 404 status code
- Added an `ISetup.Returns()` extensions for ordered setup return values of
- Added an `ISetup.Returns()` extensions for ordered setup return values of
a mock service
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

<ItemGroup>
<PackageReference Include="FluentNHibernate" Version="3.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.20" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.22" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="MySql.Data" Version="8.1.0" />
<PackageReference Include="NHibernate" Version="5.4.4" />
<PackageReference Include="NHibernate" Version="5.4.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="System.Data.SQLite" Version="1.0.118" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Reflection;
using System.Runtime.Serialization;

namespace Do.Documentation.Default;
Expand All @@ -16,18 +15,18 @@ public void Apply(OpenApiSchema model, SchemaFilterContext context)
model.Format = null;
model.Enum.Clear();

foreach (string enumName in Enum.GetNames(context.Type))
foreach (var enumName in Enum.GetNames(context.Type))
{
MemberInfo? memberInfo = context.Type.GetMember(enumName).FirstOrDefault(m => m.DeclaringType == context.Type);
EnumMemberAttribute? enumMemberAttribute = memberInfo == null
var memberInfo = context.Type.GetMember(enumName).FirstOrDefault(m => m.DeclaringType == context.Type);
var enumMemberAttribute = memberInfo == null
? null
: memberInfo.GetCustomAttributes(typeof(EnumMemberAttribute), false).OfType<EnumMemberAttribute>().FirstOrDefault();

string label = enumMemberAttribute == null || string.IsNullOrWhiteSpace(enumMemberAttribute.Value)
var label = enumMemberAttribute == null || string.IsNullOrWhiteSpace(enumMemberAttribute.Value)
? enumName
: enumMemberAttribute.Value;

model.Enum.Add(new OpenApiString(label.ToLower()));
model.Enum.Add(new OpenApiString(label.ToLowerInvariant()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Do.Architecture;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using Swashbuckle.AspNetCore.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen;
using Swashbuckle.AspNetCore.SwaggerUI;
Expand Down Expand Up @@ -30,7 +32,11 @@ protected override PhaseContext GetContext(AddServices phase)
.Add(_swaggerGenOptions)
.OnDispose(() =>
{
services.AddControllers().AddNewtonsoftJson().AddApplicationParts(_applicationParts);
services.AddControllers()
.AddNewtonsoftJson(opts =>
opts.SerializerSettings.Converters.Add(new StringEnumConverter(new CamelCaseNamingStrategy()))
)
.AddApplicationParts(_applicationParts);
services.ConfigureSwaggerGen(config =>
{
config.SwaggerGeneratorOptions = _swaggerGenOptions.SwaggerGeneratorOptions;
Expand Down
11 changes: 11 additions & 0 deletions unreleased.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# Unreleased

## Improvements

- Enums in responses are returned as string now.

## Library Upgrades

| Package | Old Version | New Version |
| --------------------------------------- | ----------- | ----------- |
| Microsoft.AspNetCore.Mvc.NewtonsoftJson | 6.0.20 | 6.0.22 |
| NHibernate | 5.4.4 | 5.4.6 |