Skip to content

feat: add JSON Schema for ScenarioSpec, robots.txt pointer, and example templates#762

Open
mvanhorn wants to merge 1 commit intoauthorjapps:masterfrom
mvanhorn:feat/scenario-json-schema-issue-761
Open

feat: add JSON Schema for ScenarioSpec, robots.txt pointer, and example templates#762
mvanhorn wants to merge 1 commit intoauthorjapps:masterfrom
mvanhorn:feat/scenario-json-schema-issue-761

Conversation

@mvanhorn
Copy link
Copy Markdown

Closes #761.

Adds a JSON Schema (Draft-07) describing the structure of a Zerocode scenario JSON file so:

  • IDEs (VS Code, IntelliJ) can validate and auto-complete scenario files
  • CLI users can validate scenarios with `ajv-cli` (or any Draft-07 tool) before runtime
  • AI tools generating scenarios have a contract to target

The schema mirrors the Java POJOs in `core/src/main/java/.../domain/`: `ScenarioSpec`, `Step`, `Retry`, `Validator`, and `Parameterized`. All required fields (`scenarioName`, `steps`, `validator.field`, `validator.value`) are marked `required`; optional fields are listed but not required; free-form Jackson `JsonNode` properties (`request`, `sort`, `assertions`, `verify`, `validator.value`) accept any JSON type via union types.

`additionalProperties: false` is set throughout to make typos catchable. The standard `$schema` pointer is whitelisted at the root so scenario files can self-describe their schema for IDE pickup.

Files

  • `schema/zerocode-scenario-schema.json` — the schema
  • `robots.txt` — root-level pointer to the schema (per the issue)
  • `core/src/test/resources/templates/example_scenario_1.json` — typical REST flow with two steps, headers, retry, verify, and inter-step value resolution
  • `core/src/test/resources/templates/example_scenario_2.json` — parameterized scenario demonstrating both `valueSource` and `csvSource` (with `withHeaders`)
  • `README.md` — new "Configuration" section pointing to the schema with CLI / IDE / AI usage examples

Verification

Both examples and two existing real-world scenarios (`reports_e2e/two_step_scenario_1.json`, `reports_e2e/two_step_scenario_2.json`) validate successfully against the schema (verified with the `jsonschema` Draft-07 validator).

Notes

The schema is intentionally permissive on free-form fields like `request`, `assertions`, and `verify` because the Java POJOs hold those as `JsonNode` (any JSON shape). Tightening these to specific shapes (e.g. `status` as integer, `headers` as object of strings) is a natural follow-up but would constrain valid scenarios that already exist in the repo, so I kept Draft-07 unions for parity with the current runtime behavior.

🤖 Authored with Claude Code

…le templates

Closes authorjapps#761.

Adds a JSON Schema (Draft-07) describing the structure of a Zerocode
scenario JSON file so:

- IDEs (VS Code, IntelliJ) can validate and auto-complete scenario files
- CLI users can validate scenarios with `ajv-cli` (or any Draft-07 tool)
  before runtime
- AI tools generating scenarios have a contract to target

The schema mirrors the Java POJOs in `core/src/main/java/.../domain/`:
ScenarioSpec, Step, Retry, Validator, and Parameterized. All required
fields (scenarioName, steps, validator.field, validator.value) are
marked `required`; optional fields are listed but not required;
free-form Jackson `JsonNode` properties (request, sort, assertions,
verify, validator.value) accept any JSON type via union types.

`additionalProperties: false` is set throughout to make typos catchable.
The standard `$schema` pointer is whitelisted at the root so scenario
files can self-describe their schema for IDE pickup.

## Files

- `schema/zerocode-scenario-schema.json` — the schema
- `robots.txt` — root-level pointer to the schema (per the issue)
- `core/src/test/resources/templates/example_scenario_1.json` — typical
  REST flow with two steps, headers, retry, verify, and inter-step
  value resolution
- `core/src/test/resources/templates/example_scenario_2.json` —
  parameterized scenario demonstrating both `valueSource` and
  `csvSource` (with `withHeaders`)
- `README.md` — new "Configuration" section pointing to the schema with
  CLI / IDE / AI usage examples

## Verification

Both examples and two existing real-world scenarios (`reports_e2e/two_step_scenario_1.json`,
`reports_e2e/two_step_scenario_2.json`) validate successfully against
the schema (verified with `jsonschema` Draft-07 validator).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add JSON Schema for Scenario, robots.txt pointer, and template scenario files

1 participant