@@ -33,7 +33,8 @@ Contract Tests
3333 - [ Examples that trigger 400 responses] ( #examples-that-trigger-400-responses )
3434 - [ Running Specific Tests] ( #running-specific-tests )
3535 - [ Supported Filters & Operators] ( #supported-filters--operators )
36- - [ Usage Examples] ( #usage-examples )
36+ - [ Filter Examples] ( #filter-examples )
37+ - [ CLI Usage] ( #cli-usage )
3738 - [ Programmatic Usage] ( #programmatic-usage )
3839 - [ Additional Tips] ( #additional-tips )
3940 - [ API Coverage] ( #api-coverage )
@@ -955,13 +956,22 @@ specmatic test --filter="METHOD='POST' && PATH='/users'"
955956
956957# ## Supported Filters & Operators
957958
958- | Filter | Description |
959- |----------|-----------------------------------------------------------------------------|
960- | `METHOD` | Filter by HTTP methods (GET, POST, etc.) |
961- | `PATH` | Filter by request paths (`/users`, `/products`, etc.) |
962- | `STATUS` | Filter by response status codes (200, 400, etc.) — supports pattern matching with `xx` (e.g., 4xx, 2xx) |
963- | `HEADERS`| Filter by request headers name |
964- | `QUERY` | Filter by query parameters name |
959+ | Available Filters | Test | Stub | Description |
960+ |-----------------------------|:--:|:--:|-----------------------------------------------------------------------------------------------------------|
961+ | `STATUS` | ✅ | ✅ | Filter by status (`200`, `500`) |
962+ | `PATH` | ✅ | ✅ | Filter by request paths (`/users`, `/products`), supports wildcard using `*` (`/users/*`, `/products/*`) |
963+ | `METHOD` | ✅ | ✅ | Filter by HTTP methods (`GET`, `POST`, etc.) |
964+ | `PARAMETERS.QUERY` | ✅ | ✅ | Filter by query parameters, supports key-value match (`PARAMETERS.QUERY.byName='John'`) |
965+ | `PARAMETERS.HEADER` | ✅ | ✅ | Filter by header parameters, supports key-value match (`PARAMETERS.HEADER.X-REQUEST-ID='Hello1234'`) |
966+ | `PARAMETERS.PATH` | ✅ | ✅ | Filter by path parameters, supports key-value match (`PARAMETERS.PATH.id='99'`) |
967+ | `REQUEST-BODY.CONTENT-TYPE` | ✅ | ✅ | Filter by request body media type (MIME type) (`application/json`, `text/plain`, `application/*`) |
968+ | `RESPONSE.CONTENT-TYPE` | ✅ | ✅ | Filter by response content type (`application/json`, `text/plain`, `application/*`) |
969+ | `EXAMPLE-NAME` | ✅ | ✅ | Filter by example name (`SUCCESS_200_OK`, `PETS_200_OK`) |
970+ | `TAGS` | ✅ | ✅ | Filter by tags |
971+ | `SUMMARY` | ✅ | ✅ | Filter by summary |
972+ | `OPERATION-ID` | ✅ | ✅ | Filter by operation ID |
973+ | `DESCRIPTION` | ✅ | ✅ | Filter by description |
974+
965975
966976| Operator | Description |
967977|----------------|-------------------------------------------------------|
@@ -971,16 +981,35 @@ specmatic test --filter="METHOD='POST' && PATH='/users'"
971981| `=`, `!=` | Comparison operators for comparing a key with its value. |
972982| `(`, `)` | Parentheses are used to group multiple filter expressions. |
973983
974- # ## Usage Examples
984+ # ## Filter Examples
985+
986+ | Filter | Examples |
987+ | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
988+ | `STATUS` | • `STATUS='200'` (only 200 responses)<br>• `STATUS>='400'` (all errors)<br>• `STATUS<'500'` (exclude 5xx errors) |
989+ | `PATH` | • `PATH='/users'` (exact match)<br>• `PATH='/products/*'` (matches all subpaths under /products) |
990+ | `METHOD` | • `METHOD='GET'` (GET requests)<br>• `METHOD='POST'` (POST requests) |
991+ | `PARAMETERS.QUERY` | • `PARAMETERS.QUERY.byName='John'` (query param `byName` equals `'John'`)<br>• `PARAMETERS.QUERY='byName'` (key present) |
992+ | `PARAMETERS.HEADER` | • `PARAMETERS.HEADER.X-REQUEST-ID='Hello1234'` (header `X-REQUEST-ID` is `'Hello1234'`)<br>• `PARAMETERS.HEADER='X-REQUEST-ID'` (header key present) |
993+ | `PARAMETERS.PATH` | • `PARAMETERS.PATH.id='99'` (path param `id` equals `'99'`)<br>• `PARAMETERS.PATH='id'` (path param key present) |
994+ | `REQUEST-BODY.CONTENT-TYPE` | • `REQUEST-BODY.CONTENT-TYPE='application/json'` (expects JSON request body)<br>• `REQUEST-BODY.CONTENT-TYPE='application/*'` (any application/\* type) |
995+ | `RESPONSE.CONTENT-TYPE` | • `RESPONSE.CONTENT-TYPE='application/json'` (response with JSON)<br>• `RESPONSE.CONTENT-TYPE='text/plain'` (response with plain text) |
996+ | `EXAMPLE-NAME` | • `EXAMPLE-NAME='SUCCESS_200_OK'` (matches example with this name)<br>• `EXAMPLE-NAME='PETS_200_OK'` (another named example) |
997+ | `TAGS` | • `TAGS='users'` (tagged with "users")<br>• `TAGS='v1-endpoints'` (tagged with "v1-endpoints") |
998+ | `SUMMARY` | • `SUMMARY='Get user by ID'` (summary exactly matches this text)<br>• `SUMMARY='List all products'` (another summary) |
999+ | `OPERATION-ID` | • `OPERATION-ID='getUserById'` (operation ID match)<br>• `OPERATION-ID='createProduct'` (another operation) |
1000+ | `DESCRIPTION` | • `DESCRIPTION='Returns user details by ID'` (matches full description)<br>• `DESCRIPTION='Lists all available products'` (another description) |
1001+
1002+
1003+ # ## CLI Usage
9751004
97610051. Run only successful response tests :
9771006` ` ` bash
978- specmatic test --filter="STATUS='2xx '"
1007+ specmatic test --filter="STATUS>='200' && STATUS<'300 '"
9791008` ` `
9801009
98110102. Skip 4xx error tests :
9821011` ` ` bash
983- specmatic test --filter="STATUS!='4xx '"
1012+ specmatic test --filter="STATUS<'400' && STATUS>'499 '"
9841013` ` `
9851014
98610153. Skip specific status codes :
@@ -1013,6 +1042,8 @@ specmatic test --filter="(PATH='/users' && METHOD='POST') || (PATH='/products' &
10131042specmatic test --filter="!(PATH='/users' && METHOD='POST') && !(PATH='/products' && METHOD='POST')"
10141043` ` `
10151044
1045+ 9.
1046+
10161047# ## Programmatic Usage
10171048
10181049Set environment properties in your test setup :
@@ -1033,7 +1064,6 @@ System.setProperty("filter", "STATUS!='400,401'");
10331064- Within a single filter with multiple values, tests matching **ANY** value will be included (**OR** operation).
10341065- **Negation(!)** causes a block to be excluded from being considered.
10351066- **Wildcard(*)** can only be used with **PATH**.
1036- - **Range (2xx, 50x)** can only be used with **STATUS**.
10371067
10381068
10391069> **Note:** Endpoints that are filtered out as a result of this expression are also excluded from the reports generated by Specmatic and from the coverage calculation.
0 commit comments