I am using NSwag SwaggerToCSharpClientGenerator to generate the request and response classes and enums.
I have some Web API methods that share the same enum as an argument or as part of request object. When I run the NSwag API, it generates the same enum definition multiple times, but named as Enum1, Enum2, Enum3, ResponseClassEnum.
Can I configure NSwag (or Swashbuckle) so that only one enum is generated?
My NSwag code looks like:
var document = SwaggerDocument.FromUrlAsync(
"http://localhost:5003/swagger/v1/swagger.json").Result;
var settings = new SwaggerToCSharpClientGeneratorSettings();
settings.GenerateClientClasses = false;
settings.CSharpGeneratorSettings.Namespace = "My.Interface";
settings.CSharpGeneratorSettings.ArrayType = "List";
settings.AdditionalNamespaceUsages = new string[] { "System.Collections.Generic" };
settings.GenerateExceptionClasses = false;
var generator = new SwaggerToCSharpClientGenerator(document, settings);
var code = generator.GenerateFile();
File.WriteAllText("Swagger.MyApi.cs", code);
I have put obfuscated swagger.json here - https://pastebin.com/hT5ySZub
Produced output from obfuscated swagger.json is here - https://pastebin.com/e0AYJWer In the output, the type DupEnum is defined in types: DupEnum, DupEnum2, DupEnum3, and TypeBDupEnum.