diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 13378217..2dfda79c 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -6,6 +6,10 @@ - [One service](proto-one-file) - [N-Services in one](proto-multifiles) +- Matching Rule + - [Input](matching-rule-input) + - [Headers](matching-rule-headers) + - Static stubs - [JSON](static-stubs-json) - [YAML](static-stubs-yaml) diff --git a/docs/api-stubs-search.md b/docs/api-stubs-search.md index 0d1939da..b2af2e80 100644 --- a/docs/api-stubs-search.md +++ b/docs/api-stubs-search.md @@ -69,147 +69,6 @@ Response: } ``` -## Input Matching -Stub will respond with the expected response only if the request matches any rule. Stub service will serve `/api/stubs/search` endpoint with format: -```json -{ - "service":"", - "method":"", - "data":{ - // input that suppose to match with stored stubs - } -} -``` -So if you do a `curl -X POST -d '{"service":"Greeter","method":"SayHello","data":{"name":"gripmock"}}' localhost:4771/api/stubs/search` stub service will find a match from listed stubs stored there. - -### Input Matching Rule -Input matching has 3 rules to match an input: **equals**,**contains** and **matches** -
-Nested fields are allowed for input matching too for all JSON data types. (`string`, `bool`, `array`, etc.) -
-**Gripmock** recursively goes over the fields and tries to match with given input. -
-**equals** will match the exact field name and value of input into expected stub. example stub JSON: -```json -{ - . - . - "input":{ - "equals":{ - "name":"gripmock", - "greetings": { - "english": "Hello World!", - "indonesian": "Halo Dunia!", - "turkish": "Merhaba Dünya!" - }, - "ok": true, - "numbers": [4, 8, 15, 16, 23, 42] - "null": null - } - } - . - . -} -``` - -**contains** will match input that has the value declared expected fields. example stub JSON: -```json -{ - . - . - "input":{ - "contains":{ - "field2":"hello", - "field4":{ - "field5": "value5" - } - } - } - . - . -} -``` - -**matches** using regex for matching fields expectation. example: - -```json -{ - . - . - "input":{ - "matches":{ - "name":"^grip.*$", - "cities": ["Jakarta", "Istanbul", ".*grad$"] - } - } - . - . -} -``` +[Input Matching](matching-rule-input.md ':include') -## Headers Matching -Stub will respond with the expected response only if the request matches any rule. Stub service will serve `/api/stubs/search` endpoint with format: -```json -{ - "service":"", - "method":"", - "data":{ - // input that suppose to match with stored stubs - } -} -``` -So if you do a `curl -X POST -d '{"service":"Greeter","method":"SayHello","data":{"name":"gripmock"}}' localhost:4771/api/stubs/search` stub service will find a match from listed stubs stored there. - -### Headers Matching Rule -Headers matching has 3 rules to match an input: **equals**,**contains** and **matches** -
-Headers can consist of a key and a value. If there are several values, then you need to list them separated by ";". Data type string. -
-**Gripmock** recursively goes over the fields and tries to match with given input. -
-**equals** will match the exact field name and value of input into expected stub. example stub JSON: -```json -{ - . - . - "headers":{ - "equals":{ - "authorization": "mytoken", - "system": "ec071904-93bf-4ded-b49c-d06097ddc6d5" - } - } - . - . -} -``` - -**contains** will match input that has the value declared expected fields. example stub JSON: -```json -{ - . - . - "headers":{ - "contains":{ - "field2":"hello" - } - } - . - . -} -``` - -**matches** using regex for matching fields expectation. example: - -```json -{ - . - . - "headers":{ - "matches":{ - "name":"^grip.*$" - } - } - . - . -} -``` +[Headers Matching](matching-rule-headers.md ':include') diff --git a/docs/matching-rule-headers.md b/docs/matching-rule-headers.md new file mode 100644 index 00000000..fe3dbe1c --- /dev/null +++ b/docs/matching-rule-headers.md @@ -0,0 +1,66 @@ +## Headers Matching +Stub will respond with the expected response only if the request matches any rule. Stub service will serve `/api/stubs/search` endpoint with format: +```json +{ + "service":"", + "method":"", + "data":{ + // input that suppose to match with stored stubs + } +} +``` +So if you do a `curl -X POST -d '{"service":"Greeter","method":"SayHello","data":{"name":"gripmock"}}' localhost:4771/api/stubs/search` stub service will find a match from listed stubs stored there. + +### Headers Matching Rule +Headers matching has 3 rules to match an input: **equals**,**contains** and **matches** +
+Headers can consist of a key and a value. If there are several values, then you need to list them separated by ";". Data type string. +
+**Gripmock** recursively goes over the fields and tries to match with given input. +
+**equals** will match the exact field name and value of input into expected stub. example stub JSON: +```json +{ + . + . + "headers":{ + "equals":{ + "authorization": "mytoken", + "system": "ec071904-93bf-4ded-b49c-d06097ddc6d5" + } + } + . + . +} +``` + +**contains** will match input that has the value declared expected fields. example stub JSON: +```json +{ + . + . + "headers":{ + "contains":{ + "field2":"hello" + } + } + . + . +} +``` + +**matches** using regex for matching fields expectation. example: + +```json +{ + . + . + "headers":{ + "matches":{ + "name":"^grip.*$" + } + } + . + . +} +``` diff --git a/docs/matching-rule-input.md b/docs/matching-rule-input.md new file mode 100644 index 00000000..9e9d3946 --- /dev/null +++ b/docs/matching-rule-input.md @@ -0,0 +1,77 @@ +## Input Matching +Stub will respond with the expected response only if the request matches any rule. Stub service will serve `/api/stubs/search` endpoint with format: +```json +{ + "service":"", + "method":"", + "data":{ + // input that suppose to match with stored stubs + } +} +``` +So if you do a `curl -X POST -d '{"service":"Greeter","method":"SayHello","data":{"name":"gripmock"}}' localhost:4771/api/stubs/search` stub service will find a match from listed stubs stored there. + +### Input Matching Rule +Input matching has 3 rules to match an input: **equals**,**contains** and **matches** +
+Nested fields are allowed for input matching too for all JSON data types. (`string`, `bool`, `array`, etc.) +
+**Gripmock** recursively goes over the fields and tries to match with given input. +
+**equals** will match the exact field name and value of input into expected stub. example stub JSON: +```json +{ + . + . + "input":{ + "equals":{ + "name":"gripmock", + "greetings": { + "english": "Hello World!", + "indonesian": "Halo Dunia!", + "turkish": "Merhaba Dünya!" + }, + "ok": true, + "numbers": [4, 8, 15, 16, 23, 42] + "null": null + } + } + . + . +} +``` + +**contains** will match input that has the value declared expected fields. example stub JSON: +```json +{ + . + . + "input":{ + "contains":{ + "field2":"hello", + "field4":{ + "field5": "value5" + } + } + } + . + . +} +``` + +**matches** using regex for matching fields expectation. example: + +```json +{ + . + . + "input":{ + "matches":{ + "name":"^grip.*$", + "cities": ["Jakarta", "Istanbul", ".*grad$"] + } + } + . + . +} +```