Skip to content

Commit

Permalink
trying to add tojson method to instance classes via decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
silvae86 committed Mar 2, 2020
1 parent e5c531c commit 302997a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
15 changes: 15 additions & 0 deletions src/GCF/decorators/OntologyClass.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import importlib
from marshmallow import Schema, fields
from marshmallow_jsonschema import JSONSchema
from functools import wraps # This convenience func preserves name and docstring

def has_json_schema(cls):

def getSchema(self):
string_schema = StringSchema()
json_schema = JSONSchema()
return json_schema.dump(string_schema)

# package_name = ".".join([cls.__module__, cls.__name__])
package_name = ".".join(str.split(cls.__module__, ".")[:-2])
module = importlib.import_module(cls.__module__ + "Schema")



def ontology_class(cls):
Expand Down
10 changes: 2 additions & 8 deletions src/Models/DataObject/v0_0_2/String.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import json

from marshmallow import Schema, fields
from marshmallow_jsonschema import JSONSchema

from neomodel import StringProperty
from src.Models.DataObject.v0_0_2.DataObject import DataObject


@has_json_schema
class String(DataObject):
stringValue = StringProperty(unique_index=True, required=True)

def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__)

def getSchema(self):
string_schema = StringSchema()
json_schema = JSONSchema()
return json_schema.dump(string_schema)


class StringSchema(Schema):
stringValue = fields.String(required=True)

0 comments on commit 302997a

Please sign in to comment.