/// <summary>Generates the Swagger definition for the given classes without operations (used for class generation).</summary> /// <param name="classNames">The class names.</param> /// <returns>The Swagger definition.</returns> public async Task <SwaggerDocument> GenerateAsync(string[] classNames) { var assemblyPath = Settings.AssemblySettings.AssemblyPaths.First(); var assemblyDirectory = Path.GetDirectoryName(Path.GetFullPath(assemblyPath)); using (var isolated = new AppDomainIsolation <NetAssemblyLoader>( assemblyDirectory, Settings.AssemblySettings.AssemblyConfig, AssemblyLoaderUtilities.GetBindingRedirects(), AssemblyLoaderUtilities.GetAssemblies(assemblyDirectory))) { var json = await Task.Run(() => isolated.Object.FromAssemblyType(classNames, JsonConvert.SerializeObject(Settings))).ConfigureAwait(false); return(await SwaggerDocument.FromJsonAsync(json).ConfigureAwait(false)); } }
/// <summary>Generates the Swagger definition for all controllers in the assembly.</summary> /// <param name="controllerClassNames">The controller class names.</param> /// <exception cref="InvalidOperationException">No assembly paths have been provided.</exception> /// <returns>The Swagger definition.</returns> public async Task <SwaggerDocument> GenerateForControllersAsync(IEnumerable <string> controllerClassNames) { if (!(Settings.SchemaNameGenerator is DefaultSchemaNameGenerator)) { throw new InvalidOperationException("The SchemaNameGenerator cannot be customized when loading types from external assemblies."); } if (!(Settings.TypeNameGenerator is DefaultTypeNameGenerator)) { throw new InvalidOperationException("The TypeNameGenerator cannot be customized when loading types from external assemblies."); } var assemblyDirectory = Path.GetDirectoryName(Path.GetFullPath(Settings.AssemblySettings.AssemblyPaths.First())); using (var isolated = new AppDomainIsolation <WebApiAssemblyLoader>(assemblyDirectory, Settings.AssemblySettings.AssemblyConfig, AssemblyLoaderUtilities.GetBindingRedirects(), AssemblyLoaderUtilities.GetAssemblies(assemblyDirectory))) { var document = await Task.Run(() => isolated.Object.GenerateForControllers(controllerClassNames, JsonConvert.SerializeObject(Settings))).ConfigureAwait(false); return(await SwaggerDocument.FromJsonAsync(document).ConfigureAwait(false)); } }
/// <summary>Gets the available controller classes from the given assembly.</summary> /// <returns>The controller classes.</returns> public string[] GetExportedClassNames() { var assemblyDirectory = Path.GetDirectoryName(Path.GetFullPath(Settings.AssemblySettings.AssemblyPaths.First())); using (var isolated = new AppDomainIsolation <NetAssemblyLoader>( assemblyDirectory, Settings.AssemblySettings.AssemblyConfig, AssemblyLoaderUtilities.GetBindingRedirects(), AssemblyLoaderUtilities.GetAssemblies(assemblyDirectory))) return(isolated.Object.GetExportedClassNames(Settings.AssemblySettings.AssemblyPaths, GetAllReferencePaths(Settings))); }
/// <summary>Gets the available controller classes from the given assembly.</summary> /// <returns>The controller classes.</returns> /// <exception cref="FileNotFoundException">The assembly could not be found.</exception> /// <exception cref="FileNotFoundException">The assembly config file could not be found..</exception> /// <exception cref="InvalidOperationException">No assembly paths have been provided.</exception> public string[] GetExportedControllerClassNames() { if (Settings.AssemblySettings.AssemblyPaths == null || Settings.AssemblySettings.AssemblyPaths.Length == 0) { throw new InvalidOperationException("No assembly paths have been provided."); } if (!File.Exists(Settings.AssemblySettings.AssemblyPaths.First())) { throw new FileNotFoundException("The assembly could not be found.", Settings.AssemblySettings.AssemblyPaths.First()); } if (!string.IsNullOrEmpty(Settings.AssemblySettings.AssemblyConfig) && !File.Exists(Settings.AssemblySettings.AssemblyConfig)) { throw new FileNotFoundException("The assembly config file could not be found.", Settings.AssemblySettings.AssemblyConfig); } var assemblyDirectory = Path.GetDirectoryName(Path.GetFullPath(Settings.AssemblySettings.AssemblyPaths.First())); using (var isolated = new AppDomainIsolation <WebApiAssemblyLoader>(assemblyDirectory, Settings.AssemblySettings.AssemblyConfig, AssemblyLoaderUtilities.GetBindingRedirects(), AssemblyLoaderUtilities.GetAssemblies(assemblyDirectory))) return(isolated.Object.GetControllerClasses(Settings.AssemblySettings.AssemblyPaths, GetAllReferencePaths(Settings))); }