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

Response is auto converting string to guid #1145

Closed
RyanMouraBrocco opened this issue Jul 24, 2024 · 2 comments
Closed

Response is auto converting string to guid #1145

RyanMouraBrocco opened this issue Jul 24, 2024 · 2 comments
Assignees
Labels

Comments

@RyanMouraBrocco
Copy link

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"
}
@StefH StefH self-assigned this Jul 28, 2024
@StefH
Copy link
Collaborator

StefH commented Jul 28, 2024

#1148

@StefH
Copy link
Collaborator

StefH commented 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 StefH closed this as completed Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants