Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to match path params with OpenAPI expectations #1776

Open
lvijnck opened this issue Jul 20, 2023 · 1 comment
Open

Unable to match path params with OpenAPI expectations #1776

lvijnck opened this issue Jul 20, 2023 · 1 comment

Comments

@lvijnck
Copy link

lvijnck commented Jul 20, 2023

Describe the issue

I am trying to match path params with the mock library,, but I can't seem to find how to do this.

https://app.swaggerhub.com/apis/jamesdbloom/mock-server-openapi/5.15.x

What you are trying to do

Setup expectations for the OpenAPI generated MockServer

MockServer version
Latest

To Reproduce
Steps to reproduce the issue:

  1. How you are running MockServer (i.e maven plugin, docker, etc)

Docker-compose

  1. Code you used to create expectations

Schema:

    "/asset-facing/project/{projectId}": {
      "get": {
        "operationId": "ProjectController_getProjectInfo",
        "summary": "Get project information",
        "description": "This endpoint returns the project details along with the users associated with the project and a list of instances.",
        "parameters": [
          {
            "name": "projectId",
            "required": true,
            "in": "path",
            "example": "996e1ac7-8a60-41ec-81a5-36ca72e69f13",
            "schema": {}
          }
        ],
        "responses": {
          "200": {
            ...
         }
    }
 {
    "httpRequest": {
      "specUrlOrPayload": "file:/openapi/core-api.json",
      "operationId": "ProjectController_getProjectInfo",
    },
    "httpResponse": {
      "statusCode": 200,
      "headers": {
        "content-type": [
          "application/json"
        ]
      },
      "body": {
        "nonce": "f1b75ac7689ff88e1ecc40c84b115785"
      }
    }
  }
  1. What error you saw

didn't match open api "" operation "ProjectController_getProjectInfo" request matcher:

core_api_1     |  because:
core_api_1     | 
core_api_1     |   method matched
core_api_1     |   path matched
core_api_1     |   body matched
core_api_1     |   headers matched
core_api_1     |   cookies matched
core_api_1     |   pathParameters didn't match
core_api_1     |  

Expected behaviour

Have the ability to specify pathParameters for matching, but that crashes with the following message, e.g.,

"pathParameters" : [
        {
          "name": "projectId",
          "values": [
            "dummy"
          ]
        }
      ]
core_api_1     | java.lang.IllegalArgumentException: incorrect expectation json format for:
core_api_1     | 
core_api_1     |   {
core_api_1     |     "httpRequest" : {
core_api_1     |       "specUrlOrPayload" : "file:/openapi/core-api.json",
core_api_1     |       "operationId" : "ProjectController_getProjectInfo",
core_api_1     |       "pathParameters" : { }
core_api_1     |     },
core_api_1     |     "httpResponse" : {
core_api_1     |       "statusCode" : 200,
core_api_1     |       "headers" : {
core_api_1     |         "content-type" : [ "application/json" ]
core_api_1     |       },
core_api_1     |       "body" : {
core_api_1     |         "nonce" : "f1b75ac7689ff88e1ecc40c84b115785"
core_api_1     |       }
core_api_1     |     }
core_api_1     |   }
core_api_1     | 
core_api_1     |  schema validation errors:
core_api_1     | 
core_api_1     |   0 error:
core_api_1     |    - 
core_api_1     |   
core_api_1     |   OpenAPI Specification: https://app.swaggerhub.com/apis/jamesdbloom/mock-server-openapi/5.15.x
core_api_1     |   Documentation: https://mock-server.com/mock_server/creating_expectations.html
core_api_1     |        at org.mockserver.serialization.ExpectationSerializer.deserializeArray(ExpectationSerializer.java:205)
core_api_1     |        at org.mockserver.server.initialize.ExpectationInitializerLoader.lambda$retrieveExpectationsFromFile$1(ExpectationInitializerLoader.java:139)
core_api_1     |        at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:273)
core_api_1     |        at java.base/java.util.Collections$2.tryAdvance(Collections.java:4853)
core_api_1     |        at java.base/java.util.Collections$2.forEachRemaining(Collections.java:4861)
core_api_1     |        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
core_api_1     |        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
core_api_1     |        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
core_api_1     |        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
core_api_1     |        at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
core_api_1     |        at org.mockserver.server.initialize.ExpectationInitializerLoader.retrieveExpectationsFromFile(ExpectationInitializerLoader.java:176)
core_api_1     |        at org.mockserver.persistence.ExpectationFileWatcher.addExpectationsFromInitializer(ExpectationFileWatcher.java:102)
core_api_1     |        at org.mockserver.persistence.ExpectationFileWatcher.lambda$null$0(ExpectationFileWatcher.java:52)
core_api_1     |        at org.mockserver.persistence.FileWatcher.lambda$new$1(FileWatcher.java:52)
core_api_1     |        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
core_api_1     |        at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
core_api_1     |        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
core_api_1     |        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
core_api_1     |        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
core_api_1     |        at java.base/java.lang.Thread.run(Thread.java:833)
core_api_1     | 
core_api_1     | 2023-07-20 15:39:56 5.15.0 INFO removed expectation:
core_api_1     | 

MockServer Log
Log output, as INFO level (or lower)

@IvanZhivkov-sumup
Copy link

What version is the OpenAPI spec?
I had the same problem. But while typing some findings here, I tried using OpenAPI spec version 3.0.1 and it worked. Using spec version 3.1.0 doesn't work. Same spec, just changing the version (it is a simple spec).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants