Skip to content
This repository has been archived by the owner on Sep 25, 2018. It is now read-only.

Explore code generation options #1

Open
cmungall opened this issue Mar 7, 2016 · 3 comments
Open

Explore code generation options #1

cmungall opened this issue Mar 7, 2016 · 3 comments
Assignees

Comments

@cmungall
Copy link
Member

cmungall commented Mar 7, 2016

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

phenopackets/phenopacket-format#31

@cmungall
Copy link
Member Author

cmungall commented Mar 7, 2016

@kshefchek
Copy link
Contributor

I have two experimental branches towards this effort:

  • Manually created API
    Manually generated Python class structure based on schema and Java reference, using annotations/type hints for eventual type checking, but this doesn't seem very pythonic which embraces duck typing. If we were to pursue we would have to write a custom object_hook for json encode/decoding.
  • Testing JSON Packages
    Unit tests to test functionality of jsonschema and python-jsonschema-objects with our schema and example files.

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
Copy link
Contributor

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

cmungall pushed a commit that referenced this issue Jun 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants