Add --validate-schema to check a response against a JSON Schema#274
Open
jongio wants to merge 1 commit into
Open
Add --validate-schema to check a response against a JSON Schema#274jongio wants to merge 1 commit into
jongio wants to merge 1 commit into
Conversation
--validate-schema <file> validates the JSON response against a JSON Schema and exits non-zero when it does not conform, printing each validation error to stderr so contract checks in CI can fail the build. The response body is still printed first, so this composes with normal output. Exit codes follow the existing contract: a conforming response exits 0, a non-conforming response exits 1, and a missing or invalid schema file (or a non-JSON response) exits 2 with a clear message. Validation uses the santhosh-tekuri/jsonschema/v6 library, promoted from an indirect to a direct dependency. Closes #267 Co-authored-by: Copilot App <[email protected]>
Contributor
|
🚀 Website Preview Your PR preview is ready! 📎 Preview URL: https://jongio.github.io/azd-rest/pr/274/ This preview will be automatically cleaned up when the PR is closed. |
Contributor
🚀 Test This PRA preview build ( One-Line Install (Recommended)PowerShell (Windows): iex "& { $(irm https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/install-pr.ps1) } -PrNumber 274 -Version 0.5.0-pr274"Bash (macOS/Linux): curl -fsSL https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/install-pr.sh | bash -s 274 0.5.0-pr274UninstallPowerShell (Windows): iex "& { $(irm https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/uninstall-pr.ps1) } -PrNumber 274"Bash (macOS/Linux): curl -fsSL https://raw.githubusercontent.com/jongio/azd-rest/main/scripts/uninstall-pr.sh | bash -s 274Build Info:
|
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.
What
Adds a
--validate-schema <file>flag that validates the JSON response against a JSON Schema and exits non-zero when it does not conform. Instead of piping a response into an external validator like ajv, you can check an Azure response against a contract inline.Behavior
0.instanceLocation: message) and exits1. The response body is still printed first.2with a clear message.The check runs after the body is written, so it composes with normal output and with
--output-file.Example
azd rest get https://management.azure.com/subscriptions/{sub}/resourceGroups/{rg}?api-version=2021-04-01 --validate-schema rg.schema.jsonNotes
github.com/santhosh-tekuri/jsonschema/v6, promoted from an indirect to a direct dependency (it was already in the module graph, so no new third-party code is pulled in). It supports Draft 4 through 2020-12 and preserves number precision viajson.Number.client.IsJSONfor the response-type guard, matching howservice.goandcolor.goalready gate JSON handling.Tests cover a conforming response, a non-conforming response (with error output), and the error paths (missing schema, invalid schema JSON, non-JSON response), plus end-to-end conforming and non-conforming runs through
Executethat confirm the body is still written.Closes #267