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

Kyl*_*ggs 6 azure swagger azure-api-management azure-functions

我有许多 Azure 函数,现在我想将 Azure API 管理放在前面。

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

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

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

    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: []
Run Code Online (Sandbox Code Playgroud)

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

Mat*_*s M 8

您的开放API规范中有一个未定义的参数。

由于 Azure 不会提供更多详细信息,因此您可以使用swagger 编辑器来验证您的规范。编辑器会给你详细的错误信息: 在此输入图像描述

另请参阅https://jamesradley.co.uk/2020/04/16/azure-api-management-template-parameters-used-in-the-uritemplate-must-be-define-in-the-operation-and-反之亦然/


Vit*_*tin 0

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

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

现在应该可以了。