Skip to content

feat: JSON Schema response validation core (#41) - #44

Merged
rwrife merged 1 commit into
mainfrom
feat/issue-41-schema-validation-core
Jul 12, 2026
Merged

feat: JSON Schema response validation core (#41)#44
rwrife merged 1 commit into
mainfrom
feat/issue-41-schema-validation-core

Conversation

@rwrife

@rwrife rwrife commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Closes #41 (partially — see follow-ups).

What changed

Pure, VS Code-free core for validating response bodies against a JSON Schema referenced by a new # @schema directive.

  • src/core/schemaRef.ts — RFC 6901 JSON Pointer parser/resolver + in-document $ref inliner (circular-ref safe).
  • src/core/schemaValidator.ts — parses @schema into a SchemaRef (inline JSON, openapi:<path>#/<pointer>, or file:<path>[#/<pointer>]), resolves it against caller-supplied loaded docs, and validates a body with ajv + ajv-formats. Non-JSON responses are reported as skipped, not failed, matching the acceptance criteria.
  • Parser already generalizes # @<key> <value> into request.directives, so # @schema … is captured with zero parser changes; new tests pin that contract.
  • README — new "Schema validation" section with inline + OpenAPI-ref examples.
  • Depsajv + ajv-formats (only these; no ajv-cli, no json-schema-ref-parser, per the issue).

Tests

+32 unit tests (test/schemaRef.test.ts, test/schemaValidator.test.ts). All 398 tests pass. Lint + typecheck clean. npm run build clean.

Follow-ups (still open on #41, intentionally out of scope here to keep this PR small and reviewable)

  • Response-panel Schema tab (pass badge / violations list / copy-as-issue-body).
  • CLI (reqit run) exit-code wiring so schema failures gate CI.
  • Extension-side path guarding for openapi:/file: doc loads (src/core/pathGuard.ts already exists — trivial once the panel tab lands).

Design notes

  • Kept all IO out of src/core/ (loaded OpenAPI/JSON Schema docs are passed in via SchemaResolveContext). The extension layer picks the file-reading strategy, and the CLI can do the same without any code duplication.
  • Compiled ajv validators are cached in a WeakMap keyed on the schema object, so re-running the same .http file doesn't recompile.

Adds the pure, VS Code-free core for validating response bodies against a
JSON Schema referenced by a new '# @Schema' directive.

- src/core/schemaRef.ts: RFC 6901 JSON Pointer parser/resolver + in-doc
  $ref inliner (circular-ref safe). Used to walk OpenAPI docs like
  '#/components/schemas/User' or '#/paths/~1users~1{id}/get/responses/200'.
- src/core/schemaValidator.ts: parses '@Schema <ref>' into a SchemaRef
  (inline JSON, openapi:<path>#/<pointer>, or file:<path>[#/<pointer>]),
  resolves it against caller-supplied loaded docs, and validates a body
  with ajv + ajv-formats. Non-JSON responses are reported as skipped, not
  failed, matching the acceptance criteria.
- Parser already generalizes '# @<key> <value>' into request.directives,
  so '# @Schema ...' is captured with zero parser changes; tests pin
  this contract.
- README: 'Schema validation' section with inline + OpenAPI-ref examples.
- Deps: ajv + ajv-formats (only these; no ajv-cli, no
  json-schema-ref-parser).

Follow-ups (tracked on the issue): Schema tab in the response panel,
CLI/runner exit-code wiring, extension-side path guarding for
'openapi:'/'file:' doc loads.
@rwrife
rwrife merged commit ff7ba49 into main Jul 12, 2026
8 checks passed
@rwrife
rwrife deleted the feat/issue-41-schema-validation-core branch July 12, 2026 17:00
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.

[feature] Response schema validation (JSON Schema / OpenAPI ref)

1 participant