UriTemplate 中使用的 Azure API 管理模板参数必须在操作中定义,反之亦然

Azure API Management Template parameters used in the UriTemplate must be defined in the Operation, and vice-versa

我有很多 Azure 功能,现在我想将 Azure API 管理放在前面。

我已经从我的帐户中的 2 或 3 个其他功能应用程序导入了所有功能,没有任何问题,但我在使用其中一个功能应用程序时遇到问题。这个功能应用程序有 6 个功能,如果我 select 具体来说,我可以导入其中的 3 个。其他 3 个函数中的某些内容引发错误:

All template parameters used in the UriTemplate must be defined in the Operation, and vice-versa.

这是我的 Swagger api 文档的相关部分,由 Azure 函数本身创建:

    paths:
'/api/api-keys/{customerId}':
    delete:
    operationId: '/api/api-keys/{customerId}/delete'
    produces: []
    consumes: []
    parameters:
        - name: customerId
        in: path
        required: true
        type: string
    description: >-
        Replace with Operation Object
        #http://swagger.io/specification/#operationObject
    responses:
        '200':
        description: Success operation
    security:
        - apikeyQuery: []
'/api/api-keys/{customerId}/{apiKeyId}':
    delete:
    operationId: '/api/api-keys/{customerId}/{apiKeyId}/delete'
    produces: []
    consumes: []
    parameters:
        - name: customerId
        in: path
        required: true
        type: string
        - name: apiKeyId
        in: path
        required: true
        type: string
    description: >-
        Replace with Operation Object
        #http://swagger.io/specification/#operationObject
    responses:
        '200':
        description: Success operation
    security:
        - apikeyQuery: []
'/api/password-hashes/{customerId}/{prefix}':
    get:
    operationId: '/api/hashes/{customerId}/{prefix}/get'
    produces: []
    consumes: []
    parameters:
        - name: customerId
        in: path
        required: true
        type: string
        - name: prefix
        in: path
        required: true
        type: string
    description: >-
        Replace with Operation Object
        #http://swagger.io/specification/#operationObject
    responses:
        '200':
        description: Success operation
    security:
        - apikeyQuery: []

通过这个,我已经验证了参数中的所有项目都在路径中。我不确定这里是否遗漏了什么,但在互联网上环顾四周,我没有看到太多关于这个问题的信息。

更新 (10/1/18):问题已解决。如果仍可重现,请清除浏览器缓存。

Function App 导入目前根本不使用您为 Function App 定义的 OpenAPI 规范。相反,它直接使用 FunctionApp 定义。问题是由于您的函数具有带参数的路由,例如 /route/{param}。这将很快得到解决。

现在应该可以了。

您打开的 api 规范中有一个未定义的参数。

因为 Azure 不会为您提供更多详细信息,您可以使用 swagger editor 来验证您的规范。 小编会给你详细的错误信息:

另见 https://jamesradley.co.uk/2020/04/16/azure-api-management-template-parameters-used-in-the-uritemplate-must-be-defined-in-the-operation-and-vice-versa/