Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalybibikov committed Jun 4, 2020
1 parent 11d12e5 commit 424bcce
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
Expand Up @@ -2,10 +2,10 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PackageId>AzureExtensions.Swashbuckle</PackageId>
<Authors>yuka1984, vitalybibikov</Authors>
<Authors>vitalybibikov</Authors>
<Description>Swagger and Swagger UI in Azure Functions by Swashbuckle</Description>
<AssemblyName>AzureFunctions.Extensions.Swashbuckle</AssemblyName>
<Version>3.1.6</Version>
<Version>3.2.0-beta</Version>
<RootNamespace>AzureFunctions.Extensions.Swashbuckle</RootNamespace>
<Copyright>yuka1984</Copyright>
<PackageProjectUrl>https://github.com/vitalybibikov/azure-functions-extensions-swashbuckle</PackageProjectUrl>
Expand All @@ -19,6 +19,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.4.1" />
Expand Down
Expand Up @@ -7,13 +7,18 @@
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host.Bindings;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;

namespace AzureFunctions.Extensions.Swashbuckle
{
public static class SwashBuckleStartupExtension
{
[Obsolete("Please, use FunctionsStartup instead")]
public static IWebJobsBuilder AddSwashBuckle(
this IWebJobsBuilder builder,
Assembly assembly,
Expand All @@ -38,5 +43,32 @@ public static class SwashBuckleStartupExtension

return builder;
}

public static IFunctionsHostBuilder AddSwashBuckle(
this IFunctionsHostBuilder builder,
Assembly assembly,
Action<SwaggerDocOptions> configureDocOptionsAction = null)
{
var wbBuilder = builder.Services.AddWebJobs(x => { return; });

wbBuilder.AddExtension<SwashbuckleConfig>()
.BindOptions<SwaggerDocOptions>()
.ConfigureOptions<SwaggerDocOptions>((configuration, section, options) =>
{
configureDocOptionsAction?.Invoke(options);
});

builder.Services.AddSingleton<IModelMetadataProvider>(new EmptyModelMetadataProvider());
builder.Services.AddSingleton(new SwashBuckleStartupConfig
{
Assembly = assembly
});

var formatter = new SystemTextJsonOutputFormatter(new JsonSerializerOptions());
builder.Services.AddSingleton<IOutputFormatter>(formatter);
builder.Services.AddSingleton<IApiDescriptionGroupCollectionProvider, FunctionApiDescriptionProvider>();

return builder;
}
}
}
Expand Up @@ -2,6 +2,7 @@
using System.Reflection;
using AzureFunctions.Extensions.Swashbuckle;
using AzureFunctions.Extensions.Swashbuckle.Settings;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Hosting;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -13,9 +14,9 @@

namespace TestFunction
{
internal class SwashBuckleStartup : IWebJobsStartup
internal class SwashBuckleStartup : FunctionsStartup
{
public void Configure(IWebJobsBuilder builder)
public override void Configure(IFunctionsHostBuilder builder)
{
//Register the extension
builder.AddSwashBuckle(Assembly.GetExecutingAssembly(), opts =>
Expand Down

0 comments on commit 424bcce

Please sign in to comment.