Use Specmatic Studio to repair incomplete external examples using partial examples, then verify behavior using validation and loop testing.
10-15 minutes.
- Docker is installed and running.
- You are in
labs/partial-examples. - Ports
9000and9001are available for Studio.
.specmatic/repos/labs-contracts/common/openapi/order-bff/product_search_bff_v6.yaml: OpenAPI contract for the BFF API, loaded byspecmatic.yaml.examples/*.json: Incomplete external examples that will be fixed using partial examples.specmatic.yaml: Specmatic configuration for contract testing and mocking.docker-compose.yaml: Suite loop setup.
docker run --rm \
-v .:/usr/src/app \
-v ../license.txt:/specmatic/specmatic-license.txt:ro \
specmatic/enterprise:latest \
validateWindows (PowerShell/CMD) single-line:
docker run --rm -v .:/usr/src/app -v ../license.txt:/specmatic/specmatic-license.txt:ro specmatic/enterprise:latest validate[OK] Specification product_search_bff_v6.yaml: PASSED
[FAIL] Examples: 0 passed and 3 failed out of 3 total
docker compose --profile studio up studioIn Studio, open product_search_bff_v6.yaml which should be under .specmatic/repos/labs-contracts/common/openapi/order-bff from the left sidebar. You will see that 3 examples have failed validation on the examples tab.
Please do not click the Fix button to make these examples valid. Instead, use partial examples to fix them.
docker run --rm \
-v .:/usr/src/app \
-v ../license.txt:/specmatic/specmatic-license.txt:ro \
specmatic/enterprise:latest \
validateWindows (PowerShell/CMD) single-line:
docker run --rm -v .:/usr/src/app -v ../license.txt:/specmatic/specmatic-license.txt:ro specmatic/enterprise:latest validate[OK] Specification simple-openapi-spec.yaml: PASSED
[OK] Examples: 3 passed and 0 failed out of 3 total
- Partial examples docs: https://docs.specmatic.io/contract_driven_development/service_virtualization#partial-examples
In Studio, after examples are valid:
- Go to
Mockand clickRun(mock server on port8080). - Go to
Test, set URL tohttp://127.0.0.1:8080, then clickRun.
Expected: 7 tests passing and 0 failing.
docker compose --profile studio down -vYou have 3 external examples, plus additional inline examples in the OpenAPI spec.
Specmatic runs tests from both sources, so total generated tests are higher than 3.
Run the following command to start the mock server and run the tests against it using CLI.
docker compose up --abort-on-container-exitThis runs the suite, starts the dependency mocks, and executes the tests. You should see:
Tests run: 7, Successes: 7, Failures: 0, Errors: 0
docker compose down -v- Validation shows:
3 passed and 0 failed out of 3 total. - Loop test shows:
Tests run: 7, Successes: 7, Failures: 0, Errors: 0.
If you are doing this lab as part of an eLearning course, return to the eLearning site and continue with the next module.