Skip to content

Allow preserving proto field names before checking mappings #191

@joseluzon

Description

@joseluzon

Proposal

When using response templating reference to request field should be using lowerCamelCase.

Example:

{
  "mappings": [
    {
      "request": {
        "method": "POST",
        "url": "/api.v1.service.MyService/DeleteResource"
      },
      "response": {
        "status": 200,
        "jsonBody": {
          "created_at": "{{now}}",
          "resource_uuid": "{{jsonPath request.body '$.resourceUuid'}}"
        }
      }
    }
  ]
}

This is due to the following code:

jsonPrinter = JsonFormat.printer().usingTypeRegistry(typeRegistry);

JsonFormat default printer is used, which by default convert names to lowerCamelCase.

It should be nice to allow preserving proto field names:

jsonPrinter = JsonFormat.printer().preservingProtoFieldNames().usingTypeRegistry(typeRegistry);

so this json works too:

{
  "mappings": [
    {
      "request": {
        "method": "POST",
        "url": "/api.v1.service.MyService/DeleteResource"
      },
      "response": {
        "status": 200,
        "jsonBody": {
          "created_at": "{{now}}",
          "resource_uuid": "{{jsonPath request.body '$.resource_uuid'}}"
        }
      }
    }
  ]
}

The solution proposed is to leave the current behavior as it is and, depending on an setting configuration that could be set in a wiremock container (env var for example), use the "preservingProtoFieldNames" printer. This way, both approaches could be used.

Note: see this issue

Adven27/grpc-wiremock#26

References

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions