0

By default, in ASP.NET Web API apps swagger generates JSON-schema in which class field names start with a lowercase letter. For example, for this class:

    public class WeatherForecast
    {
        public DateTime Date { get; set; }
    
        public int TemperatureC { get; set; }
    
        public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
    
        public string? Summary { get; set; }
    }

the following schema will be generated: schema

How to configure it so that the field names in schema exactly match the names in the C# code?

I read this document from Microsoft (ASP.NET Core web API documentation with Swagger / OpenAPI), but did not find the answer

  • what problem do you face because of this case change in schema ? – CodingMytra Sep 09 '22 at 10:35
  • 1
    Which implementation are you using `NSwagger` or `Swashbuckle` anyway you could change the `jsonserializer` options https://stackoverflow.com/questions/61405727/swagger-ui-shows-camelcase-parameters-instead-of-pascalcase – jjchiw Sep 09 '22 at 10:36
  • 1
    @jjchiw, thank you very much! indeed, adding this JsonSerializer option helped - `.AddJsonOptions(opt => opt.JsonSerializerOptions.PropertyNamingPolicy = null)` – Vadim Artyushenko Sep 09 '22 at 10:42
  • @CodingMytra, there were problems with deserialization on the client side – Vadim Artyushenko Sep 09 '22 at 10:47
  • you mean you have another client who is using this json file for listing your API's ? – CodingMytra Sep 09 '22 at 11:12

0 Answers0