Skip to content
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

Model casing is changed #83

Open
gsimardnet opened this issue Apr 6, 2021 · 6 comments
Open

Model casing is changed #83

gsimardnet opened this issue Apr 6, 2021 · 6 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@gsimardnet
Copy link

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.

@ssa3512
Copy link
Contributor

ssa3512 commented Apr 6, 2021

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

@justinyoo
Copy link
Contributor

@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:

public interface IOpenApiConfigurationOptions
{
/// <summary>
/// Gets or sets the <see cref="OpenApiInfo"/> instance.
/// </summary>
OpenApiInfo Info { get; set; }
/// <summary>
/// Gets or sets the list of <see cref="OpenApiServer"/> instances.
/// </summary>
List<OpenApiServer> Servers { get; set; }
}

@justinyoo justinyoo added the enhancement New feature or request label Apr 6, 2021
@ssa3512
Copy link
Contributor

ssa3512 commented Apr 13, 2021

@justinyoo if you want to assign this to me I should be able to get a PR up later this week or weekend.

@justinyoo
Copy link
Contributor

@ssa3512 Thanks for your support!

@Ausxor
Copy link

Ausxor commented Dec 22, 2023

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:

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?

CSymes added a commit to CSymes/azure-functions-openapi-extension that referenced this issue Feb 19, 2024
@CSymes
Copy link

CSymes commented Feb 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants