Help with modular JSON Schema

130 views
Skip to first unread message

grah...@gmail.com

unread,
Jun 20, 2017, 8:55:54 AM6/20/17
to JSON Schema
I generate the JSON schemas for FHIR, which is a RESTful API for health data exchange. 

I generate 2 sets of schemas - a single schema with everything in it. That schema is quite large (1.5Mb) so I also generate a series of modular schemas as well. They all refer to each other :-( - it's the way containment works. I've tried to understand the way that $ref works, but evidently I don't. I've had this exchange:


and now I have this: 


It seems that all the problems are around the schema, and the interplay between the logical URI and the literal URL. Take the schema for the Patient resource - the URI for the Patient JSON schema is http://hl7.org/fhir/json-schema/Patient, though the actual file lives at http://hl7.org/fhir/Patient.schema.json. I haven't set up a redirect from logical to literal yet - though I maybe might be able to (logistical nightmare because I don't control the choice of server and can't run active content). But it's far from clear to me that would resolve the problems that are being reported around how the schema are constructed. 

When I build the schemas - custom software I wrote, then I validate the json examples against the schema using the java everit library, which has no problems with the schema, though it might be a while since I tested invalid content. :-(

The full set of schemas is here: http://hl7.org/fhir/fhir.schema.json.zip

I'm hoping some one here will feel some pity for me, and help me get the schemas right 

thanks
Grahame


Ben Hutton (@Relequestual)

unread,
Jun 20, 2017, 9:07:02 AM6/20/17
to JSON Schema, grah...@gmail.com
If they provide the schemas and you're having issues with how the schemas should be used, then I would say ask them how they intend for them to be used.

This discussion you had on gitter: Evgeny is one of the JSON Schema team now, but regrdless his understanding is pretty damn good. You're unlikely to find any different answers here... sorry.

Ben

Jason Desrosiers

unread,
Jun 23, 2017, 1:46:44 AM6/23/17
to JSON Schema, grah...@gmail.com
Grahame,

I posted an answer to the SO question you linked to.  The bottom line is that your schemas are technically correct, but a little oddly structured.  Unfortunately, many validators don't handle `$ref` as well as they should.  My recommendation is to inline your top level `$ref`s so you have compatibility with a wider range of (potentially buggy) validators.

Also, if online validation is a common need for your users, I recommend providing one for them because what's out there really isn't designed for something on the scale you are working with.

Good Luck,
Jason
Reply all
Reply to author
Forward
0 new messages