azureopenapiazure-api-management

Validated Open API spec fails to upload on Azure API Management


I am trying to import OpenAPI specs json largely similar to https://github.com/ccouzens/keycloak-openapi/blob/master/keycloak/9.0.json on my azure api management service. I validated my version of the openapi.json on http://editor.swagger.io/ . When I try creating API resources using the above json I get the Error :

{"error":{"code":"ValidationError","message":"One or more fields contain incorrect values:","details":[{"code":"ValidationError","target":"templateParameters","message":"All template parameters used in the UriTemplate must be defined in the Operation, and vice-versa."}]}}

please help


Solution

  • Found the Issue. The json API spec file has multiple API URLs with {id} occurring twice in the same URL ,which azure's API management doesn't allow, and there is no "parameter" definition for two path parameters. For example , refer below URL and corresponding parameter definition in the api spec file

    /{realm}/client-scopes/{id}/protocol-mappers/models/{id}

     "parameters": [
            {
              "in": "path",
              "name": "realm",
              "description": "realm name (not id!)",
              "required": true,
              "schema": {
                "type": "string"
              },
              "style": "simple"
            },
            {
              "in": "path",
              "name": "id",
              "description": "Mapper id",
              "required": true,
              "schema": {
                "type": "string"
              },
              "style": "simple"
            }
          ]
    

    swagger editor does not consider these constrain violations

    So, to sum up, for uploading open API spec on Azure api management service, you need to consider following constrains along with the ones that is present in the azure docs

    1. you cannot have two path parameters with same identification string
    2. all path parameters should have a "parameter" definition in the spec json

    PS : My api spec json was largely similar to the json file, but not the same. It has other issues like delete API with a request body.