Swashbuckle for Azure Function:自定义标头 [英] Swashbuckle for Azure Function: customize header

查看:87
本文介绍了Swashbuckle for Azure Function:自定义标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Azure Functions中,我添加了Swashbuckle,并且它可以正常工作.

In my Azure Functions I added Swashbuckle and it is working.

[SwaggerIgnore]
[FunctionName("swaggerUi")]
public static Task<HttpResponseMessage> SwaggerUi(
    [HttpTrigger(AuthorizationLevel.Function, "get", Route = SwaggerRoutes.UiRoute)] 
    HttpRequestMessage req,
    [SwashBuckleClient] ISwashBuckleClient swashBuckleClient)
{
    return Task.FromResult(swashBuckleClient.CreateSwaggerUIResponse(req, 
                           req.CreateSwaggerDocumentRoute()));
}

现在,我想使用有关我的api的一些信息来自定义标头.

Now, I wanted to customize the header with some information about my apis.

我找到了帖子那个家伙说在host.json中添加一些配置就足够了,例如:

I found a post where that guy said it is enough to add some configuration in the host.json like:

{
  "version": "2.0",
  "extensions": {
    ...

    "Swashbuckle": {
      "Documents": [
        {
          "Title": "YOUR_TITLE",
          "Version": "v1",
          "Description": "YOUR_DESCRIPTION"
        }
      ]
    }
  }
}

但是对我来说这是行不通的.有什么需要做的?

but for me it doesn't work. What is it necessary to do?

推荐答案

好,现在我设法使其正常运行.当您在Visual Studio中创建新的Azure函数时,默认情况下会创建一个在.netcore3.0上运行的V3 Azure函数.

Ok so this is now i managed to get it working. When you create a fresh Azure Function in Visual Studio, by default it created a V3 Azure Function which runs on .netcore3.0.

首先我没有注意到,并安装了这个nuget AzureFunctions.Extensions.Swashbuckle;

I did not notice that in the first place and installed this nuget AzureFunctions.Extensions.Swashbuckle;

添加了两个功能,一个赋予Swagger JSON,另一个赋予Swagger UI

Added two functions, one to give Swagger JSON and another one for the Swagger UI

当我运行该应用程序时,它给出了一些无关的错误.经过快速搜索,我最终遇到了这个 Github第21期

When i ran the app, it gave some errors which were unrelated. After a quick search i ended up on this Github Issue #21

  1. 此后,我迅速检查了它指向最新的V3.xMicrosoft.Net.Sdk.Functions版本,并将其降级为V1.0.36

  1. After this, i quickly checked the Microsoft.Net.Sdk.Functions version it was pointing to the latest V3.x i downgraded it to V1.0.36

我编辑了func.csproj,并使用Azure func v2将目标框架指向了.netcore2.1

I edited my func.csproj and pointed the Target Framework to .netcore2.1 with Azure func v2

<TargetFramework>netcoreapp2.1</TargetFramework> <AzureFunctionsVersion>v2</AzureFunctionsVersion>

运行时,控制台显示

我在这里浏览以查看SwaggerUI是否有效

Here i browse to see if the SwaggerUI works

我也测试了SwaggerJSON

这篇关于Swashbuckle for Azure Function:自定义标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆