Hello. I've an issue but what Tom suggested me doe...
# help
a
Hello. I've an issue but what Tom suggested me doesn't work https://github.com/wiremock/wiremock/issues/1921 In which version of WM it should work?
I'm asking cos I'm getting an error right now:
Copy code
{
  "errors": [
    {
      "code": 10,
      "source": {
        "pointer": "/mappings"
      },
      "title": "Error parsing JSON",
      "detail": "Unrecognized field \"mappings\" (class com.github.tomakehurst.wiremock.stubbing.StubMapping), not marked as ignorable"
    }
  ]
}
version: 2.34.0
t
Can you share the file you’re trying to use?
a
Copy code
{
  "mappings": [
    {
      "scenarioName": "payment-status-11192",
      "requiredScenarioState": "payment-status-created",
      "request": {
        "url": "/api/v2/payment",
        "method": "GET"
      },
      "response": {
        "status": 200,
        "jsonBody": [
          {
            "orderNumber": "00011192"
          }
        ],
        "headers": {
          "Content-Type": "application/json"
        }
      }
    },
    {
      "scenarioName": "payment-status-11192",
      "requiredScenarioState": "payment-status-complete",
      "request": {
        "url": "/api/v2/payment",
        "method": "GET"
      },
      "response": {
        "status": 200,
        "jsonBody": [
          {
            "orderNumber": "11111192"
          }
        ],
        "headers": {
          "Content-Type": "application/json"
        }
      }
    }
  ]
}
t
This file works for me, both in 2.34.0 and 2.35.0. Wondering if you’ve got another file in there that’s causing the error?
a
How did you check it? We upload stubs throw com.github.tomakehurst.wiremock.client.WireMock#loadMappingsFrom(java.lang.String)
t
I dropped it in the mappings folder then started WireMock.
Try this:
Copy code
WireMock.importStubMappings(Json.read("{your JSON}", StubImport.class));
loadMappingsFrom
takes a folder path as the parameter - was that what you were passing?
a
takes a folder path as the parameter - was that what you were passing?
Yes. It works for every mapping except my example
I have only such methods. I will try both
t
I think
loadMappingsFrom
still only supports the single file format so you’ll need to use the import variant
a
How to use it when we have over 500 mappings to load to docker?
t
The same way. Should scale up to that amount no problem. Or you can mount the files into the Docker container so they’re loaded automatically.
a
Yes, method which u suggested helped me
Mount is not the solution for us. We work on the remote hosts
As we understood - loadMappings doesn't support such files. And you suggest to read directory, map each file and use stubImport?
Or I didn't understand you 😞
And I want to say that I think 'loadMappings' has to support such files and it looks like a bug
t
I agree it should, although I'd characterise it as a not-yet-implemented feature. Happy to receive a PR if you feel like creating one.
👍 1
a
So, at this moment u suggest: • Read directory • For each mapping use
WireMock.importStubMappings(Json.read("{your JSON}", StubImport.class));
Am I right?
t
For each file, yes
a
Ok, thanks for the help. When I find time for PR, I will make it)
👍 1
Tom, We've checked the code. We have stub/mappings with such variants of mappings: • just mappings with request/response without the "mappings" field • separated scenarios • scenarios with "mappings" field • mappings with 'bodyFilePath' field and mappings with "jsonBody" field so this class doesn't searching for file body if it's in other json With ur suggestion StubImport class it doesn't work and we should refactor all files to
{ "mappings": [] }
variant It will take a lot of time and as we understood this class doesn't have backward capability What can u say about this situation?
@Oleg Nenashev FYI
Hi) Any suggestions? )
t
It seems given your requirements and setup that your best option is to stick with single mapping files for the time being. Once
RemoteMappingsLoader
supports multi-mapping files, then you can switch to using them.
a
Ok, thanks
And the last question Json with the "mappings" field supports only scenarios or we can put several different mappings and it could be not scenarios?
t
The scenarios part is irrelevant, you can put collections of unrelated stubs in there if you want to also
a
Thanks!
@Tom we've opened PR https://github.com/wiremock/wiremock/pull/2198 Review please when you will be able to
t
Comment added