我创建了一个 Azure API 应用程序并将其部署到 Azure。起初,我从门户获取 Swagger 文件没有问题(即通过单击 API App 刀片上的“API 定义”按钮),但在某些时候它停止工作。
我已经在App_Start\SwaggerConfig.cs
. 当我在本地调试时,我可以导航到http://localhost:12345/Swagger以进入 Swagger UI 并下载 Swagger 文件,一切正常。当我转到门户时,尝试访问https://microsoft-apiappad6cxxxxxxxxxxxx426c23a66.azurewebsites.net:443/swagger/docs/v1时出现 500 错误。
我试过删除 API 应用程序并重新部署它......不走运。我尝试过开始一个新项目并使用它创建相同的界面并将其部署到 Azure ......每次都有效(当然)。
我将在此处包含 Swagger 文件,以防万一,但我不明白的是:为什么 Swashbuckle 会在本地工作,但不能在 Azure 中工作?
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "StorefrontApi"
},
"host": "localhost:52912",
"schemes": [
"http"
],
"paths": {
"/api/v1/storefront/applications": {
"get": {
"tags": [
"GET"
],
"operationId": "Storefront_Applications",
"consumes": [],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Object"
}
}
},
"deprecated": false
}
},
"/api/v1/storefront/aurorastatus": {
"get": {
"tags": [
"GET"
],
"operationId": "Storefront_AuroraStatus",
"consumes": [],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "auroraSerialNumber",
"in": "query",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Object"
}
}
},
"deprecated": false
}
},
"/api/v1/storefront/order": {
"post": {
"tags": [
"POST"
],
"operationId": "Storefront_Order",
"consumes": [
"application/json",
"text/json",
"application/xml",
"text/xml",
"application/x-www-form-urlencoded"
],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "requestBody",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Object"
}
}
},
"deprecated": false
}
},
"/api/v1/storefront/register": {
"post": {
"tags": [
"POST"
],
"summary": "",
"operationId": "Storefront_Register",
"consumes": [
"application/json",
"text/json",
"application/xml",
"text/xml",
"application/x-www-form-urlencoded"
],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "requestBody",
"in": "body",
"description": "",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Object"
}
}
},
"deprecated": false
}
},
"/api/v1/storefront/removeapplication": {
"post": {
"tags": [
"POST"
],
"summary": "",
"operationId": "Storefront_RemoveApplication",
"consumes": [
"application/json",
"text/json",
"application/xml",
"text/xml",
"application/x-www-form-urlencoded"
],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "requestBody",
"in": "body",
"description": "",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Object"
}
}
},
"deprecated": false
}
},
"/api/v1/storefront/updateserialnumber": {
"post": {
"tags": [
"POST"
],
"operationId": "Storefront_UpdateSerialNumber",
"consumes": [
"application/json",
"text/json",
"application/xml",
"text/xml",
"application/x-www-form-urlencoded"
],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "requestBody",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Object"
}
}
},
"deprecated": false
}
}
},
"definitions": {
"Object": {
"type": "object",
"properties": {}
}
}
}
当然,这限制了在逻辑应用程序中使用 API 应用程序的能力,以及右键单击/将 Azure API 应用程序客户端添加到我的项目的能力。(是的,我可以在本地获取 Swagger 文件,然后在项目中修改和使用它,但这不是我们要寻找的流程)。
是否有人对导致 API 应用程序无法生成有效 Swagger(或正确执行 Swashbuckle 代码)的原因有任何想法?