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

2

10

I have a number of Azure functions, that I would like to now put Azure API Management in front of.

I have imported all the functions from 2 or 3 of my other function apps in my account with no issues, but I am having issues with one of the function apps. This function app has 6 functions, 3 of which I can import fine if I select the specifically. Something within the other 3 functions is throwing an error:

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

Here the the relevant part of my Swagger api document created by the Azure Function itself:

    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: []

Looking through this, I have verified that all items in the parameters are in the paths. I am not sure if there is anything I am missing here, but looking around on the internet I did not see much regarding the issue.

Phillida answered 10/9, 2018 at 19:8 Comment(2)
Maybe these are just copy-paste errors, but the indentation in your example does not look right. Use editor.swagger.io to validate the syntax.Tetrapod
@Tetrapod Yeah, Syntax was previously validated. Indentation just got messed up during the copy/paste.Phillida
D
0

Update (10/1/18): The issue is fixed. Clear browser cache if still reproducible.

Function App import at the moment does not use OpenAPI spec you've defined for Function App at all. Instead it consumes FunctionApp definition directly. The problem is caused by your functions having routes with parameters, like /route/{param}. This will be fixed shortly.

This should work now.

Domineer answered 12/9, 2018 at 19:36 Comment(6)
So the API Management looks up the function app and tries to do it's own direct import, but since I have {params} in my route, it is unable to? When you say shortly, are we talking weeks, months, quarters, etc? Also, in the short term, the only way around this would be to manually create the blank API and configure it there to setup the routes and parameters?Phillida
Fix has been deployed. Give it a try.Domineer
Thank you, looks like the import has been fixed in the latest release of the "API Management Service". This makes it a lot easier, although, I had managed to build it all manually from a "Blank API" there were some things that I had to hack around to get it to work. For example, not being able to set the back end Azure Service, to a Function App (only Logic Apps supported), instead having to hard code the HTTPS endpoint. Anyways, thanks for the updates, function app importing is now working as expected for functions with parameters in their routes.Phillida
@VitaliyKurokhtin FYI: few minutes ago I used a route with param {param?} and the APIM import of this particular function fails..Fizzy
This is fixed now, clear browser cache if you still don't see the fix.Domineer
July 2020 and this is still an issue. I've never used functions or api management beforeAssert
H
8

There is an undefined parameter in your open api specifications.

Because Azure won't give you more details, you can use the swagger editor to validate your specifications. The editor will give you a detailed error message: enter image description here

See also 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/

Handicraft answered 7/9, 2020 at 19:51 Comment(4)
This was super helpful! My issue with this turned out to be an extra [HTTPGET] on my controller method that didn't have the same signature, so the pipeline deploy that was running threw an error.Lody
In my case, I had a duplicate parameter. I think it's solid advice to check using an alternative swagger editor if your template deployment failsMesmerize
@MatthiasM Do you know if there are any first-party ways to validate the OAS specification at runtime to avoid this issue cropping up during deployment?Tachyphylaxis
@Tachyphylaxis Sorry, I don't know. But perhaps Azure did some improvements in the last 2 years. I haven't checked this.Handicraft
D
0

Update (10/1/18): The issue is fixed. Clear browser cache if still reproducible.

Function App import at the moment does not use OpenAPI spec you've defined for Function App at all. Instead it consumes FunctionApp definition directly. The problem is caused by your functions having routes with parameters, like /route/{param}. This will be fixed shortly.

This should work now.

Domineer answered 12/9, 2018 at 19:36 Comment(6)
So the API Management looks up the function app and tries to do it's own direct import, but since I have {params} in my route, it is unable to? When you say shortly, are we talking weeks, months, quarters, etc? Also, in the short term, the only way around this would be to manually create the blank API and configure it there to setup the routes and parameters?Phillida
Fix has been deployed. Give it a try.Domineer
Thank you, looks like the import has been fixed in the latest release of the "API Management Service". This makes it a lot easier, although, I had managed to build it all manually from a "Blank API" there were some things that I had to hack around to get it to work. For example, not being able to set the back end Azure Service, to a Function App (only Logic Apps supported), instead having to hard code the HTTPS endpoint. Anyways, thanks for the updates, function app importing is now working as expected for functions with parameters in their routes.Phillida
@VitaliyKurokhtin FYI: few minutes ago I used a route with param {param?} and the APIM import of this particular function fails..Fizzy
This is fixed now, clear browser cache if you still don't see the fix.Domineer
July 2020 and this is still an issue. I've never used functions or api management beforeAssert

© 2022 - 2024 — McMap. All rights reserved.