public async Task <string> GenerateSwagger() { var generator = new AzureFunctionsV2ToSwaggerGenerator(new AzureFunctionsV2ToSwaggerGeneratorSettings { Title = "H3 API", }); var publicApis = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(assembly => assembly.GetTypes()) .Where(type => type.GetCustomAttributes(typeof(PublicApiAttribute), inherit: true).Length > 0); var document = await generator.GenerateForAzureFunctionClassesAsync(publicApis, functionNames : null); var swagger = JObject.Parse(document.ToJson()); var paths = (JObject)swagger["paths"]; foreach (var property in paths.Properties().ToArray()) { if (property.Name.StartsWith(AutoGeneratedPrefix)) { paths.Remove(property.Name); paths.Add(property.Name.Substring(AutoGeneratedPrefix.Length), property.Value); } } return(swagger.ToString()); }
public static async Task <IActionResult> Swagger( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) { // swaggerUIの設定 var settings = new AzureFunctionsV2ToSwaggerGeneratorSettings(); settings.Title = "TestNSwag"; var generator = new AzureFunctionsV2ToSwaggerGenerator(settings); // UIに表示したいクラスを記載する var funcClasses = new[] { typeof(TestNSwag), }; var document = await generator.GenerateForAzureFunctionClassesAsync(funcClasses, null); // Workaround for NSwag global security bug, see https://github.com/RicoSuter/NSwag/pull/2305 document.Security.Clear(); var json = document.ToJson(); return(new OkObjectResult(json)); }
public static async Task <SwaggerDocument> GenerateSwaggerDocument() { var generator = new AzureFunctionsV2ToSwaggerGenerator(SwaggerConfiguration.SwaggerGeneratorSettings); var funcClasses = new[] { typeof(Replays), typeof(Maps), typeof(Players) }; var document = await generator.GenerateForAzureFunctionClassesAsync(funcClasses, null); return(document); }
public async Task Should_include_nonstatic_function_classes_and_methods() { // Arrange var settings = new AzureFunctionsV2ToSwaggerGeneratorSettings(); var generator = new AzureFunctionsV2ToSwaggerGenerator(settings); // Act var swaggerDoc = await generator.GenerateForAzureFunctionClassesAsync( new[] { typeof(NonStaticFunctionClass), typeof(IgnoredNonStaticFunctionClass) }, null); // Assert swaggerDoc.Operations.Count().Should().Be(1); }
public static async Task <IActionResult> Swagger( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) { var generator = new AzureFunctionsV2ToSwaggerGenerator(SwaggerConfiguration.SwaggerGeneratorSettings); var funcClasses = new[] { typeof(SwaggerEndpoints), typeof(GenerationAnnotationTests), typeof(HttpExtensionTests), typeof(RouteParamTests) }; var document = await generator.GenerateForAzureFunctionClassesAsync(funcClasses, null); // Workaround for NSwag global security bug, see https://github.com/RicoSuter/NSwag/pull/2305 document.Security.Clear(); var json = document.ToJson(); return(new OkObjectResult(json)); }