门户网站不提供Azure API App Swagger

时间:2015-04-27 18:23:15

标签: c# azure azure-web-sites azure-api-apps

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

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

我尝试删除API App并重新部署它......没有运气。我已经尝试启动一个新项目并使用它创建相同的界面并将其部署到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": {}
    }
}

}

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

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

5 个答案:

答案 0 :(得分:5)

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

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

在将计划更改为标准后,我的API应用程序才能正常运行。 希望这有帮助!

My API App with Swagger in Azure

有用的参考资料:

Create API App Tutorial

Deploy API App Tutorial

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

答案 1 :(得分:0)

部署版本不起作用时使用的过程是。

  1. 设置对公共的访问权限 - 删除网关引入的问题。
  2. 检查已知的终点api - https:\ | xxxxx \ yourapi
  3. 启用web.config中的远程错误
  4. 解决未包含在构建中的任何缺少的引用(将“复制到输出目录”设置为true)
  5. 重新部署
  6. 访问Swagger端点。
  7. 通过网关重新启用安全性。
  8. 这允许您删除多个故障点,并在新的Api应用程序中添加额外的图层之前查看最简单的功能是否有效。

答案 2 :(得分:0)

你必须更新Swashbuckle版本,一切正常

  • Install-Package Swashbuckle -Version 5.2.2无法正常工作
  • Install-Package Swashbuckle -Version 5.2.1运行正常

答案 3 :(得分:0)

我遇到了同样的问题,通过升级服务计划和更新nuget包解决了这个问题。

答案 4 :(得分:0)

最近发现这一点,发现Startup.cs的Config方法中的app.UseSwaggerUI被包装在If Debug Compiler指令中。不确定它是开发人员还是自动模板的一部分,但值得一提。