The selected path is not the right one

Issue #69 closed
xavier le galles created an issue

Hi, We have a problem with a PACT trying to test a /v1/field/all path because it is resolved as /v1/field/{field id:guid}. Do you have a workaround or do you agree that it is a bug?

Both paths exist in the swagger.json file:

"/v1/field/{fieldId}": {
      "get": {
        "tags": [
          "FieldQuery"
        ],
        "summary": "Returns the specified field",
        "operationId": "V1FieldByFieldIdGet",
        "consumes": [],
        "produces": [
          "text/plain",
          "application/json",
          "text/json"
        ],
        "parameters": [
          {
            "name": "fieldId",
            "in": "path",
            "description": "The Id of the field",
            "required": true,
            "type": "string",
            "format": "uuid"
          },

And

"/v1/field/all": {
      "get": {
        "tags": [
          "FieldQuery"
        ],
        "summary": "Returns all fields",
        "operationId": "V1FieldAllGet",
        "consumes": [],
        "produces": [
          "text/plain",
          "application/json",
          "text/json"
        ],
        "parameters": [
          {
            "name": "transactionId",
            "in": "header",
            "description": "Transaction Id for the request",
            "required": false,
            "type": "string"
          }
        ],
        "responses"

Comments (6)

  1. Ben Sayers

    @xlegalles I agree it's a bug.

    The Swagger 2 specification does not define what the behaviour should be when a templated path and non-templated path both match a url, however the openapi-3 specification states this:

    When matching URLs, concrete (non-templated) paths would be matched before their templated counterparts. Templated paths with the same hierarchy but different templated names MUST NOT exist as they are identical. In case of ambiguous matching, it's up to the tooling to decide which one to use.

    So my proposal would be to update the tool to check for non-templated path matches before looking for templated path matches. Will this fix the bug for your use case?

  2. xavier le galles reporter

    Yes, it would be perfect. I have tried by hand to place the non-templated path before the templated one and it works. But I don't know how to do it from code (i.e. order paths).

  3. Ben Sayers

    @xlegalles awesome, I've put this bug fix into my teams backlog, we'll get to it as soon as we can.

    Just to be clear what we will do is update swagger-mock-validator to check for non-templated path matches before looking for path matches. Once we ship this fix it won't matter what order the paths appear in the swagger file.

  4. Log in to comment