Validate deep payload schemas for every resource - #44
Merged
Conversation
Add tests/schemas/contract.schema.json — a hand-authored, additive-tolerant JSON Schema pinning the nested payload of every resource (organizer, location.coordinates, occurrences[], imageUrls, …) with types and the consumer-critical required fields. ContractSchemaTest validates both collection members and item endpoints against it, handling the D6 quirk where the five nested resources return a hydra:Collection with a single member on their item endpoint while Tag/Vocabulary return true items. This is the delta over CollectionContractTest (top-level field set only): a removed/renamed nested field or a changed type now fails CI, while adding a field passes. Adds justinrainbow/json-schema as a dev dependency.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #44 +/- ##
=============================================
+ Coverage 71.89% 72.99% +1.09%
- Complexity 226 232 +6
=============================================
Files 29 29
Lines 637 648 +11
=============================================
+ Hits 458 473 +15
+ Misses 179 175 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Adds deep JSON-Schema validation of every resource's nested payload, closing the last big contract gap before the API Platform upgrade.
Changes
tests/schemas/contract.schema.json— a hand-authored, additive-tolerant schema pinning the nested payload of each resource:organizer/partners,location(incl.coordinatesas a 2-number array),occurrences[]/dailyOccurrences[],imageUrls, and thetag/vocabularyitem shapes. Types and consumer-criticalrequiredfields are declared;additionalPropertiesstays open.ContractSchemaTestvalidates both collection members and item endpoints against the schema, handling the D6 quirk (the five nested resources return ahydra:Collectionwith a single member on their item endpoint; Tag/Vocabulary return true items).justinrainbow/json-schemaas a dev dependency (was already present transitively; now an explicit dev requirement).Why
CollectionContractTestonly pins the top-level member field set, and API Platform's self-generated item/collection schema is near-empty (@id/@type/@contextonly). Neither catches a nested field being removed, renamed, or having its type changed. This schema does — verified: renamingorganizer.email, changingentityIdto a string, or truncatingcoordinatesall fail; adding a field passes. Tests only — no production code changes.