3

Problem:

I have Rest Endpoint with route params that look something like this

    [HttpDelete("{id}")]
    public async Task<IActionResult> DeleteDocument([FromRoute] DeleteDocumentRequest request)

Where the "DeleteDocumentRequest" has a gettor / settor

    public Guid Id {get; set;}

However, when swagger gen serializes this into OpenApi 3.0, it generates an error because the case of the property "Id" in the class does not match the property "id" in the route.

Question:

How can I override the serializer for it to change all of my properties to camelCase to ensure conformity?

Using Newtonsoft Json in .NET 6, I have tried to use CamelCasePropertyNamesContractResolver as well as overrides for ResolvePropertyName and CreateProperties, but the parameters in the controller endpoint are not "properties" that get hit.

adova
  • 950
  • 1
  • 8
  • 14
  • 2
    hi might be of interest https://stackoverflow.com/questions/61405727/swagger-ui-shows-camelcase-parameters-instead-of-pascalcase – jspcal May 19 '22 at 16:20
  • @jspcal - spot on - that article solved it. Kudos to you! – adova May 19 '22 at 16:51

1 Answers1

6

I was able to solve it by adding the following to the Swagger Gen setup. Thanks to @jspcal for the link to a related question.

services.AddSwaggerGen(c =>
            {
                c.DescribeAllParametersInCamelCase();
            });
adova
  • 950
  • 1
  • 8
  • 14