Conflicting paths

Hi everyone, hope you’re all good.

I’m new to Kong and I’m experimenting generating a declarative yaml file for Kong based on an OpenAPI documentation file.

The problem i’m trying to solve occurs when there are overlapping paths. In my case:

  • /pets/{id}
  • /pets/{id}/name/{name}

My yaml file:

_format_version: "2.1"
_transform: true

services:
- name: pets
  url: http://127.0.0.1:3001/pets
  routes:
  - name: route-3-3
    methods:
    - GET
    paths:
    - /pets/(?<id>\d+)
    plugins:
    - name: request-transformer
      config:
        replace:
          uri: /pets/$(uri_captures["id"])

  - name: route-3-6
    methods:
    - GET
    paths:
    - /pets/(?<id>\d+)/name/(?<name>[^/]+?)
    plugins:
    - name: request-transformer
      config:
        replace:
          uri: /pets/$(uri_captures["id"])/name/$(uri_captures["name"])

What can I do so that when I make a request to http://127.0.0.1:8000/pets/1/name/random I go to the backend http://127.0.0.1:3001/pets/1/name/random instead of http://127.0.0.1:3001/pets/1.

I’ve tried making a request for http://127.0.0.1:8000/pets/a/name/random (changed the number for a letter, although there is a \d+ in the regex) and I went for http://127.0.0.1:3001/pets/a/name/random somehow.

Thank you all in advance!

I guess I skipped a section of the documentation. regex_priority based on the number of path params solved the issue.