Skip to content

Commit 8c68fbd

Browse files
committed
WIP - Upgrade swashbuckle
1 parent 26cab69 commit 8c68fbd

File tree

3 files changed

+22
-29
lines changed

3 files changed

+22
-29
lines changed

src/Exceptionless.Web/Exceptionless.Web.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<PackageReference Include="MiniValidation" Version="0.9.2" />
2020
<PackageReference Include="NEST.JsonNetSerializer" Version="7.17.5" />
2121
<PackageReference Include="OAuth2" Version="0.10.3" />
22-
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
22+
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.1" />
2323
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
2424
<PackageReference Include="Serilog.Enrichers.Span" Version="3.1.0" />
2525
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />

src/Exceptionless.Web/Startup.cs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
using Microsoft.AspNetCore.Mvc;
2323
using Microsoft.AspNetCore.Mvc.NewtonsoftJson;
2424
using Microsoft.Net.Http.Headers;
25-
using Microsoft.OpenApi.Models;
25+
using Microsoft.OpenApi;
2626
using Newtonsoft.Json;
2727
using Serilog;
2828
using Serilog.Events;
@@ -135,26 +135,12 @@ public void ConfigureServices(IServiceCollection services)
135135
Type = SecuritySchemeType.ApiKey
136136
});
137137

138-
c.AddSecurityRequirement(new OpenApiSecurityRequirement {
139-
{
140-
new OpenApiSecurityScheme {
141-
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Basic" }
142-
},
143-
Array.Empty<string>()
144-
},
145-
{
146-
new OpenApiSecurityScheme {
147-
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" }
148-
},
149-
Array.Empty<string>()
150-
},
151-
{
152-
new OpenApiSecurityScheme {
153-
Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Token" }
154-
},
155-
Array.Empty<string>()
156-
}
157-
});
138+
c.AddSecurityRequirement(document => new OpenApiSecurityRequirement
139+
{
140+
{ new OpenApiSecuritySchemeReference("Basic", document), [] },
141+
{ new OpenApiSecuritySchemeReference("Bearer", document), [] },
142+
{ new OpenApiSecuritySchemeReference("Token", document), [] }
143+
});
158144

159145
string xmlDocPath = Path.Combine(AppContext.BaseDirectory, "Exceptionless.Web.xml");
160146
if (File.Exists(xmlDocPath))
@@ -236,7 +222,7 @@ ApplicationException applicationException when applicationException.Message.Cont
236222
Predicate = hcr => hcr.Tags.Contains("Critical") || (options.RunJobsInProcess && hcr.Tags.Contains("AllJobs"))
237223
});
238224

239-
var readyTags = new List<string> { "Critical" };
225+
List<string> readyTags = ["Critical"];
240226
if (!options.EventSubmissionDisabled)
241227
readyTags.Add("Storage");
242228
app.UseReadyHealthChecks(readyTags.ToArray());

src/Exceptionless.Web/Utility/RequestBodyOperationFilter.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
using System.Text.Json.Nodes;
12
using Microsoft.AspNetCore.Mvc;
2-
using Microsoft.OpenApi.Any;
3-
using Microsoft.OpenApi.Models;
3+
using Microsoft.OpenApi;
44
using Swashbuckle.AspNetCore.SwaggerGen;
55

6-
public class RequestBodyContentAttribute : Attribute { }
6+
public class RequestBodyContentAttribute : Attribute
7+
{
8+
}
79

810
public class RequestBodyOperationFilter : IOperationFilter
911
{
@@ -17,12 +19,17 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context)
1719
if (consumesAttribute is null)
1820
return;
1921

20-
operation.RequestBody = new OpenApiRequestBody { Required = true };
22+
operation.RequestBody = new OpenApiRequestBody
23+
{
24+
Required = true,
25+
Content = new Dictionary<string, OpenApiMediaType>()
26+
};
27+
2128
foreach (string contentType in consumesAttribute.ContentTypes)
2229
{
23-
operation.RequestBody.Content.Add(contentType, new OpenApiMediaType
30+
operation.RequestBody.Content!.Add(contentType, new OpenApiMediaType
2431
{
25-
Schema = new OpenApiSchema { Type = "string", Example = new OpenApiString(String.Empty) }
32+
Schema = new OpenApiSchema { Type = JsonSchemaType.String, Example = JsonValue.Create(String.Empty) }
2633
});
2734
}
2835
}

0 commit comments

Comments
 (0)