Skip to content

feat: introduce v3 schema with Go template support - #67

Merged
fzipi merged 5 commits into
mainfrom
feat/v3-schema
Jun 26, 2026
Merged

fzipi merged 5 commits into
mainfrom
feat/v3-schema

Conversation

@fzipi

@fzipi fzipi commented Jun 21, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Adds RequestTemplate type and a file-level template field to FTWTest, so tests can define the HTTP request structure once and inject per-test payloads via {{.Payload}} in URI, data, and header values
  • Tests can now use a simplified format (id + description + payload + output) instead of explicit stages; the stages format remains fully supported for multi-step tests
  • Bumps the Go module path to github.com/coreruleset/ftw-tests-schema/v3

Changes

  • New RequestTemplate struct with template-capable uri, data, and header values
  • FTWTest.Template — file-level default request template
  • Test.Payload, Test.Template, Test.Output — simplified per-test fields
  • Custom UnmarshalYAML on Test accepts id / description as aliases for test_id / desc
  • spec/v3.0.0/ — generated JSON schemas for tests and platform overrides
  • README updated with v3 and v2 format examples, version history table with comments

Backward compatibility

All v2 test files parse and behave identically. Deprecated fields (stop_magic, log_contains, no_log_contains, headers map, enabled, test_title) are preserved in structs so existing test files produce correct results without modification.

Test plan

  • go test ./... passes (all 6 tests green)
  • mage jsonSchemas regenerates spec/v3.0.0/ correctly
  • Existing v2-format YAML in types/types_test.go still unmarshals correctly (TestUnmarshalFTWTest)
  • New v3-format YAML parses correctly, including id/description aliases (TestUnmarshalV3Format)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Released FTW Tests YAML schema v3 with file-level default request templates, payload-based simplified test definitions, and field aliases (id, description) with backward-compatible parsing.
    • Added v3 JSON Schemas for core tests and platform overrides.
  • Documentation
    • Extensively updated README to document schema v3 details (templates, overrides, stages behavior) and developer workflows.
  • Tests
    • Added/extended tests covering v3 unmarshalling, alias handling, template/payload parsing, and expected stage behavior.

Add RequestTemplate type and file-level template field to FTWTest,
allowing tests to define the HTTP request structure once and inject
per-test payloads via {{.Payload}} in URI, data, and header values.

Tests can now use the simplified format (id + description + payload +
output) instead of explicit stages. Stages remain fully supported for
multi-step and complex tests, preserving backward compatibility.

Other v3 additions:
- `id` and `description` as YAML aliases for `test_id` and `desc`
- test-level `output` field for payload-based tests
- module path bumped to github.com/coreruleset/ftw-tests-schema/v3
- spec/v3.0.0 JSON schemas generated
- README updated with v3 and v2 format examples and version history

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 21, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@fzipi, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 43 minutes and 45 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: aeb12559-5330-4973-8b62-5c45f1856bfe

📥 Commits

Reviewing files that changed from the base of the PR and between ab0e941 and 604b204.

📒 Files selected for processing (4)
  • README.md
  • spec/v3.0.0/waf-tests-schema-v3.0.0.json
  • types/types.go
  • types/types_test.go
📝 Walkthrough

Walkthrough

The Go module is promoted from v2 to v3. The core type file adds a file-level Template field to FTWTest and extends Test with payload-based shorthand fields plus custom YAML alias handling. New v3 JSON schema files are added, tooling imports are updated, and the README is rewritten for v3.

Changes

ftw-tests-schema v3 upgrade

Layer / File(s) Summary
Module and import path v2→v3 bump
go.mod, cmd/generate-doc-yaml-schema/main.go, magefile.go, types/overrides/types.go, types/overrides/examples.go, types/examples.go, types/types_test.go
go.mod changes the module declaration to v3, and command, mage, type example, override example, and test imports move from v2 package paths to v3 package paths.
V3 type definitions: FTWTest.Template, Test shorthand fields, UnmarshalYAML
types/types.go
FTWTest gains a file-level Template field; Test adds V3 shorthand fields, YAML aliases, and custom unmarshalling; HeaderTuple tags are made explicit; the v3 yaml decoder import is added.
V3 example variables and unit tests
types/examples.go, types/types_test.go
Example request-template variables are added, and tests cover the v3 YAML fixture, template parsing, alias handling, payload behavior, stage-less decoding, and IdString() formatting.
V3 JSON schema files and generation tooling
spec/v3.0.0/waf-tests-schema-v3.0.0.json, spec/v3.0.0/waf-platform-overrides-schema-v3.0.0.json, magefile.go
Draft 2020-12 JSON Schema files for ftw-test and ftw-overrides are added under spec/v3.0.0, and the schema generation mage target is updated to use v3 types.
README rewritten for v3
README.md
README adds v3 template documentation, per-test overrides, alias mapping, expanded v2 examples, compatibility notes, Go library usage, development tasks, schema generation steps, and a schema versions table.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 Hop hop, version three is here,
Templates and payloads now appear!
{{.Payload}} dances in the URI,
id and desc now travel free.
The schema hops ahead with style and glee —
A tidy upgrade, v3 for me!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: introducing v3 schema support with Go templates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/v3-schema

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@fzipi
fzipi requested a review from theseion June 21, 2026 01:09
@fzipi fzipi added the enhancement New feature or request label Jun 21, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Around line 187-189: The fenced code blocks in the README.md file are missing
language identifiers, which triggers markdown linting issues and reduces
consistency. Add the bash language identifier to the two code fences: the first
one containing the go install command for yamldoc-go at lines 187-189, and the
second one containing the mkdir and mage commands at lines 205-208. Change each
opening fence from triple backticks to triple backticks followed by bash.

In `@spec/v3.0.0/waf-platform-overrides-schema-v3.0.0.json`:
- Line 1: The annotations property in the FTWOverridesMeta definition is
declared as an array type but uses additionalProperties instead of items to
define element validation, leaving item types unconstrained. Replace the
additionalProperties constraint with an items property that specifies type
string to properly enforce that each array element is a string.

In `@spec/v3.0.0/waf-tests-schema-v3.0.0.json`:
- Line 1: The HeaderTuple definition in the schema has property names cased as
Name and Value with additionalProperties set to false, but the v3 examples and
tests use lowercase name and value. Change the properties in the HeaderTuple
object definition to use lowercase name and value instead of Name and Value, and
update the required array to reflect these lowercase property names to match the
actual usage in v3 examples and tests.
- Line 1: The Test object definition in the schema only accepts test_id and desc
properties with additionalProperties set to false, which rejects the documented
v3 aliases id and description supported by the UnmarshalYAML implementation in
types.go. Add id and description as valid optional properties in the Test
definition with the same type constraints as test_id and desc respectively, so
that valid tests using the shorthand aliases will pass schema validation.
- Line 1: The Test schema definition is currently missing validation rules to
enforce the mutually exclusive payload-mode versus stages-mode contract. The
Test object should require either the payload and output properties together, or
the stages property alone, but not allow arbitrary combinations of these. Add a
oneOf constraint in the Test definition that enforces two distinct schemas: one
for payload-mode tests that requires test_id and payload with output, and
another for stages-mode tests that requires test_id with stages. This will
prevent invalid test definitions where both payload and stages are specified
together, or where output is used without payload.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e8a6ab51-d862-435d-8aef-e808503223f4

📥 Commits

Reviewing files that changed from the base of the PR and between 40d9c85 and 593aa2e.

📒 Files selected for processing (11)
  • README.md
  • cmd/generate-doc-yaml-schema/main.go
  • go.mod
  • magefile.go
  • spec/v3.0.0/waf-platform-overrides-schema-v3.0.0.json
  • spec/v3.0.0/waf-tests-schema-v3.0.0.json
  • types/examples.go
  • types/overrides/examples.go
  • types/overrides/types.go
  • types/types.go
  • types/types_test.go

Comment thread README.md Resolved
fzipi and others added 2 commits June 20, 2026 22:39
Fix dstdocgen crash (Go 1.22 binary vs Go 1.25 module): reinstalled
with current toolchain. Root cause in types.go: double-quoted values
inside description strings (e.g. "http" or "https") were embedded
unescaped into the LineComment field of generated code, producing a
Go syntax error. Removed inline double quotes from Protocol, Version,
and Method descriptions in RequestTemplate.

Address CodeRabbit findings:
- README: add bash language identifier to two fenced code blocks
- HeaderTuple: add yaml/json tags (name, value) so schema and YAML
  parsing use lowercase keys, matching actual test file usage
- Test schema: expose id and description as valid optional properties
  (v3 aliases for test_id and desc) via IdAlias/DescriptionAlias
  fields with yaml:"-"; make test_id omitempty so neither alias is
  required
- Regenerate spec/v3.0.0 JSON schemas

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The Annotations field is map[string]string, which should generate a
JSON Schema object with additionalProperties. The jsonschema:"type=array"
tag was incorrect: it forced type=array but left additionalProperties
(an object keyword) as the item validator, making item types
unconstrained and the schema internally inconsistent.

Removing the tag produces {type: object, additionalProperties: {type: string}},
which correctly matches both the Go type and the YAML key-value usage.

Regenerate spec/v3.0.0/waf-platform-overrides-schema-v3.0.0.json.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@fzipi

fzipi commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

@coderabbitui full_review

@theseion theseion left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Comment thread types/types.go Resolved
Comment thread types/types.go Resolved
Comment thread types/types.go Resolved
Comment thread types/types.go Resolved
Comment thread types/types.go Resolved
Comment thread README.md Resolved
Comment thread README.md Resolved
Comment thread README.md Resolved
fzipi and others added 2 commits June 24, 2026 11:28
Co-authored-by: Max Leske <250711+theseion@users.noreply.github.com>
In v3, `id` and `description` are now the primary YAML/JSON field names.
The v2 names `test_id` and `desc` are still accepted via UnmarshalYAML
but are deprecated aliases. Also simplifies UnmarshalYAML to use a
`type rawTest Test` alias instead of an explicit parallel struct.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@fzipi
fzipi requested a review from theseion June 24, 2026 10:33
@fzipi
fzipi merged commit 771fb15 into main Jun 26, 2026
2 checks passed
@fzipi
fzipi deleted the feat/v3-schema branch June 26, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants