Response is auto converting string to guid #616

Closed
opened 2025-12-29 15:28:29 +01:00 by adam · 2 comments
Owner

Originally created by @RyanMouraBrocco on GitHub (Jul 24, 2024).

Originally assigned to: @StefH on GitHub.

Describe the bug

I am using random-type responses, and when I am trying to return a GUID without the - it is converted automatically to the GUID with - no matter what I do.

An important thing is: I know that is a string conversion to a guid because when I add some static text, the conversion to a guid not happens. (as shown in the additional example)

Expected behavior:

For me, the expected behavior would be not to automatically convert any string that matches the format of a guid into a guid.

Test to reproduce

  • 1 Creating a mapping with TextRegex generation
  {
    "Guid": "78a8301a-6f86-4dfa-a4e7-e5f82cc36f75",
    "Priority": 0,
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/test",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "GET"
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": {
        "myguid": "{{Random Type=\"TextRegex\" Pattern=\"^[0-9a-f]{8}([0-9a-f]{4}){3}[0-9a-f]{12}$\"}}"
      },
      "UseTransformer": true,
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  }

the result

{
    "myguid": "8b5f1f76-cfa0-f3c9-b2de-f370c3512a1e"
}
  • 2 Creating a map with replace action
  {
    "Guid": "78a8301a-6f86-4dfa-a4e7-e5f82cc36f75",
    "Priority": 0,
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/test",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "GET"
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": {
        "myguid": "{{ String.Replace (Random Type=\"Guid\") \"-\" \"\" }}"
      },
      "UseTransformer": true,
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  }

The result

{
    "myguid": "a1e56fde-251d-409a-8b49-2dfd02c91e56"
}

Additional example

The mapping

  {
    "Guid": "78a8301a-6f86-4dfa-a4e7-e5f82cc36f75",
    "Priority": 0,
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/test",
            "IgnoreCase": false
          }
        ]
      },
      "Methods": [
        "GET"
      ]
    },
    "Response": {
      "StatusCode": 200,
      "BodyAsJson": {
        "myguid": "{{ String.Replace (Random Type=\"Guid\") \"-\" \"\" }} a"
      },
      "UseTransformer": true,
      "Headers": {
        "Content-Type": "application/json"
      }
    }
  }

the result

{
    "myguid": "045A02ACE846437DAF761D971D012C1A a"
}
Originally created by @RyanMouraBrocco on GitHub (Jul 24, 2024). Originally assigned to: @StefH on GitHub. ### Describe the bug I am using random-type responses, and when I am trying to return a GUID without the `-` it is converted automatically to the GUID with `-` no matter what I do. An important thing is: I know that is a string conversion to a guid because when I add some static text, the conversion to a guid not happens. (as shown in the additional example) ### Expected behavior: For me, the expected behavior would be not to automatically convert any string that matches the format of a guid into a guid. ### Test to reproduce - 1 Creating a mapping with TextRegex generation ```json { "Guid": "78a8301a-6f86-4dfa-a4e7-e5f82cc36f75", "Priority": 0, "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/test", "IgnoreCase": false } ] }, "Methods": [ "GET" ] }, "Response": { "StatusCode": 200, "BodyAsJson": { "myguid": "{{Random Type=\"TextRegex\" Pattern=\"^[0-9a-f]{8}([0-9a-f]{4}){3}[0-9a-f]{12}$\"}}" }, "UseTransformer": true, "Headers": { "Content-Type": "application/json" } } } ``` the result ```json { "myguid": "8b5f1f76-cfa0-f3c9-b2de-f370c3512a1e" } ``` - 2 Creating a map with replace action ```json { "Guid": "78a8301a-6f86-4dfa-a4e7-e5f82cc36f75", "Priority": 0, "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/test", "IgnoreCase": false } ] }, "Methods": [ "GET" ] }, "Response": { "StatusCode": 200, "BodyAsJson": { "myguid": "{{ String.Replace (Random Type=\"Guid\") \"-\" \"\" }}" }, "UseTransformer": true, "Headers": { "Content-Type": "application/json" } } } ``` The result ```json { "myguid": "a1e56fde-251d-409a-8b49-2dfd02c91e56" } ``` ### Additional example The mapping ```json { "Guid": "78a8301a-6f86-4dfa-a4e7-e5f82cc36f75", "Priority": 0, "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/test", "IgnoreCase": false } ] }, "Methods": [ "GET" ] }, "Response": { "StatusCode": 200, "BodyAsJson": { "myguid": "{{ String.Replace (Random Type=\"Guid\") \"-\" \"\" }} a" }, "UseTransformer": true, "Headers": { "Content-Type": "application/json" } } } ```` the result ```json { "myguid": "045A02ACE846437DAF761D971D012C1A a" } ```
adam added the bug label 2025-12-29 15:28:29 +01:00
adam closed this issue 2025-12-29 15:28:30 +01:00
Author
Owner

@StefH commented on GitHub (Jul 28, 2024):

https://github.com/WireMock-Net/WireMock.Net/pull/1148

@StefH commented on GitHub (Jul 28, 2024): https://github.com/WireMock-Net/WireMock.Net/pull/1148
Author
Owner

@StefH commented on GitHub (Jul 28, 2024):

@RyanMouraBrocco
This has been fixed in WireMock.Net

But note that of you want a random Guid without the "-", you can also provide the format.
Like:

"myguid": "{{ String.Replace (Random Type=\"Guid\") Format=\"D\"  }}"
@StefH commented on GitHub (Jul 28, 2024): @RyanMouraBrocco This has been fixed in WireMock.Net But note that of you want a random Guid without the "-", you can also provide the format. Like: ``` handlebars "myguid": "{{ String.Replace (Random Type=\"Guid\") Format=\"D\" }}" ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#616