Azure API App无法识别Swagger定义

时间:2015-11-26 11:10:48

标签: azure azure-web-sites swagger azure-api-apps

我正在尝试Azure的API App服务,并且我有一个有效的Swagger架构公开,供服务使用,遵循文档here。我可以在我的本地服务器上和部署API应用程序时检索其端点上的Swagger架构,并且我已经更新了我的web.config文件以包含application / json MIME类型。我的apiapp.json文件如下:

{
  "$schema": "http://json-schema.org/schema#",
  "id": "apiapp.dlxdev",
  "namespace": "microsoft.com",
  "gateway": "/* gateway, copied from Azure portal */",
  "version": "1.0.0",
  "title": "DLX API App (Dev)",
  "summary": "The developer version of the DLX API App.",
  "author": "Daniel W. Hieber",
  "endpoints": {
    "apiDefinition": "/api.json",
    "status": null
  }
}

即使我的端点定义为/api.json,当我转到Azure门户中的API定义刀片时,它会显示Failed to get metadata for 'apiApp.dlxDev' from endpoint '/swagger/docs/v1': Failed status code: 'NotFound'. Response Body: 'Not Found'.。似乎Azure仍然在默认的/swagger/docs/v1端点而不是我指定的/api.json端点上查找我的Swagger文件。

我还尝试创建一个metadata文件夹并将我的Swagger架构放在那里(根据文档将其重命名为apiDefinition.swagger.json),并且也没有任何运气。

我出错的任何想法?为什么Azure没有检测到我的Swagger架构的端点?

更新1

现在,我在API定义刀片中收到以下错误:#/definitions/: Cannot determine schema of data definition named ''。这似乎不是Swagger架构本身的问题,因为我的所有架构引用都是正确格式化的,并且架构本身是有效的。

更新2

我需要做的一件事是重新启动托管我的API应用程序的网关。重新启动网关是导致错误消息更改的原因。所以我认为应用程序现在正在识别我的Swagger架构。但我仍然不确定为什么我收到'无法确定架构'错误,因为我的架构格式正确。

1 个答案:

答案 0 :(得分:1)

  

现在我在API定义刀片中收到以下错误:>#/ definitions /:无法确定名为''的数据定义的架构。这>对于Swagger架构本身来说似乎不是问题,因为我的所有>架构引用都是正确格式化的,并且架构本身是有效的。

我认为Azure需要为每个操作都以swagger定义默认响应。也许仔细检查每个操作是否都有默认响应,并且每个响应都有一个schema属性,该属性可以解析为定义部分中的有效模式。

像:

"paths": {
    "/Categories": {
      "get": {
        "tags": [
          "Categories"
        ],
        ...
        ],
        ...
"responses": {
  "200": {
    "description": "EntitySet Categories",
    "schema": {
      "$ref": "#/definitions/NorthwindAPI.Models.Category"
    }
  },
  "default": {
    "description": "Unexpected error",
    "schema": {
      "$ref": "#/definitions/_Error"
    }
  }
},
...
"definitions": {
"NorthwindAPI.Models.Category": {
    "properties": {
        "CategoryID": {
          "format": "int32",
          "description": "CategoryID",
          "type": "integer"
        },
        "CategoryName": {
          "description": "CategoryName",
          "type": "string"
        },
        "Description": {
          "description": "Description",
          "type": "string"
        },
        "Picture": {
          "description": "Picture",
          "type": "string"
        }
    }
},
"_Error": {
    "properties": {
        "error": {
          "$ref": "#/definitions/_InError"
        }
    }
},

HTH, 约什