Skip to content

Commit ee80ed2

Browse files
Fix document URL serialization (#3773)
Fix URLs not being serialized correctly if a custom `JsonSerializerOptions` is provided. See #3772 (comment).
1 parent 3d260bb commit ee80ed2

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,12 @@ private async Task RespondWithFile(HttpContext context, string fileName)
183183
private async Task RespondWithDocumentUrls(HttpContext context)
184184
{
185185
var response = context.Response;
186+
var urls = _options.ConfigObject.Urls ?? [];
186187

187-
string json = "[]";
188-
189-
if (_jsonSerializerOptions is null)
190-
{
191-
var l = new List<UrlDescriptor>(_options.ConfigObject.Urls);
192-
json = JsonSerializer.Serialize(l, SwaggerUIOptionsJsonContext.Default.ListUrlDescriptor);
193-
}
194-
195-
json ??= JsonSerializer.Serialize(_options.ConfigObject.Urls, _jsonSerializerOptions);
188+
string json =
189+
_jsonSerializerOptions is { } options ?
190+
JsonSerializer.Serialize(urls, options) :
191+
JsonSerializer.Serialize([.. urls], SwaggerUIOptionsJsonContext.Default.ListUrlDescriptor);
196192

197193
var etag = GetETag(json);
198194
var ifNoneMatch = context.Request.Headers.IfNoneMatch;

0 commit comments

Comments
 (0)