Ramesh Kannan
Ramesh Kannan

Reputation: 1108

How to convert API response parameters to snake case in Swagger?

I've changed my API response parameters to snake case by adding below line in WebApiConfig.cs

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new DefaultContractResolver
        {
            NamingStrategy = new SnakeCaseNamingStrategy()
        };
    }
}

Currently I'm generating API documentation by using Swagger and I'm looking for same setup in Swagger response? Is there any option in Swagger for this?

Current document Output:

enter image description here

Expected document Output:

enter image description here

Upvotes: 2

Views: 2332

Answers (2)

Sourabh
Sourabh

Reputation: 481

Swagger Snake Case Configuration in Springboot

I faced the same issue and was able to fix it using ModelResolver from Swagger OAS.

Upvotes: 1

Helder Sepulveda
Helder Sepulveda

Reputation: 17664

Try using an IDocumentFilter, you can do all kind of changes to your document output (aka SwaggerDocument)

Here are some examples on GitHub

Upvotes: 1

Related Questions