Closed blushingpenguin closed 5 years ago
The problem is that you use AspNetCoreToSwaggerGenerator when starting the app and the legacy WebApiToSwaggerGenerator via CLI - this might give you different output. It is recommended to also use the AspNetCoreToSwaggerGenerator in CLI: https://github.com/RSuter/NSwag/wiki/AspNetCore-Middleware#generate-via-cli (this way the SerializerSettings are used from AddSwaggerDocument).
Another important point: The SerializerSettings should not be changed in AddSwaggerDocument as it is automatically retrieved from the ASP.NET Core system - i.e. change the config with:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddJsonOptions(opt =>
{
opt.SerializerSettings.ContractResolver = new DefaultContractResolver { NamingStrategy = new SnakeCaseNamingStrategy() };
});
}
so that the serialization actually matches the generated spec..
In Startup.cs for the API:
This works fine and generates swagger.json with camelCase properties, but generating an API with: node_modules/.bin/nswag run /runtime:NetCore22 /variables:Configuration=Release
produces an API with properties like:
using nswag.json
I guess nswag is using reflection to find the property details and hence can't see the camelCase serializer setting passed on to the middleware, but given that defaultPropertyNameHandling is deprecated (and also appears to have been removed from nswagstudio) how should one generate now generate an API with a camelCase naming convention?
Thanks,
Mark