-
Notifications
You must be signed in to change notification settings - Fork 199
Open
Description
Describe the issue
When using IHostApplicationBuilder, I cannot figure out how to adjust the Json Serialization setting to match what the function returns.
To Reproduce
Steps to reproduce the behavior:
- Create a default HttpTrigger function app, which should use
FunctionsApplication.CreateBuilder(args)
- Change the Json Options to use a different naming policy
- Update the HttpTrigger to return an object and add an appropriate
[OpenApiResponseWithBody]
attribute. - View the Swagger UI page, the respons object will not have appropriate formatting of names, while when you run the HtttpTrigger will return proper casing.
Program.cs
var builder = FunctionsApplication.CreateBuilder(args);
builder.ConfigureFunctionsWebApplication();
builder.Services.AddMvc().AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower;
});
builder.Build().Run();
HttpTrigger1.cs
namespace Company.Function
{
public class HttpTrigger1
{
private readonly ILogger<HttpTrigger1> _logger;
public HttpTrigger1(ILogger<HttpTrigger1> logger)
{
_logger = logger;
}
[Function("HttpTrigger1")]
[OpenApiOperation(operationId: "Run")]
[OpenApiResponseWithBody(HttpStatusCode.OK, "application/json", typeof(ResponseData), Description = "Some Data")]
public IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");
return new OkObjectResult(new ResponseData { AgeInYears = 18, FullName = "Fred" });
}
}
public class ResponseData
{
public int AgeInYears { get; set; }
public string FullName { get; set; } = string.Empty;
}
}
You can see in the screen shot that the execution response used the proper casing (SnakeCaseLower), but the Example Value Response did not.
Expected behavior
It would be ideal for the same serializer to be used in both the response objects and the Swagger UI/OpenAPI schema.
CedNZ, Porges and rubenchristoffer
Metadata
Metadata
Assignees
Labels
No labels