0

I have an ASP.NET Core 7 Web API using SwaggerUI. When my methods use a class for a parameter, it changes all of its properties to lowercase.

Is there a way to prevent that?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
kevin
  • 338
  • 2
  • 13
  • Can you post a screenshot? Wanna say it's simply following JSON notation and there is no practical way to change that. – beautifulcoder Mar 06 '23 at 20:53
  • 1
    JSON notation doesn't require the capitialization to be lower. JSON is case sensitive, but that is not the same thing. – kevin Mar 06 '23 at 21:06
  • See if any of these Q&As answer your question: [Is it possible to give input model properties different names in the Swagger UI, without using FromQuery?](https://stackoverflow.com/q/57477903/113116), [Web API serialize properties starting from lowercase letter](https://stackoverflow.com/q/22130431/113116), [Swagger UI incorrectly displays properties in lower-case for XML requests](https://stackoverflow.com/q/73498138/113116), [API Json response to C# Object with capital case properties first letter](https://stackoverflow.com/q/59281901/113116) – Helen Mar 06 '23 at 22:48

2 Answers2

0

You can use [JsonPropertyName] attribute to make it uppercase. For example: enter image description here
enter image description here
You can see that the key turns into uppercase with this attribute.

Qiang Fu
  • 1,401
  • 1
  • 2
  • 8
0

You can configure PascalCase formatting instead of the default camelCase formatting

builder.Services.AddControllers()
.AddJsonOptions(options =>
{
    options.JsonSerializerOptions.PropertyNamingPolicy = null;
});
david-ao
  • 3,000
  • 5
  • 12