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.

Kyle Briggs
  • 103
  • 1
  • 5
  • Maybe these are just copy-paste errors, but the indentation in your example does not look right. Use http://editor.swagger.io to validate the syntax. – Helen Sep 10 '18 at 19:14
  • @Helen Yeah, Syntax was previously validated. Indentation just got messed up during the copy/paste. – Kyle Briggs Sep 10 '18 at 19:30

2 Answers2

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/

Matthias M
  • 12,906
  • 17
  • 87
  • 116
  • 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. – RichieMN Mar 04 '22 at 16:01
  • 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 fails – smurtagh Mar 22 '22 at 02:37
  • @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? – Marie Jan 09 '23 at 19:12
  • 1
    @Marie Sorry, I don't know. But perhaps Azure did some improvements in the last 2 years. I haven't checked this. – Matthias M Jan 09 '23 at 19:30
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.

Vitaliy Kurokhtin
  • 7,205
  • 1
  • 19
  • 18
  • 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? – Kyle Briggs Sep 13 '18 at 13:22
  • Fix has been deployed. Give it a try. – Vitaliy Kurokhtin Sep 14 '18 at 17:20
  • 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. – Kyle Briggs Sep 17 '18 at 15:20
  • @VitaliyKurokhtin FYI: few minutes ago I used a route with param `{param?}` and the APIM import of this particular function fails.. – GuyT Sep 25 '18 at 13:06
  • This is fixed now, clear browser cache if you still don't see the fix. – Vitaliy Kurokhtin Oct 01 '18 at 18:59
  • July 2020 and this is still an issue. I've never used functions or api management before – The Muffin Man Jul 23 '20 at 23:45