private async Task <string> FromAssemblyTypeAsync(string[] classNames, string settingsData) { var document = new SwaggerDocument(); var settings = JsonConvert.DeserializeObject <AssemblyTypeToSwaggerGeneratorSettings>(settingsData); RegisterReferencePaths(GetAllReferencePaths(settings)); var generator = new JsonSchemaGenerator(settings); var schemaResolver = new SwaggerSchemaResolver(document, settings); #if FullNet var assemblies = PathUtilities.ExpandFileWildcards(settings.AssemblySettings.AssemblyPaths) .Select(path => Assembly.LoadFrom(path)).ToArray(); #else var currentDirectory = await DynamicApis.DirectoryGetCurrentDirectoryAsync().ConfigureAwait(false); var assemblies = PathUtilities.ExpandFileWildcards(settings.AssemblySettings.AssemblyPaths) .Select(path => Context.LoadFromAssemblyPath(PathUtilities.MakeAbsolutePath(path, currentDirectory))).ToArray(); #endif var allExportedClassNames = assemblies.SelectMany(a => a.ExportedTypes).Select(t => t.FullName).ToList(); var matchedClassNames = classNames .SelectMany(n => PathUtilities.FindWildcardMatches(n, allExportedClassNames, '.')) .Distinct(); foreach (var className in matchedClassNames) { var type = assemblies.Select(a => a.GetType(className)).FirstOrDefault(t => t != null); await generator.GenerateAsync(type, schemaResolver).ConfigureAwait(false); } return(document.ToJson()); }
protected override async Task <string> RunIsolatedAsync(AssemblyLoader.AssemblyLoader assemblyLoader) { var document = new OpenApiDocument(); var generator = new JsonSchemaGenerator(Settings); var schemaResolver = new OpenApiSchemaResolver(document, Settings); #if FullNet var assemblies = PathUtilities.ExpandFileWildcards(AssemblyPaths) .Select(path => Assembly.LoadFrom(path)).ToArray(); #else var currentDirectory = DynamicApis.DirectoryGetCurrentDirectory(); var assemblies = PathUtilities.ExpandFileWildcards(AssemblyPaths) .Select(path => assemblyLoader.Context.LoadFromAssemblyPath(PathUtilities.MakeAbsolutePath(path, currentDirectory))).ToArray(); #endif var allExportedClassNames = assemblies.SelectMany(a => a.ExportedTypes).Select(t => t.FullName).ToList(); var matchedClassNames = ClassNames .SelectMany(n => PathUtilities.FindWildcardMatches(n, allExportedClassNames, '.')) .Distinct(); foreach (var className in matchedClassNames) { var type = assemblies.Select(a => a.GetType(className)).FirstOrDefault(t => t != null); generator.Generate(type, schemaResolver); } return(document.ToJson(OutputType)); }
public void SingleWildcardAtTheEnd() { //// Arrange var items = new string[] { "abc/a", "abc/b", "abc/c/d" }; //// Act var matches = PathUtilities.FindWildcardMatches("abc/*", items, '/'); //// Assert Assert.Equal(2, matches.Count()); }
public void SingleWildcardInTheMiddle() { //// Arrange var items = new string[] { "abc/def/ghi", "abc/def/jkl", "abc/a/b/ghi" }; //// Act var matches = PathUtilities.FindWildcardMatches("abc/*/ghi", items, '/'); //// Assert Assert.Single(matches); Assert.Equal("abc/def/ghi", matches.First()); }
public void NoWildcard() { //// Arrange var items = new string[] { "abc/def", "ghi/jkl" }; //// Act var matches = PathUtilities.FindWildcardMatches("abc/def", items, '/'); //// Assert Assert.Single(matches); Assert.Equal("abc/def", matches.First()); }
public void DoubleWildcardAtTheBeginning() { //// Arrange var items = new string[] { "a/b/c", "a/b/d", "a/c" }; //// Act var matches = PathUtilities.FindWildcardMatches("**/c", items, '/'); //// Assert Assert.Equal(2, matches.Count()); Assert.Equal("a/b/c", matches.First()); Assert.Equal("a/c", matches.Last()); }
private async Task <IEnumerable <Type> > GetControllerTypesAsync(IEnumerable <string> controllerNames, AssemblyLoader.AssemblyLoader assemblyLoader) #pragma warning restore 1998 { if (AssemblyPaths == null || AssemblyPaths.Length == 0) { throw new InvalidOperationException("No assembly paths have been provided."); } #if FullNet var assemblies = PathUtilities.ExpandFileWildcards(AssemblyPaths) .Select(path => Assembly.LoadFrom(path)).ToArray(); #else var currentDirectory = await DynamicApis.DirectoryGetCurrentDirectoryAsync().ConfigureAwait(false); var assemblies = PathUtilities.ExpandFileWildcards(AssemblyPaths) .Select(path => assemblyLoader.Context.LoadFromAssemblyPath(PathUtilities.MakeAbsolutePath(path, currentDirectory))).ToArray(); #endif var allExportedNames = assemblies.SelectMany(a => a.ExportedTypes).Select(t => t.FullName).ToList(); var matchedControllerNames = controllerNames .SelectMany(n => PathUtilities.FindWildcardMatches(n, allExportedNames, '.')) .Distinct(); var controllerNamesWithoutWildcard = controllerNames.Where(n => !n.Contains("*")).ToArray(); if (controllerNamesWithoutWildcard.Any(n => !matchedControllerNames.Contains(n))) { throw new TypeLoadException("Unable to load type for controllers: " + string.Join(", ", controllerNamesWithoutWildcard)); } var controllerTypes = new List <Type>(); foreach (var className in matchedControllerNames) { 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); }