feat: JSON Schema response validation core (#41) - #44
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
# @schemadirective.src/core/schemaRef.ts— RFC 6901 JSON Pointer parser/resolver + in-document$refinliner (circular-ref safe).src/core/schemaValidator.ts— parses@schemainto aSchemaRef(inline JSON,openapi:<path>#/<pointer>, orfile:<path>[#/<pointer>]), resolves it against caller-supplied loaded docs, and validates a body withajv+ajv-formats. Non-JSON responses are reported as skipped, not failed, matching the acceptance criteria.# @<key> <value>intorequest.directives, so# @schema …is captured with zero parser changes; new tests pin that contract.ajv+ajv-formats(only these; noajv-cli, nojson-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 buildclean.Follow-ups (still open on #41, intentionally out of scope here to keep this PR small and reviewable)
reqit run) exit-code wiring so schema failures gate CI.openapi:/file:doc loads (src/core/pathGuard.tsalready exists — trivial once the panel tab lands).Design notes
src/core/(loaded OpenAPI/JSON Schema docs are passed in viaSchemaResolveContext). The extension layer picks the file-reading strategy, and the CLI can do the same without any code duplication.WeakMapkeyed on the schema object, so re-running the same.httpfile doesn't recompile.