Skip to content

Commit 763e98f

Browse files
Merge branch 'master' into dotnet-vnext
2 parents 221a546 + f5cbec1 commit 763e98f

6 files changed

Lines changed: 32 additions & 10 deletions

File tree

src/Swashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/JsonSerializerDataContractResolver.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public DataContract GetDataContractForType(Type type)
6060
// This is a special case where we know the possible key values
6161
var enumValuesAsJson = keyType.GetEnumValues()
6262
.Cast<object>()
63-
.Select(value => JsonConverterFunc(value, keyType));
63+
.Select(value => JsonConverterFunc(value, keyType))
64+
.Distinct();
6465

6566
keys =
6667
enumValuesAsJson.Any(json => json.StartsWith('\"'))

test/Swashbuckle.AspNetCore.IntegrationTests/Swashbuckle.AspNetCore.IntegrationTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
</ItemGroup>
4848

4949
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net10.0'))">
50-
<PackageReference Update="Microsoft.AspNetCore.Mvc.Testing" VersionOverride="10.0.4" />
51-
<PackageReference Update="Microsoft.AspNetCore.TestHost" VersionOverride="10.0.4" />
50+
<PackageReference Update="Microsoft.AspNetCore.Mvc.Testing" VersionOverride="10.0.5" />
51+
<PackageReference Update="Microsoft.AspNetCore.TestHost" VersionOverride="10.0.5" />
5252
</ItemGroup>
5353

5454
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net11.0'))">

test/Swashbuckle.AspNetCore.SwaggerGen.Test/SchemaGenerator/JsonSerializerSchemaGeneratorTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,20 @@ public void GenerateSchema_HonorsEnumDictionaryKeys_StringEnumConverter()
12751275
Assert.Equal(typeof(IntEnum).GetEnumNames(), referenceSchema.Properties.Keys);
12761276
}
12771277

1278+
[Fact]
1279+
public void GenerateSchema_GeneratesDictionarySchema_IfEnumKeyHasDuplicateValues()
1280+
{
1281+
// Regression test for https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/2956
1282+
var subject = Subject(
1283+
configureSerializer: c => c.Converters.Add(new JsonStringEnumConverter()));
1284+
var schemaRepository = new SchemaRepository();
1285+
1286+
var schema = subject.GenerateSchema(typeof(Dictionary<IntEnumWithDuplicateValues, string>), schemaRepository);
1287+
1288+
Assert.Equal(JsonSchemaTypes.Object, schema.Type);
1289+
Assert.Equal(["Unknown", "PreferredName"], schema.Properties.Keys);
1290+
}
1291+
12781292
[Fact]
12791293
public void GenerateSchema_HonorsSerializerAttribute_StringEnumConverter()
12801294
{
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
11
namespace Swashbuckle.AspNetCore.TestSupport;
22

3-
public enum ByteEnum:byte
3+
public enum ByteEnum : byte
44
{
55
Value2 = 2,
66
Value4 = 4,
77
Value8 = 8,
88
}
99

10-
public enum ShortEnum:short
10+
public enum ShortEnum : short
1111
{
1212
Value2 = 2,
1313
Value4 = 4,
1414
Value8 = 8,
1515
}
1616

17-
public enum EmptyIntEnum:int
17+
public enum EmptyIntEnum : int
1818
{
1919
}
2020

21-
public enum IntEnum:int
21+
public enum IntEnum : int
2222
{
2323
Value2 = 2,
2424
Value4 = 4,
2525
Value8 = 8,
2626
}
2727

28-
public enum LongEnum:long
28+
public enum LongEnum : long
2929
{
3030
Value2 = 2,
3131
Value4 = 4,
3232
Value8 = 8,
3333
}
34+
35+
public enum IntEnumWithDuplicateValues : int
36+
{
37+
Unknown = 0,
38+
PreferredName = 1,
39+
OldNameForBackwardsCompatibility = PreferredName,
40+
}

test/WebSites/OAuth2Integration/OAuth2Integration.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</ItemGroup>
1515

1616
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
17-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" VersionOverride="10.0.4" />
17+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" VersionOverride="10.0.5" />
1818
</ItemGroup>
1919

2020
<ItemGroup Condition="'$(TargetFramework)' == 'net11.0'">

test/WebSites/TodoApp/TodoApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<ProjectReference Include="..\..\..\src\Swashbuckle.AspNetCore.SwaggerUI\Swashbuckle.AspNetCore.SwaggerUI.csproj" />
1515
</ItemGroup>
1616
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
17-
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" VersionOverride="10.0.4" />
17+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" VersionOverride="10.0.5" />
1818
</ItemGroup>
1919
<ItemGroup Condition="'$(TargetFramework)' == 'net11.0'">
2020
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" VersionOverride="11.0.0-preview.2.26159.112" />

0 commit comments

Comments
 (0)