Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…ashbuckle#1 added test for STJ serialization too.
  • Loading branch information
Havunen committed Feb 11, 2024
1 parent e980cda commit dcc7114
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ private OpenApiSchema CreatePrimitiveSchema(DataContract dataContract)
private OpenApiSchema CreateArraySchema(DataContract dataContract, SchemaRepository schemaRepository)
{
var hasUniqueItems = dataContract.UnderlyingType.IsConstructedFrom(typeof(ISet<>), out _)
|| dataContract.UnderlyingType.IsConstructedFrom(typeof(KeyedCollection<,>), out _);
|| dataContract.UnderlyingType.IsConstructedFrom(typeof(KeyedCollection<,>), out _)
|| dataContract.UnderlyingType.IsConstructedFrom(typeof(IReadOnlySet<>), out _);

return new OpenApiSchema
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ namespace DotSwashbuckle.AspNetCore.Newtonsoft.Test
{
public class NewtonsoftSchemaGeneratorTests
{
[Fact]
public void GenerateSchema_SetsUniqueItems_IfEnumerableTypeIsReadOnlySet()
{
var schema = Subject().GenerateSchema(typeof(IReadOnlySet<string>), new SchemaRepository());

Assert.Equal("array", schema.Type);
Assert.True(schema.UniqueItems);
}

[Theory]
[InlineData(typeof(IFormFile))]
[InlineData(typeof(FileResult))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ namespace DotSwashbuckle.AspNetCore.SwaggerGen.Test
{
public class JsonSerializerSchemaGeneratorTests
{
[Fact]
public void GenerateSchema_SetsUniqueItems_IfEnumerableTypeIsReadOnlySet()
{
var schema = Subject().GenerateSchema(typeof(IReadOnlySet<string>), new SchemaRepository());

Assert.Equal("array", schema.Type);
Assert.True(schema.UniqueItems);
}

[Theory]
[InlineData(typeof(IFormFile))]
[InlineData(typeof(FileResult))]
Expand Down

0 comments on commit dcc7114

Please sign in to comment.