Settings for the WebApiAssemblyToSwaggerGenerator.
Inheritance: WebApiToSwaggerGeneratorSettings
Esempio n. 1
0
 private static string[] GetAllReferencePaths(WebApiAssemblyToSwaggerGeneratorSettings settings)
 {
     return(settings.AssemblyPaths.Select(p => Path.GetDirectoryName(PathUtilities.MakeAbsolutePath(p, Directory.GetCurrentDirectory())))
            .Concat(settings.ReferencePaths)
            .Distinct()
            .ToArray());
 }
 private static string[] GetAllReferencePaths(WebApiAssemblyToSwaggerGeneratorSettings settings)
 {
     return settings.AssemblyPaths.Select(p => Path.GetDirectoryName(PathUtilities.MakeAbsolutePath(p, Directory.GetCurrentDirectory())))
         .Concat(settings.ReferencePaths)
         .Distinct()
         .ToArray();
 }
Esempio n. 3
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
        }
Esempio n. 4
0
 /// <summary>Initializes a new instance of the <see cref="WebApiAssemblyToSwaggerGenerator"/> class.</summary>
 /// <param name="settings">The generator settings.</param>
 public WebApiAssemblyToSwaggerGenerator(WebApiAssemblyToSwaggerGeneratorSettings settings) : base(settings)
 {
 }
Esempio n. 5
0
            /// <exception cref="InvalidOperationException">No assembly paths have been provided.</exception>
            private IEnumerable <Type> GetControllerTypes(IEnumerable <string> controllerClassNames, WebApiAssemblyToSwaggerGeneratorSettings settings)
            {
                if (settings.AssemblyPaths == null || settings.AssemblyPaths.Length == 0)
                {
                    throw new InvalidOperationException("No assembly paths have been provided.");
                }

#if FullNet
                var assemblies = PathUtilities.ExpandFileWildcards(settings.AssemblyPaths)
                                 .Select(path => Assembly.LoadFrom(path)).ToArray();
#else
                var assemblies = PathUtilities.ExpandFileWildcards(settings.AssemblyPaths)
                                 .Select(path => Context.LoadFromAssemblyPath(path)).ToArray();
#endif

                var controllerTypes = new List <Type>();
                foreach (var className in controllerClassNames)
                {
                    var controllerType = assemblies.Select(a => a.GetType(className)).FirstOrDefault(t => t != null);
                    if (controllerType != null)
                    {
                        controllerTypes.Add(controllerType);
                    }
                    else
                    {
                        throw new TypeLoadException("Unable to load type for controller: " + className);
                    }
                }
                return(controllerTypes);
            }
 public WebApiToSwaggerCommand()
 {
     Settings = new WebApiAssemblyToSwaggerGeneratorSettings();
     ControllerNames = new string[] { };
 }
 /// <summary>Initializes a new instance of the <see cref="WebApiAssemblyToSwaggerGenerator" /> class.</summary>
 /// <param name="settings">The generator settings.</param>
 public WebApiAssemblyToSwaggerGenerator(WebApiAssemblyToSwaggerGeneratorSettings settings)
 {
     Settings = settings;
 }
 /// <summary>Initializes a new instance of the <see cref="WebApiAssemblyToSwaggerGeneratorBase"/> class.</summary>
 /// <param name="settings">The generator settings.</param>
 protected WebApiAssemblyToSwaggerGeneratorBase(WebApiAssemblyToSwaggerGeneratorSettings settings)
 {
     Settings = settings;
 }
Esempio n. 9
0
 public WebApiToSwaggerCommand()
 {
     Settings = new WebApiAssemblyToSwaggerGeneratorSettings();
 }
 /// <summary>Initializes a new instance of the <see cref="WebApiAssemblyToSwaggerGeneratorBase"/> class.</summary>
 /// <param name="settings">The generator settings.</param>
 protected WebApiAssemblyToSwaggerGeneratorBase(WebApiAssemblyToSwaggerGeneratorSettings settings)
 {
     Settings = settings;
 }
 /// <summary>Initializes a new instance of the <see cref="WebApiAssemblyToSwaggerGenerator" /> class.</summary>
 /// <param name="settings">The generator settings.</param>
 public WebApiAssemblyToSwaggerGenerator(WebApiAssemblyToSwaggerGeneratorSettings settings)
 {
     Settings = settings; 
 }
            private IEnumerable <Type> GetControllerTypes(IEnumerable <string> controllerClassNames, WebApiAssemblyToSwaggerGeneratorSettings settings)
            {
                var assembly = Assembly.LoadFrom(settings.AssemblyPath);
                var types    = assembly.GetTypes();

                var controllerTypes = new List <Type>();

                foreach (var className in controllerClassNames)
                {
                    try
                    {
                        var type = types.First(t => t.FullName == className || t.Name == className);
                        controllerTypes.Add(type);
                    }
                    catch (Exception exception)
                    {
                        throw new TypeLoadException("Unable to load type for controller: " + className, exception);
                    }
                }
                return(controllerTypes);
            }
            /// <exception cref="InvalidOperationException">No assembly paths have been provided.</exception>
            private IEnumerable<Type> GetControllerTypes(IEnumerable<string> controllerClassNames, WebApiAssemblyToSwaggerGeneratorSettings settings)
            {
                if (settings.AssemblyPaths == null || settings.AssemblyPaths.Length == 0)
                    throw new InvalidOperationException("No assembly paths have been provided.");

#if FullNet
                var assemblies = PathUtilities.ExpandFileWildcards(settings.AssemblyPaths)
                    .Select(path => Assembly.LoadFrom(path)).ToArray();
#else
                var assemblies = PathUtilities.ExpandFileWildcards(settings.AssemblyPaths)
                    .Select(path => Context.LoadFromAssemblyPath(path)).ToArray();
#endif

                var controllerTypes = new List<Type>();
                foreach (var className in controllerClassNames)
                {
                    var controllerType = assemblies.Select(a => a.GetType(className)).FirstOrDefault(t => t != null);
                    if (controllerType != null)
                        controllerTypes.Add(controllerType);
                    else
                        throw new TypeLoadException("Unable to load type for controller: " + className);
                }
                return controllerTypes;
            }
 /// <summary>Initializes a new instance of the <see cref="WebApiAssemblyToSwaggerGenerator"/> class.</summary>
 /// <param name="settings">The generator settings.</param>
 public WebApiAssemblyToSwaggerGenerator(WebApiAssemblyToSwaggerGeneratorSettings settings) : base(settings)
 {
 }