门户网站不提供Azure API App Swagger

Sco*_*ott 4 c# azure azure-web-sites azure-api-apps

我创建了一个Azure API应用程序并将其部署到Azure.首先,我从门户网站获取Swagger文件没有问题(即通过单击API App刀片上的"API定义"按钮),但在某些时候它停止工作.

我已经启用了Swagger UI App_Start\SwaggerConfig.cs.当我在本地调试时,我可以导航到http:// localhost:12345/Swagger以进入Swagger UI并下载Swagger文件,一切正常.当我去门户网站时,我得到500错误,试图访问https://microsoft-apiappad6cxxxxxxxxxxxx426c23a66.azurewebsites.net:443/swagger/docs/v1.

我已经尝试删除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": {}
    }
}
Run Code Online (Sandbox Code Playgroud)

}

当然,这限制了在逻辑应用程序中使用API​​ App的能力,以及右键单击/添加Azure API App客户端到我的项目.(是的,我可以在本地获取Swagger文件,然后在项目中修改并使用它,但这不是我们正在寻找的流程).

有没有人对API应用程序无法生成有效的Swagger(或正确执行Swashbuckle代码)的原因有任何想法?

juv*_*han 5

尝试转到新的Azure门户(预览门户),浏览到您的API应用程序并将应用服务计划/定价层设置标准.

当我第一次使用默认的应用服务计划在Azure中部署我的API应用程序时,我也遇到了问题,而且当它是免费计划时,似乎没有为API应用程序创建实例.

将计划更改为标准后,我的API应用程序才能正常工作.希望这可以帮助!

我在Azure中使用Swagger的API应用程序

有用的参考:

创建API应用程序教程

部署API应用程序教程

编辑:答案在下面的评论中找到.在我更新了我的Swashbuckle NuGet包后,Swagger在Azure门户中正确显示.

  • 您好@Scott,您是否为.Net(2.6)安装了最新的Azure SDK?还尝试将API App的nuget包更新到最新版本.从Azure API API中返回的实际错误消息是什么? (2认同)
  • 更新NuGet包就可以了.我要编辑您的原始答案,并将其标记为答案.谢谢! (2认同)