https://linen.dev logo
#help
Title
a

Albert Vesker

05/26/2023, 9:51 AM
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

Tom

05/26/2023, 10:16 AM
Can you share the file you’re trying to use?
a

Albert Vesker

05/26/2023, 10:23 AM
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

Tom

05/26/2023, 10:26 AM
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

Albert Vesker

05/26/2023, 10:30 AM
How did you check it? We upload stubs throw com.github.tomakehurst.wiremock.client.WireMock#loadMappingsFrom(java.lang.String)
t

Tom

05/26/2023, 10:31 AM
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

Albert Vesker

05/26/2023, 10:34 AM
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

Tom

05/26/2023, 10:37 AM
I think
loadMappingsFrom
still only supports the single file format so you’ll need to use the import variant
a

Albert Vesker

05/26/2023, 10:39 AM
How to use it when we have over 500 mappings to load to docker?
t

Tom

05/26/2023, 10:39 AM
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

Albert Vesker

05/26/2023, 10:41 AM
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

Tom

05/26/2023, 10:47 AM
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

Albert Vesker

05/26/2023, 10:49 AM
So, at this moment u suggest: • Read directory • For each mapping use
WireMock.importStubMappings(Json.read("{your JSON}", StubImport.class));
Am I right?
t

Tom

05/26/2023, 10:50 AM
For each file, yes
a

Albert Vesker

05/26/2023, 10:51 AM
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

Tom

05/30/2023, 1:31 PM
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

Albert Vesker

05/30/2023, 1:34 PM
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

Tom

05/30/2023, 1:36 PM
The scenarios part is irrelevant, you can put collections of unrelated stubs in there if you want to also
a

Albert Vesker

05/30/2023, 1:40 PM
Thanks!
@Tom we've opened PR https://github.com/wiremock/wiremock/pull/2198 Review please when you will be able to
t

Tom

05/30/2023, 5:45 PM
Comment added