Model casing is changed
I defined an XML request like the following :
[OpenApiRequestBody(contentType: "text/xml", bodyType: typeof(Model.MyClass))]
public class MyClass
{
public MySubClass MySubClass { get; set; }
}
public class MySubClass
{
public string MyProperty { get; set; }
}
Then when I look in the generated UI, the casing I have defined has changed:
<?xml version="1.0" encoding="UTF-8"?>
<myClass>
<mySubClass>
<myProperty>string</myProperty>
</mySubClass>
</myClass>
So far, the only solution I have found is to redefine the name of each property using the JsonProperty decorator.
For instance: [JsonProperty("MyProperty")]
Also does it make sense to use that decorator when my request is 'text/xml' ? It looks like this extension is made for JSON and XML is an afterthought.
At the moment it doesn't look like there is a way to override this using the main package that provides the templates, but if you copy in the three OpenAPI template files (OpenApiConfiguration, OpenApiHttpTrigger, and OpenApiHttpTriggerContext) and reference the Microsoft.Azure.WebJobs.Extensions.OpenApi.Core package instead, you can then change NamingStrategy on OpenApiHttpTriggerContext to be new DefaultNamingStrategy() instead of using CamelCaseNamingStrategy
@gsimardnet Thanks for the issue! You can use the suggestion by @ssa3512 as a workaround. In the meantime, I'll have a look at the configuration that can be overrideable, which is on:
https://github.com/Azure/azure-functions-openapi-extension/blob/7f70286964d0abc3fc88be32da11f50cce6652ba/src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/IOpenApiConfigurationOptions.cs#L10-L21
@justinyoo if you want to assign this to me I should be able to get a PR up later this week or weekend.
@ssa3512 Thanks for your support!
This is still an issue, or atleast also an issue in .NET isolated using 'Microsoft.Azure.Functions.Worker.Extensions.OpenApi'.
'UseNewtonsoftJson' uses the 'CamelCasePropertyNamesContractResolver', see:
https://github.com/Azure/azure-functions-openapi-extension/blob/ab184cbf3c8ff16378cfa00fa1cb23cb58ac1727/src/Microsoft.Azure.Functions.Worker.Extensions.OpenApi/Extensions/FunctionsWorkerApplicationBuilderExtensions.cs#L37
This seems like a strange choice as default, as it differs from default serializer (System.Text.Json) in a new isolated Function App.
For anyone looking to disable this, you can do the following:
worker.UseNewtonsoftJson(new JsonSerializerSettings
{
ContractResolver = new DefaultContractResolver()
});
Is there a reason camel case is defaulted?
Implemented and opened as PR #646. I agree that camel case as default is possibly not the optimal choice (personally not my desired one anyway), but changing that would obviously be a breaking change.