ccouzens / keycloak-openapi

OpenAPI definitions for Keycloak's Admin API
168 stars 66 forks source link

{id} path parameter occurs twice in some URLs #1

Closed chiragAcuver closed 4 years ago

chiragAcuver commented 4 years ago

{id} path parameter occurs twice in some URLs and parameter definition has "in path" definition for one of them. This will create problems in some applications that use open API specs. For example Azure API management does not allow two path params with same name. eg : /{realm}/client-scopes/{id}/protocol-mappers/models/{id}

I know that this crawls the official keycloak api docs and it has urls defined in that manner..

ccouzens commented 4 years ago

Thanks for reporting this.

I'll need to think about the best way to deal with it. Possibly I will respond one of these ways:

I'll need to investigate if there are other instances of repeated parameters.

I'm unlikely to get much chance to look further at this before the weekend.

ccouzens commented 4 years ago

I made a little program to identify the routes with issues. It can be run in the web browser's javascript console on the API page.

const paths = 
  [...document.querySelectorAll('pre, h4')]
    .map(s => s.textContent).
    filter(t => t.match(/{realm}/))
    .map(p => p.split(' ')[1])

new Set(
  paths
    .filter(r => {
      const params = [...r.match(/{\w+}/g) || []];
      return params.length !== new Set(params).size
    })
)

And it returns

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

I will think about the best way forward. It's only 2 routes, and they're both repeating id.

ccouzens commented 4 years ago

Should be fixed now.

Please let me know if you have any further issues

ccouzens commented 4 years ago

The solution I went with was to detect when id repeats, and then modify the parameters to then have a counter after them. eg /{realm}/client-scopes/{id1}/protocol-mappers/models/{id2}

chiragAcuver commented 4 years ago

Is it also generating "in-path" parameter definition now?

Sorry for delayed response, I don't use this Id for github.

ccouzens commented 4 years ago

Is it also generating "in-path" parameter definition now?

Yes, the 2 routes identified have the following path parameter definitions:

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