-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Request/Response Interceptors Broken with .NET8 Upgrade / 6.6.1
#2906
Comments
I was able to workaround this by settings services.Configure<SwaggerUIOptions>(s =>
{
s.JsonSerializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web)
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
TypeInfoResolver = new DefaultJsonTypeInfoResolver
{
Modifiers =
{
static s =>
{
if (s.Type != typeof(InterceptorFunctions))
return;
// SwaggerUI Index expected capital letters for the property names on the
// interceptor functions (RequestInterceptorFunction and ResponseInterceptorFunction)
foreach (var prop in s.Properties)
prop.Name = char.ToUpper(prop.Name[0], CultureInfo.InvariantCulture) + prop.Name[1..];
}
}
}
};
}); Note that I found I needed to specify the |
One fix would be to change the casing on lines Swashbuckle.AspNetCore/src/Swashbuckle.AspNetCore.SwaggerUI/index.html Lines 99 to 103 in ecce973
Alternatively, you could add Swashbuckle.AspNetCore/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs Lines 257 to 273 in ecce973
|
JsonPropertyName attributes are how I would go about the fix if I were to do it. If you'd like to submit a PR we'd be grateful, otherwise I'll look into it tomorrow or over the weekend. |
Personally I disagree with that. All of the other properties are lowercase including the ones on Unfortunately I don't have the time to offer a PR right now |
I typically use JsonPropertyName to codify any property names and make them refactor-proof in my own projects to be explicit, rather than rely on conventions. I'll go with that approach when I fix this. |
I might also rename it for consistency, but I've seen so many bugs caused by refactoring breaking deserialisation that I always use attributes for new code. |
If you don't rename it and just use attributes, then I won't have to remember to remove the workaround from my project since it will just keep working... So there's that upside =) |
Fix property casing of Swagger UI interceptor function properties. Resolves domaindrivendev#2906.
Fix property casing of Swagger UI interceptor function properties. Resolves #2906.
Thanks for reporting this issue - the fix is available in Swashbuckle.AspNetCore 6.6.2. |
Describe the bug
After the upgrade to
6.6.1
, Request and Response interceptors are output to the document with the wrong property names (incorrect casing). They are expected to be written with initial uppercase letters,RequestInterceptorFunction
andResponseInterceptorFunction
but are now being written asrequestInterceptorFunction
andresponseInterceptorFunction
. This causes them to longer function as expected (or rather, at all).We rely on this functionality and missed this during the upgrade process as we were more focused on the document generation. We will need to roll back unless there's a workaround I'm not aware of
Expected behavior
The serialized functions should be output using the correct property names (or the expected property name in the index.html should be adjusted to reflect the new names) and should be invoked in response to requests/responses.
Actual behavior
Functions are serialized with incorrect names and no longer execute.
Steps to reproduce
Set a request or response interceptor:
Previously this would produce the following:
With latest version (6.6.1) it produces this instead:
Exception(s) (if any)
No response
Swashbuckle.AspNetCore version
6.6.1
.NET Version
net8.0
Anything else?
No response
The text was updated successfully, but these errors were encountered: