mirror of
https://github.com/bitwarden/server
synced 2025-12-14 07:13:39 +00:00
Update Swashbuckle and improve generated OpenAPI files (#6066)
* Improve generated OpenAPI files * Nullable * Fmt * Correct powershell command * Fix name * Add some tests * Fmt * Switch to using json naming policy
This commit is contained in:
41
test/SharedWeb.Test/EnumSchemaFilterTest.cs
Normal file
41
test/SharedWeb.Test/EnumSchemaFilterTest.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Bit.SharedWeb.Swagger;
|
||||
using Microsoft.OpenApi.Any;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
namespace SharedWeb.Test;
|
||||
|
||||
public class EnumSchemaFilterTest
|
||||
{
|
||||
private enum TestEnum
|
||||
{
|
||||
First,
|
||||
Second,
|
||||
Third
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetsEnumVarNamesExtension()
|
||||
{
|
||||
var schema = new OpenApiSchema();
|
||||
var context = new SchemaFilterContext(typeof(TestEnum), null, null, null);
|
||||
var filter = new EnumSchemaFilter();
|
||||
filter.Apply(schema, context);
|
||||
|
||||
Assert.True(schema.Extensions.ContainsKey("x-enum-varnames"));
|
||||
var extensions = schema.Extensions["x-enum-varnames"] as OpenApiArray;
|
||||
Assert.NotNull(extensions);
|
||||
Assert.Equal(["First", "Second", "Third"], extensions.Select(x => ((OpenApiString)x).Value));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DoesNotSetExtensionForNonEnum()
|
||||
{
|
||||
var schema = new OpenApiSchema();
|
||||
var context = new SchemaFilterContext(typeof(string), null, null, null);
|
||||
var filter = new EnumSchemaFilter();
|
||||
filter.Apply(schema, context);
|
||||
|
||||
Assert.False(schema.Extensions.ContainsKey("x-enum-varnames"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user