gpt4 book ai didi

c# - Azure 发布 : Failed to update API in Azure

转载 作者:行者123 更新时间:2023-12-02 07:43:09 31 4
gpt4 key购买 nike

我正在尝试从 Visual Studio 在 Azure 上发布我的 .net3.1 Web 应用程序。

Visual Studio 在“开始更新 API”步骤上失败,这是 Visual Studio 的输出:

Build started...
1>------ Build started: Project: WebApplication_XXX, Configuration: Release Any CPU ------
1>WebApplication_XXX -> C:\Users\YYYY\source\repos\WebApplication_XXX\WebApplication_XXX\bin\Release\netcoreapp3.1\WebApplication_XXX.dll
1>Done building project "WebApplication_XXX.csproj".
2>------ Publish started: Project: WebApplication_XXX, Configuration: Release Any CPU ------
WebApplication_XXX -> C:\Users\YYYY\source\repos\WebApplication_XXX\WebApplication_XXX\bin\Release\netcoreapp3.1\WebApplication_XXX.dll
npm install
npm run build -- --prod
> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dea9bbbcbfaeaeb2b7bdbfaab7b1b081a6a6a69eeef0eef0ee" rel="noreferrer noopener nofollow">[email protected]</a> build C:\Users\YYYY\source\repos\WebApplication_XXX\WebApplication_XXX\ClientApp
> ng build "--prod"

Generating ES5 bundles for differential loading...
ES5 bundle generation complete.
....
Publish Succeeded.
Web App was published successfully https://xxxxxxx.azurewebsites.net/
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========
Starting to update your API
Generating swagger file to 'C:\Users\YYYY\source\repos\WebApplication_XXX\WebApplication_XXX\bin\Release\netcoreapp3.1\swagger.json'.
Failed to update your API in Azure.

然后我检查 Azure 门户并在“创建 API 或更新 API”json 中发现一些错误

...
"properties": {
"statusCode": "BadRequest",
"serviceRequestId": "*****",
"statusMessage": "{\"error\":{\"code\":\"ValidationError\",\"message\":\"One or more fields contain incorrect values:\",\"details\":[{\"code\":\"ValidationError\",\"target\":\"representation\",\"message\":\"Parsing error(s): JSON is valid against no schemas from 'oneOf'. Path 'securityDefinitions.Bearer', line 2841, position 15.\"},{\"code\":\"ValidationError\",\"target\":\"representation\",\"message\":\"Parsing error(s): The input OpenAPI file is not valid for the OpenAPI specificate https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md (schema https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json).\"}]}}",
"eventCategory": "Administrative",
"entity": "/subscriptions/*****/resourceGroups/XXX/providers/Microsoft.ApiManagement/service/WebApplicationXXXapi/apis/WebApplicationXXX",
"message": "Microsoft.ApiManagement/service/apis/write",
"hierarchy": "*****"
},
...

因此,我在 swagger 中打开 'C:\Users\YYYY\source\repos\WebApplication_XXX\WebApplication_XXX\bin\Release\netcoreapp3.1\swagger.json' 生成的 swagger.json 文件编辑器并得到相同的错误:

Structural error at securityDefinitions.Bearer
should have required property 'type'
missingProperty: type

因为 json 文件中的安全定义承载为空

securityDefinitions:
Bearer: {
}

如果我在 swagger 编辑器中进行以下更改,它会很高兴:

securityDefinitions:
Bearer: {
type: apiKey,
name: "JWT Authentication",
in: "header"
}

在我的应用程序 Startup.cs 中,我得到:

services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "XXX API", Version = "v1" });
var securityScheme = new OpenApiSecurityScheme
{
Name = "JWT Authentication",
Description = "Enter JWT Bearer token **_only_**",
In = ParameterLocation.Header,
Type = SecuritySchemeType.Http,
Scheme = "bearer", // must be lower case
BearerFormat = "JWT",
Reference = new OpenApiReference
{
Id = JwtBearerDefaults.AuthenticationScheme,
Type = ReferenceType.SecurityScheme
}
};
c.AddSecurityDefinition(securityScheme.Reference.Id, securityScheme);
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{securityScheme, new string[] { }}
});
});

我缺少什么? Startup.cs中的代码在生成swagger.json文件时是否应该添加securityDefinition?

最佳答案

我们也有同样的问题。目前,我们使用了一种解决方法,即在发布期间禁用更新 api。 (我使用VS2022和.net6.0)
在 PublishProfiles/...pubxml 中将参数 UpdateApiOnPublish 更改为 false。

<UpdateApiOnPublish>false</UpdateApiOnPublish>

关于c# - Azure 发布 : Failed to update API in Azure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69090118/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com