Skip to content

Commit

Permalink
Fix interceptor JSON casing
Browse files Browse the repository at this point in the history
Fix property casing of Swagger UI interceptor function properties.
Resolves #2906.
  • Loading branch information
martincostello committed May 21, 2024
1 parent 432c417 commit d5cd28e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json.Serialization;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Swashbuckle.AspNetCore.SwaggerUI
{
Expand Down Expand Up @@ -262,6 +262,7 @@ public class InterceptorFunctions
/// Accepts one argument requestInterceptor(request) and must return the modified request, or a Promise that resolves to the modified request.
/// Ex: "function (req) { req.headers['MyCustomHeader'] = 'CustomValue'; return req; }"
/// </summary>
[JsonPropertyName("RequestInterceptorFunction")]
public string RequestInterceptorFunction { get; set; }

/// <summary>
Expand All @@ -270,6 +271,7 @@ public class InterceptorFunctions
/// Accepts one argument responseInterceptor(response) and must return the modified response, or a Promise that resolves to the modified response.
/// Ex: "function (res) { console.log(res); return res; }"
/// </summary>
[JsonPropertyName("ResponseInterceptorFunction")]
public string ResponseInterceptorFunction { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ public async Task IndexUrl_ReturnsCustomIndexHtml_IfConfigured()
Assert.Contains("Example.com", content);
}

[Fact]
public async Task IndexUrl_ReturnsInterceptors_IfConfigured()
{
var client = new TestSite(typeof(CustomUIConfig.Startup)).BuildClient();

var response = await client.GetAsync("/swagger/index.html");
var content = await response.Content.ReadAsStringAsync();

Assert.Contains("\"RequestInterceptorFunction\":", content);
Assert.Contains("\"ResponseInterceptorFunction\":", content);
}

[Theory]
[InlineData("/swagger/index.html", new [] { "Version 1.0", "Version 2.0" })]
[InlineData("/swagger/1.0/index.html", new [] { "Version 1.0" })]
Expand Down

0 comments on commit d5cd28e

Please sign in to comment.