phenopackets / phenopacket-python

8 stars 3 forks source link

Explore code generation options #1

Open cmungall opened 8 years ago

cmungall commented 8 years ago

Bindings can be made automatically based on schema def, depends on this ticket:

https://github.com/phenopackets/phenopacket-format/issues/31

cmungall commented 8 years ago

http://jsonmodels.readthedocs.org/en/latest/readme.html

allows you to go from an OM to JSONSchema - but not vice versa.

from 2012: http://stackoverflow.com/questions/12465588/convert-a-json-schema-to-a-python-class

warlock or this: https://github.com/cwacek/python-jsonschema-objects

kshefchek commented 8 years ago

I have two experimental branches towards this effort:

Jsonschema validates the omim and variant example, accurately fails on the journal example since we're using "human" instead of "patient." However, the patient example fails due to:

KeyError: 'urn:jsonschema:org:monarchinitiative:ppk:model:condition:TemporalRegion' urllib.error.URLError: jsonschema.exceptions.RefResolutionError:

I assume this has to do with the lines $ref: urn:jsonschema... jsonschema attempts to resolve the url and fails.

Similarly, python-jsonschema-objects fails when loading the schema: builder = jsonobjects.ObjectBuilder(self.schema) Exception: urllib.error.URLError: With the same issue (note we haven't even attempted to load an example file here).

I'm not familiar with JSONschema enough to know if the use of $ref and referring to an object within the schema is legal and this is a bug in these packages, or if we're using this incorrectly.

Update: this is fixed by changing $ref to id, or we could alternatively follow this pattern of internal referencing.

kshefchek commented 8 years ago

I've changed $ref to id in the schema for the sake of testing (on my branch). python-jsonschema-objects works reasonably well for both validation and mapping json to python objects and serializing back to json.

See latest commit