Understand how you can use Specmatic Dictionary feature to generate deterministic, domain-aware request payloads from contract testing and response from service virtualization.
10-15 minutes.
- Docker is installed and running.
- You are in
labs/dictionary.
.specmatic/repos/labs-contracts/openapi/dictionary/simple-openapi-spec.yaml- runtime OpenAPI contract used byspecmatic.yamlafter the contracts repo is checked out.specs/simple-openapi-spec.yaml- local copy kept only for theexamples dictionary --spec-file ...command in this lab.examples/*.json- External examples used by tests.specmatic.yaml- Specmatic config file that pulls the runtime contract fromlabs-contractsand uses local examples.
docker compose up suite --abort-on-container-exitExpected output:
Tests run: 3, Successes: 0, Failures: 3, Errors: 0
Tests expect specific response values, but the mock generates random valid values.
We will fix this by configuring dictionary-driven mock generation, not by editing the example test files.
Clean up before the next step:
docker compose down -vGenerate dictionary data from existing examples:
docker run --rm -v .:/usr/src/app specmatic/enterprise examples dictionary --examples-dir examples --spec-file specs/simple-openapi-spec.yaml --out specs/dictionary.yamlGenerated dictionary file at specs/dictionary.yaml
Open and understand the generated dictionary file
Update specmatic.yaml under dependencies.services[0].service to add:
data:
dictionary:
path: specs/dictionary.yamldocker compose up suite --abort-on-container-exitExpected output:
Tests run: 3, Successes: 3, Failures: 0, Errors: 0
Clean up:
docker compose down -v- Baseline run fails with
Tests run: 3, Successes: 0, Failures: 3, Errors: 0. - After dictionary configuration, run passes with
Tests run: 3, Successes: 3, 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.