opentable / wiremock-body-transformer

Wiremock Body Transformer Extension
Apache License 2.0
65 stars 42 forks source link

Change the behaviour of url query string parameters support #30

Closed okondrashin closed 6 years ago

okondrashin commented 7 years ago

The current behaviour of wire mock-body-transformer is:

1. Try to create request-map from json,
if failed - try to create request-map from xml
if failed - try to create request-map from key/value
if failed - try to create request-map from url query parameters

2. Enrich request-map using urlRegex parameters if exists (replace fields whith same names).

3. Transform response body using request-map.

This behaviour is not supports to use query parameters with request body look like json,xml,key/value from the box (without using urlRegex parameters).

What you think about to change the behaviour? Which variant is better?

Variant a)

1. Try to create request-map from url query parameters

2. Enrich request-map from json,
if failed - try to create request-map from xml
if failed - try to create request-map from key/value
(replace fields whith same names)

3. Enrich request-map using urlRegex parameters if exists (replace fields whith same names).

Variant b)

1. Try to create request-map from json,
if failed - try to create request-map from xml
if failed - try to create request-map from key/value

2. Enrich request-map from url query parameters (replace fields whith same names).

3. Enrich request-map using urlRegex parameters if exists (replace fields whith same names).

The variant a will save backward compatibility if someone uses query parameters with body with same field names. But I think the variant b is more logical for setting priorities for the names of fields.

I can create pr :)

tranhungt commented 7 years ago

@chornyi Any thoughts?

KRoLer commented 7 years ago

For me, the idea that we will have a possibility to override parameters from the request using URL - sounds good. But on another hand, we may increase the complexity of using body-transformer and bug finding for regular users.

okondrashin commented 7 years ago

@KRoLer @tranhungt What are you think about variants? (a, b)

tranhungt commented 7 years ago

I agree with @KRoLer that allowing parameters to be overridden by one method over another can be complex and bug prone.

To my understanding, API calls do not use more than one specification to transfer data in RESTful API's. For example, JSON body is used in a PUT/POST, whereas query params are used in GET.

Is there a common practice where a JSON body request will also include query params to specify its data content?

okondrashin commented 6 years ago

@tranhungt @KRoLer You are right. Usually api calls use one specification to transfer data) I think this issue can be closed)

tranhungt commented 6 years ago

Thanks @okondrashin