GenerateForControllers() public method

Generates the Swagger definition for all controllers in the assembly.
No assembly paths have been provided.
public GenerateForControllers ( IEnumerable controllerClassNames ) : SwaggerDocument
controllerClassNames IEnumerable The controller class names.
return SwaggerDocument
        public async Task<string> RunAsync()
        {
            var generator = new WebApiAssemblyToSwaggerGenerator(Settings);

            var controllerNames = ControllerNames.ToList(); 
            if (!string.IsNullOrEmpty(ControllerName))
                controllerNames.Add(ControllerName);

            controllerNames = controllerNames.Distinct().ToList();
            if (!controllerNames.Any())
                controllerNames = generator.GetControllerClasses().ToList();

            var service = generator.GenerateForControllers(controllerNames);
            return service.ToJson();
        }
Exemplo n.º 2
0
        public void When_controller_type_is_not_found_then_type_load_exception_is_thrown()
        {
            //// Arrange
            var settings = new WebApiAssemblyToSwaggerGeneratorSettings
            {
                AssemblyPaths = new[] { @"./NSwag.CodeGeneration.Tests.dll" },
                DefaultUrlTemplate = "api/{controller}/{action}/{id}"
            };

            var generator = new WebApiAssemblyToSwaggerGenerator(settings);

            //// Act
            var document = generator.GenerateForControllers(new[] { "NonExistingClass" }); // Should throw exception

            //// Assert
        }