kayaelle/openbadges-jsonld-jsonschema-validator — pull request #5 by ottonomy (2014-10-08 00:50:44+00:00)
Title: Grabremotes

Oof, this is a big one. I went in just trying to add the feature on our roadmap of grabbing remote resources (linked badgeclasses, issuers), and I ended up revamping a bunch of how the internal control flow works.

The MEAT of the whole thing is the grossly enormous function `analyzeBadgeObjectForValidation`, which should probably be refactored pretty harshly to pull all these components apart. It
* determines what type the badge is (assertion, badgeclass, issuer, ~extension)
* builds up a JSON representation of a complete badge after it's grabbed any necessary linked badge objects.
* re-expands JSON-LD (this isn't useful at the moment, but could be useful in the near future)
* identifies `@context` properties at `root`, `/badge`, and `/badge/issuer` locations in order to analyze them to determine what parts of the full badge object may have any extensions.
* analyzes each of these @context blocks in order to build validation directives from it.
* within each @context block there may be three different ways to handle it to build a schema validation rule. It determines which case applies and builds one rule from it (if a simple string), or digs into a context array to handle strings or object-designated contexts within.
* Sends it back for validation, along with any non-critical warnings or any critical errors it had to stop for along the way.

OOF, amirite!?

@kayaelle, is there a testing framework you like?